[gdal-dev] OSR Python: SR.ImportFromEPSG(4326), SR.ImportFromESRI(strPrj) return null values

Even Rouault even.rouault at mines-paris.org
Sun Dec 16 05:49:05 PST 2012


Le dimanche 16 décembre 2012 14:30:06, David Verbyla a écrit :
> I am a newbie to OGR/OSR using Python 2.7.2, please excuse my ignorance:
> 
> I'm having problems creating spatial reference using either .ImportFromEPSG
> or .ImportFromESRI(prjfile string).
> Yet .SetWellKnownGeogCS works fine.
> 
> from osgeo import ogr
> import osr,os
> testSR = osr.SpatialReference()
> testSR.SetWellKnownGeogCS("WGS84")
> print testSR.ExportToPrettyWkt()
> #returns
> #GEOGCS["WGS 84",
>  #   DATUM["WGS_1984",
> #....and so on...
> 
> testSR.ImportFromEPSG(4326)#returns 6

Works for me. My bet is that, in your configuration, the GDAL_DATA environement 
variable does not point to the path where the GDAL .csv files are stored.

> print testSR.ExportToPrettyWkt() #returns zero length string
> 
> prjFile = open('c:/test/GCS_WGS84.prj')
>  strPrj  = prjFile.readline() #returns string with len 145
>  testSR.ImportFromESRI(strPrj)#returns 5

Yes, ImportFromESRI() has a particular interface. It takes an array of 
strings, not a string.

So use  testSR.ImportFromESRI([strPrj])

>  print testSR.ExportToPrettyWkt() #returns zero length string


More information about the gdal-dev mailing list