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

lky moon_inwell at 163.com
Wed Nov 2 08:21:22 EST 2005


Frank Warmerdam:

Thanks for your bounteous help.

Using the methods you teld me, I have finished the program that I read the data from one shapefile ,and  wrote it to the other one after I transformed their coordinate. But there still some problems in the program. I can use the "transform" method to transform the obejct of class OGRMultiPolygon. But I can't give the coordinate system and projection which I order to the OGRDataSource pointer. 

Here, poSourceSRS is a pointer of the coordinate system and projection of the source data,and poTargetSRS is a pointer of the coordinate system and projection of the target data.I have tried two ways, but both failed.Firstly, I got the poSourceSRS by the OGRLayer::GetSpatialRef() method, but I can't change this pointer. Secondly I use the TargetSRS in the OGRDataSource::CreateLayer() method to specify the coordinate system and projection, I will get the result. But this is not useful in the shapefile. When I open the shapefile by ArcMap, the note pop up that is "Note: one or more layers is missing spatial reference information.  Data from these layers cannot be projected.".

Perhaps I can't let you clear my meaning because my poor English. I repeat it again.

I transform one data geometry by changing its coordinate system and projection. I have transform the geometry, but I don't know how to write the new coordinate system and projection to the .prj file.

Best Regards

Kunyang Li
----- Original Message ----- 
From: "Frank Warmerdam" <warmerdam at pobox.com>
To: "lky" <moon_inwell at 163.com>
Cc: "gdal 邮件列表" <gdal-dev at lists.maptools.org>
Sent: Tuesday, November 01, 2005 10:44 PM
Subject: Re: [Gdal-dev] How can I get coordinate system and projection from shape files?


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