[gdal-dev] problems with gdal reprojection (from pixel to latitude/longitude)

Even Rouault even.rouault at mines-paris.org
Fri Mar 1 20:03:48 PST 2013


Le mercredi 27 février 2013 15:23:31, B.O a écrit :
> I have a satellite images of this type (link to example:
> http://navigator.eumetsat.int/smartEditor/preview/msg-level-1-5.jpg). I
> have to reproject the image to obtain latitude and longitude values for
> every pixel. I use gdal library (http://www.gdal.org/), and I follow some
> public example. The problem is that longitude and latitude values do not
> corrispond to real values that i suppose...
> I link a short version of my code. I do not use class GDALDataset because I
> have geotransform matrix yet (values are g0, g1, g2, g3, g4, g5).
> 
> 
> OGRSpatialReference *poSRS_Proj = new OGRSpatialReference("WGS84");
> poSRS_Proj->importFromEPSG( 4326 );
> // Define Geographic coordinate system - set it to WGS84.
> OGRSpatialReference *poSRS_Geog = new OGRSpatialReference("WGS84");
> poSRS_Geog->importFromEPSG( 4326 ); // WGS84
> // Set up the coordinate transform (projected-to-geographic).
> OGRCoordinateTransformation *poCT_Proj2Geog;
> poCT_Proj2Geog = OGRCreateCoordinateTransformation( poSRS_Proj, poSRS_Geog
> );

From the above definitions of poSRS_Proj and poSRS_Geog, your poCT_Proj2Geog 
transformation will be the identity. You must modify poSRS_Proj to reflect the 
projection of the image.

> 
> double lats = g3 + g4 * (row_pixel) + g5 * (column_pixel);
> double lons = g0 + g1 * (row_pixel) + g2 * (column_pixel);

You must invert row_pixel and column_pixel in the above formulas

> 
> double lat0 = lats;
> double lon0 = lons;
> // Projected coordinates to latlon
> poCT_Proj2Geog->Transform(1, &lat0, &lon0);

You must invert lat0 and lon0

> 
> 
> Outputs are: latitude = 1.06815e+06, longitude = -1.06815e+06.
> I tried several values for row_pixel and column_pixel but i get always the
> same problem.
> Can someone help me???? Thanks!

After doing the above changes, if it still does not yet work, I'd also double 
check that your geotransform is correct.

Another possibilitiy if the image is recognized as a GDAL format and include 
projection and geotransform information is to use the gdaltransform utility

> 
> 
> 
> --
> View this message in context:
> http://osgeo-org.1560.n6.nabble.com/problems-with-gdal-reprojection-from-p
> ixel-to-latitude-longitude-tp5037268.html Sent from the GDAL - Dev mailing
> list archive at Nabble.com.
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev


More information about the gdal-dev mailing list