[gdal-dev] Python geometry.Transform() returns code 6

Howard Butler hobu.inc at gmail.com
Thu Dec 9 12:11:06 EST 2010


On Dec 9, 2010, at 11:08 AM, Frank Warmerdam wrote:

> On 10-12-08 07:40 PM, Gregor at HostGIS wrote:
>> Hey all. I am having a problem with the geometry.Transform() method in
>> OGR for Python. Short version: geometry.Transform() returns a code 6. A
> ...
>> sourceSR = osr.SpatialReference()
>> sourceSR.ImportFromProj4('+proj=longlat +ellps=WGS84 +datum=WGS84
>> +no_defs <>')
>> 
>> targetSR = osr.SpatialReference()
>> targetSR.ImportFromProj4('+proj=tmerc +lat_0=0 +lon_0=36 +k=0.9996
>> +x_0=500000 +y_0=10000000 +ellps=WGS84 +datum=WGS84 +units=m +no_defs <>')
>> 
>> coordTrans = osr.CoordinateTransformation(sourceSR, targetSR)
>> 
>> # And now the error: a code 6 but no further explanation
>> geom.Transform(coordTrans)
> 
> Gregor,
> 
> If I run:
> 
> from osgeo import osr, ogr
> 
> 
> sourceSR = osr.SpatialReference()
> sourceSR.ImportFromProj4('+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs <>')
> 
> targetSR = osr.SpatialReference()
> targetSR.ImportFromProj4('+proj=tmerc +lat_0=0 +lon_0=36 +k=0.9996 +x_0=500000 +y_0=10000000 +ellps=WGS84 +datum=WGS84 +units=m +no_defs <>')
> 
> ct = osr.CoordinateTransformation(sourceSR, targetSR )
> 
> geom = ogr.CreateGeometryFromWkt( 'POINT(-110 36)' )
> 
> geom.Transform( ct )
> 
> I get:
> 
> warmerda at gdal65[58]% python test.py
> OGRCT: PROJ >= 4.8.0 features enabled
> OGRCT: Source: +proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs
> OGRCT: Target: +proj=tmerc +lat_0=0 +lon_0=36 +k=0.9996 +x_0=500000 +y_0=10000000 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
> ERROR 1: latitude or longitude exceeded limits
> 
> I believe the problem is that your data (-110 longitude) is no where near
> the central meridian of your transverse mercator projection (+36 longitude).
> 
> Some projections have areas of validity and attempts to reproject
> outside those will result in a failure with code 6.
> 
> I'm not sure why you did not see the error message I am seeing.

IIRC, older versions of the bindings silenced error messages to stdout but didn't throw exceptions by default.  Gregor might try issuing 'osr.UseExceptions()' or 'gdal.UseExceptions()' and then running his code to see if he can force it to give him a message.

Howard


More information about the gdal-dev mailing list