[Gdal-dev] How can I get coordinate system and projection from shape files?

Frank Warmerdam warmerdam at pobox.com
Tue Nov 1 09:44:57 EST 2005


On 11/1/05, lky <moon_inwell at 163.com> wrote:
> Frank Warmerdam,
>
> Thanks for your help.
>
> I have understood how to get the coordinate system and projection from .prj file. But I have another question about this. Since I can get the coordinate system and projection from .prj file, I also can write these information to it. But I didn't find the support about this. Can you tell me how to write the files?


Kunyang Li,

The only way to write the projection to a shapefile layer
through OGR is to pass it at the point the layer is created.
That is, pass the appropriate OGRSpatialReference into the
OGRDataSource::CreateLayer() call.

If you really need to generate a .prj file for a shapefile later
you can do it manually.  To do that, setup an appropriate
OGRSpatialReference, then invoke morphToESRI() on it
to convert the format to match what ESRI software expects.
Then exportToWkt() and manually write the resulting string
to the .prj file yourself.

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