[gdal-dev] python CreateFeature() error when converting OGR features from gpsbabel layer to PostGIS layer
Even Rouault
even.rouault at mines-paris.org
Thu Nov 1 12:58:10 PDT 2012
Selon James Hiebert <hiebert at uvic.ca>:
> Hi All,
>
> For months I've been happily pulling GPS tracks into PostGIS using ogr in a
> pretty simple python script. The essence of it approximately this:
>
> rlyr = ogr.Open(gpsbabel_src).GetLayerByName('tracks')
> wlyr = ogr.Open(pg_con_string).GetLayerByName('tracks')
>
> fid_map = {}
>
> for feat in rlyr:
> fFID = feat.GetFID()
> feat.SetFID(-1)
The error is there. It is illegal to call CreateFeature() on layer wlyr directly
with a feature from layer rlyr. You need to instanciate a feature with the layer
definition of layer wlyr, and copy the fields from the source feature into it
src_feat = feat
feat = ogr.Feature(wlyr.GetLayerDefn())
feat.SetFrom(src_feat)
> rv = wlyr.CreateFeature(feat)
> fid_map[fFID] = feat.GetFID()
>
More information about the gdal-dev
mailing list