[gdal-dev] How to add a OGRSpatialReference to an OGRLayer?

Tom Kazimiers 2voodoo at gmx.de
Tue Sep 30 17:11:54 EDT 2008

Frank Warmerdam schrieb:
> On Tue, Sep 30, 2008 at 10:55 PM, Tom Kazimiers <2voodoo at gmx.de> wrote:
>> Hi,
>> unfortunately I have no experience with OGR and want to display a
>> SHP-File (on WinCE, but I don't think that matters). The rendering works
>> well, but is slow - so I will add some caching. One thing of faster
>> rendering is to use SetSpatialFilterRect() I guess. This works, as
>> written in the docs, with comparing the coorinates (they must be in the
>> same coorinate systeme). Sadly, my shp files do not have any
>> SpatialReference (I get NULL returned from OGRLayer::GetSpatialRef() ).
>> If I use SetSpatialFilterRect() with this shp file datasource I will get
>> back absolutely no features. I thought the reason for this could be the
>> missing spatial referenc. So I wonder how to add/change a spatial
>> reference (e. g. a coorinate interpretation, right?) to a layer?
> Tom,
> In fact there is no GDAL way to do this.  You can however manually
> put a .prj file with an ArcGIS PE string along side the shapefiles.
> Best regards,

thanks for the answer. So does this actually mean I have to look if
there is a .prj file - if not create one by myself (maybe ask the user
for the parameters) and then load the file with OGR? And if a spatial
reference of a layer is NULL I have to create also a (new) .prj file (in
case of the one provided is damaged).

thanks, regards,

More information about the gdal-dev mailing list