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

Frank Warmerdam warmerdam at pobox.com
Thu Dec 9 12:08:40 EST 2010


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.

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent



More information about the gdal-dev mailing list