[gdal-dev] Setting the spatial reference of an existing shapefile with OGR

Frank Warmerdam warmerdam at pobox.com
Thu Nov 12 20:02:13 EST 2009

Jason Roberts wrote:
>> Yes. Or... you could cheat a bit. In the case of a shapefile, the spatial
>> reference is written in a .prj file. So technically you can create a fake
> empty
>> shapefile with the right spatial reference, close it, rename the .prj to
> have
>> the same basename as your shapefile of interes and re-open it.
> Ah, excellent. Thanks for this suggestion!
> It looks like the .prj file simply contains the WKT. Would it be sufficient
> to just call OGRSpatialReference::exportToWKT and write the string to the
> .prj file directly? In my situation that would be slightly cleaner. If this
> is a good approach, should I also call morphToESRI first, if I know the
> coordinate system has not already been morphed to ESRI?


Yes, this would be appropriate.  Note that in all but exceptional circumstances
the OGRSpatialReference is *not* in ESRI format, so you should expect to
call morphToESRI() before exporting to WKT.

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