[gdal-dev] ENVI Header information from GeoTIFF file

Even Rouault even.rouault at spatialys.com
Thu Jan 14 01:45:17 PST 2016


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


More information about the gdal-dev mailing list