[gdal-dev] python CreateFeature() error when converting OGR features from gpsbabel layer to PostGIS layer

James Hiebert hiebert at uvic.ca
Thu Nov 1 11:41:04 PDT 2012


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)
    rv = wlyr.CreateFeature(feat)
    fid_map[fFID] = feat.GetFID()

It had been working great until the other day when I added another field (start_time timestamp with time zone) to the 'tracks' table in the database.  Oddly, with this new field in the destination layer, the call to CreateFeature() fails.  Looking into the PG query log, I see that ogr is making a curious choice of insertion fields.  The INSERT statement is:

INSERT INTO "tracks" ("wkb_geometry" , "name", "number", "start_time") VALUES ('<geometry text>'::GEOMETRY, '279', 15, 'MULTILINESTRING') RETURNING "ogc_fid"

Note that the last field in the insert statement says "start_time" and it's trying to insert 'MULTILINESTRING' in the field.  The source layer doesn't have any fields named start_time, so I'm not even sure why CreateFeature() would try to insert something for it, and it certainly doesn't have anything to do with the geometry type.

FWIW, ogr2ogr appears to do the right thing and only uses fields ("wkb_geometry" , "name", "number"), but it doesn't meet my needs for a number of other reasons.  Is this a bug in the python bindings for CreateFeature()?  Or are there any other leads that I should follow?  I'm using GDAL 1.9.1.

Thanks in advance for any help that can be offered.

~James


More information about the gdal-dev mailing list