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

Frank Warmerdam warmerdam at pobox.com
Fri Nov 4 10:30:59 EST 2005


On 11/4/05, lky <moon_inwell at 163.com> wrote:
> I read the data from the shapefile by OGRSFDriverRegistrar::Open() method , then I transform the data by OGRCoordinateTransformation::Transform() method. But the coordinate system and projection of the OGRDataSource is not changed at all.

Kunyang Li,

You just transformed the point location, you didn't do anything to
change the coordinate system of the layer as a whole.   You also
didn't do anything to actually write the results back out to the original
layer (if that was your intention).   I'm not sure that in-place update is
even supported by the Shapefile driver.

> How can I change the spatial reference?

 o Create a new layer for the output.
 o Make sure you pass the altered OGRSpatialReference to the
    CreateLayer() call.
 o You might as well just call transform() on the geometry
    instead of extracting the point and transforming that.

Make sure you follow the translation example on the OGR page.
It is important to create create all the fields on the new layer
with CreateLayer(), and to make sure the feature get converted
from the old layer definition to the new layer definition (even
though they seem the same).

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