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

Frank Warmerdam warmerdam at pobox.com
Mon Oct 31 10:03:01 EST 2005


On 10/31/05, lky <moon_inwell at 163.com> wrote:
>
> Hello,everyone:
>
> I'm a new learner of the gdal. During my study, I met some problems. I hope
> I can find help here.
>
> I found these is one sentence "If a .prj files in old Arc/Info style or new
> ESRI OGC WKT style is present, it will be read and used to associate a
> projection with features." in \ogr\dev_shapefile.html.
>
> And I found there are some *.prj files with the same name shapefile in
> directory C:\arcgis\arcexe83\Reference Systems(The directory which I install
> arcinfo).In the ArcMap, that the frame map file is *.mxt.
>
> I try to use the OGRSFDriverRegistrar::Open function to open these *.prj
> files but I failed.
>
> So I have the following questions.
>
> 1. Who can explain the use of these *.prj files in this directory? Which
> shapefiles do they support? Or they only support project mode for AcrMap?

Kunyang Li,

You should open the shapefile normally with OGRSFDriverRegistrar::Open()
and then fetch the layers from the datasource.  To find the coordinate
system of a layer you can call OGRLayer::GetSpatialRef() to get a handle
to the corresponding OGRSpatialReference object.

This method will read it from a correspondingly named .prj file if it
is present.

> 2. What is the relation with the *.prj and *mxt files?

I don't know anything about mxt files.

> 3. How can I read the coordinate system and projection from the *.prj files?
> And whether this prj file support the coordinate system and projection for
> the same name shapefile or for the shapefiles in the same directory?

OGR assumes a .prj file applies to the shapefile with the same
base filename.  If there is no corresponding .prj file, then GetSpatialRef()
will return NULL.

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