[Gdal-dev] python ogr - creating a feature in a postgis layer

Frank Warmerdam warmerdam at pobox.com
Mon Apr 2 02:34:50 EDT 2007


Jason Gaudet wrote:
> Hello list.
> 
> I am attempting to take information from an ESRI Shapefile data source 
> and write it to a PostGIS data source. The data I am using is all in the 
> same projection, but I cannot create a new feature in the postgis layer. 
> When I try to:
> 
> postgisLayer.CreateFeature(newfeature)
> 
> My SRID is set to -1, where it should be set to 42102 (I am using the 
> older projection format, so that is what the enforce_srid_constraint for 
> my table is expecting.)  I have searched the net and have not yet found 
> a way to change the SRID attribute in the geometry.  So far I've tried 
> this:
> 
> newspatial = osr.SpatialReference()
> newspatial.ImportFromEPSG(42102)
> newfeatureGeometry.AssignSpatialReference(newspatial)
> 
> But when I try to write to the postgis db it still shows the SRID as 
> being -1. I'm a GIS newbie, so I'm still a little vague about what *all* 
> of the data structures represent, but I've been spinning my wheels on 
> this for a week now. I'd be very grateful for any help.

Jason,

Was this an existing PostGIS layer or a new one you created as part of
the script.  If you created it, then the key is likely to pass the
osr.SpatialReference() in the CreateLayer() call.  If it is an
existing layer then it may be that the driver isn't capturing the existing
layer's SRID properly for use when creating new features.  I believe, but
am not certain, that the spatialreference on the feature itself is ignored
by the postgis driver.

We are closing in on the 1.4.1 release, and with Mateusz (a relative
PostGIS expert available) this is an excellent week to squash OGR/PostGIS
bugs.  So if you can provide enough detail for us to reproduce this, we
can hopefully fix it.

PS. What version of GDAL are you using?  There were some important fixes for
PostGIS coordinate system handling a while ago.  I'm not sure if they were
in 1.4.0 or not, but they are definately in the most recent FWTools
distributions.

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    | President OSGeo, http://osgeo.org




More information about the Gdal-dev mailing list