[FWTools] Projections OGR OSR .prj files in Python

Frank Warmerdam warmerdam at pobox.com
Tue Oct 24 23:03:59 EDT 2006


David Fawcett wrote:
> I am attempting to set input and output SRSs and transform the data when 
> necessary.  I am stuck on a small part of it. 
> 
> I am trying to set the input SRS and then convert it to WKT so I can 
> create a .prj file.  I am getting an error on the ExportToWkt method. 
> 
> Here is a small script that I whipped up to demonstrate it:
> 
> import ogr, osr, sys, os
> 
> srs_in = osr.SpatialReference()
> 
> proj_in = srs_in.ImportFromEPSG(4326)
 >
> wkt_proj = proj_in.ExportToWkt()
> 
> print wkt_proj

David,

The ImportFromEPSG() method modifies the srs_in object and returns an
error code.  So the script should I think look like:

import ogr, osr, sys, os

srs_in = osr.SpatialReference()

srs_in.ImportFromEPSG(4326)

wkt_proj = srs_in.ExportToWkt()

print wkt_proj

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    | President OSGeo, http://osgeo.org



More information about the FWTools mailing list