[postgis-devel] [gdal-dev] Question about gdal2wktraster

Jorge Arévalo jorge.arevalo at gmail.com
Tue Jul 14 10:46:22 PDT 2009


Hello,

2009/7/14 Jorge Arévalo <jorge.arevalo at gmail.com>:
> Ok, here are the Corner coordinates of the utm.tif file (gdalinfo output):
>
> Corner Coordinates:
> Upper Left  (  440720.000, 3751320.000) (117d38'28.21"W, 33d54'8.47"N)
> Lower Left  (  440720.000, 3720600.000) (117d38'20.79"W, 33d37'31.04"N)
> Upper Right (  471440.000, 3751320.000) (117d18'32.07"W, 33d54'13.08"N)
> Lower Right (  471440.000, 3720600.000) (117d18'28.50"W, 33d37'35.61"N)
> Center      (  456080.000, 3735960.000) (117d28'27.39"W, 33d45'52.46"N)
>
> After loading the raster in PostGIS, the Corner Coordinates set by my
> driver (gdalinfo ouptut):
>
> Corner Coordinates:
> Upper Left  (  440720.000, 3720600.000) (117d38'20.79"W, 33d37'31.04"N)
> Lower Left  (  440720.000, 3689880.000) (117d38'13.48"W, 33d20'53.57"N)
> Upper Right (  471440.000, 3720600.000) (117d18'28.50"W, 33d37'35.61"N)
> Lower Right (  471440.000, 3689880.000) (117d18'24.98"W, 33d20'58.09"N)
> Center      (  456080.000, 3705240.000) (117d28'21.94"W, 33d29'14.98"N)
>
> As you can see, there are small differences in Y coordinate. I
> populate the raster info in this way:
>
> (...)
> pszProjectionRef = (char *) GetProjectionRef(); // returns the correct
> projection ref for srid 26711
>
> poSR = new OGRSpatialReference(pszProjectionRef);
>
> // pszWKTRaster has the extent of the raster, got by ST_AsText(extent)
> from raster_columns
> // poGeom will store the geometry
> poOgrErr = OGRGeometryFactory::createFromWkt(&pszWKTRaster, poSR,
> &poGeom);
>
> poE = new OGREnvelope();
> poGeom->getEnvelope(poE);
>
> // raster coordinates
> fUpperLeftX = poE->MinX;
> fUpperLeftY = poE->MinY;
>
> // fPixelSizeX and fPixelSizeY got from raster_columns
> nRasterXSize = (int) fabs(rint((poE->MaxX - poE->MinX) / fPixelSizeX));
> nRasterYSize = (int) fabs(rint((poE->MaxY - poE->MinY) / fPixelSizeY));
> (...)
>
> Then, I suppose that gdalinfo obtains corner coordinates from upper
> left coordinates and raster size. Is there any obvious problem in this
> code? Maybe the rint function?

Solution:
 fUpperLeftX = poE->MinX;
 fUpperLeftY = poE->MaxY; // Not min!!!!!!!!


Sometimes I feel sooooooo stupid....

Best regards
Jorge



More information about the postgis-devel mailing list