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

Gregor at HostGIS gregor at hostgis.com
Wed Dec 8 19:40:44 EST 2010


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 
code 6, according to the OGR source is simply OGRERROR

II guess the rest is best explained by example:

from osgeo import ogr, osr

shapefile  = "zt04_d00.shp" 

driver     = ogr.GetDriverByName('ESRI Shapefile')
datasource = driver.Open(shapefile,0)
layer      = datasource.GetLayer()
feat       = layer.GetFeature(0)
geom       = feat.GetGeometryRef()

# ta-da, a geometry and here is its WKT. Good
geom.ExportToWkt()

# Generate the source and target SRS
# and a SRS transform object
# these all return code 0 which seems good

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)


Any ideas?

-- 
HostGIS, Open Source solutions for the global GIS community
Greg Allensworth - SysAdmin, Programmer, GIS Person, Security
    Network+   Server+   A+   Security+   Linux+
    PHP   PostgreSQL   MySQL   DHTML/JavaScript/AJAX

"No one cares if you can back up — only if you can recover."


More information about the gdal-dev mailing list