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:
> 
> warme...@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_______________________________________________
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to