[gdal-dev] ENVI Header information from GeoTIFF file

nguler at jlab.org nguler at jlab.org
Thu Jan 14 09:34:52 PST 2016


Than you Even,

double adfGeoTransform[6];
srcDS->GetGeoTransform(adfGeoTransform)
gives me 6 values: center, pixel size and rotation.

But when I do CreateCopy I get:
map info = {UTM, 1, 1, 145185, 2189715, 30, 30, 19, North}

Is there any way of getting the first three elements of this map info {UTM, 1,
1, outside CreateCopy method? Also I want to add DATUM, and Unite to the map
info. Like this one:

map info = {UTM, 1.000, 1.000, 145185.000, 2189715.000, 3.0000000000e+001,
3.0000000000e+001, 19, North, WGS-84, units=Meters}


In addition, as I mentioned
  srcDS->GetProjectionRef()
gives me a coordinate system string without GEOGCS. Also the string gives
PROJCS["unnamed"..]. However, PROJCS is in the file (ENVI knows it and finds
it correctly). I can get the GEOGCS via OGRSpatialReference class with
exportToWkt if I know PROJCS. Currently I set it myself as explained below but
if I can extract it from the file, I can get the exact coordinate system
string I am seeking for, the one I have printed below.

With CreateCopy (or with GetProjectionRef()), I get:

{PROJCS["unnamed",PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-69],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["Meter",1]]}
band names = {
Band 1}

What I should get is:

PROJCS["UTM_Zone_19N",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS
84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9108"]],AUTHORITY["EPSG","4326"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",-69],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",0],UNIT["Meter",1]]


The reason I can't use CreateCopy is that I am reading many bands from LANDSAT
and combining them into a single ENVI cube and I have to use my own custom
cube writing algorithm.

Best regards,
- Nevzat

> Le jeudi 14 janvier 2016 00:22:33, nguler at jlab.org a écrit :
>> Dear GDAL users,
>>
>> I am just starting to use GDAL and apparently I don't quite understand many
>> classes. My purpose is to extract some map information from GeoTIFF files
>> (LANDSAT data). I need to access this information to generate an ENVI file
>> header. When i import the tiff file, I can see the following information is
>> already in the file:
>>
>> ---- Map Info Properties ----
>> Type = Projected
>> Pixel Tie Point X = 0.5
>> Pixel Tie Point Y = 0.5
>> Map Tie Point X = 145200.0
>> Map Tie Point Y = 2189700.0
>> Pixel Size X = 30.0
>> Pixel Size Y = 30.0
>> Units = Meters
>> Rotation = 0.0
>>
>> ---- Extents Properties ----
>> Extent Left = 145185.0
>> Extent Top = 2189715.0
>> Extent Right = 372315.0
>> Extent Bottom = 1967385.0
>> Units = Meters
>>
>> Coordinate System String =
>> PROJCS["UTM_Zone_19N",GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WG
>> S_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0
>> 174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Eastin
>> g",500000.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-
>> 69.0],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",0.0],
>> UNIT["Meter",1.0]]
>>
>>
>> I am able to get the coordinate system properties by using the following
>> commands but I first need to set few things to use exportToWTK.
>>
>>       OGRSpatialReference oSRS;
>>       char *pszWKT = NULL;
>>       oSRS.SetProjCS("UTM_Zone_19N");
>>       oSRS.SetWellKnownGeogCS("WGS84");
>>       oSRS.SetUTM(19, TRUE);
>>       oSRS.SetWellKnownGeogCS("WGS84");
>>       oSRS.exportToWkt(&pszWKT);
>>       printf("%s\n", pszWKT);
>>
>> Is there any way of getting the information without setting anything. After
>> all, when I import the tiff file into ENVI, ENVI knows all these things so
>> it should be in the file. But. i don't know this information before i read
>> the file like SetProjCS, SetWellKnownGeogCS, SetUTM values are unknown but
>> they are in the file.
>>
>> I can get some of the map info (Map Tie Point and Pixel Size) from
>> GetGeoTransform member. How can I get the other map info as shown above
>> (Pixel Tie Point), Rotation etc.. and the "Extents Properties".
>>
>> Is there any way to get individual fields in the "Coordinate System
>> String", like I could extract the UNIT information from there to use in
>> the map info. I am trying to avoid string manipulation since I am not sure
>> how the string structure changes from file to file.
>
> Why don't you just use the GDALCreateCopy() API (basically what is used when
> you use gdal_translate) ? This will create both the .hdr and .img file for you
>
> GDALDatasetH hSrcDS = GDALOpen("your.tif", GA_ReadOnly);
> GDALDriverH hEnviDrv = GDALGetDriverByName("ENVI");
> GDALDatasetH hOutDS = GDALCreateCopy(hEnviDrv, "your.img", hSrcDS, 0, NULL,
> NULL, NULL);
> GDALClose(hOutDS);
>
> Oh I see in a past message you didn't want to use CreateCopy(). So use
> dstDS.SetGeoTransform( srcDS.GetGetTransform() ) and dstDS.SetProjection(
> srcDS.GetProjectionRef() ). This will take care of all needed format/header
> translations.
>
> --
> Spatialys - Geospatial professional services
> http://www.spatialys.com
>


Nevzat Guler
Senior Scientist
Spectral Sciences
Phone: 781-273-4770
http://www.spectral.com/index.shtml
http://www.linkedin.com/in/nevzatguler




More information about the gdal-dev mailing list