Is it possible to add features to an existing PostGIS table using Python
OGR/GDAL? I've tried these two approaches:

# Approach 1. Results in:
# ERROR 1: Layer tracks already exists, CreateLayer failed.
# Use the layer creation option OVERWRITE=YES to replace it.
ds = ogr.Open("PG:dbname='db' user='user'")
srs = osr.SpatialReference()
srs.ImportFromEPSG(4326)
layer = ds.CreateLayer('tracks', srs, ogr.wkbMultiLineString,
['OVERWRITE=NO'] )

# Approach 2. Results in:
# ERROR 1: Invalid index : -1
# ERROR 6: CreateFeature : unsupported operation on a read-only datasource.
ds = ogr.Open("PG:dbname='db' user='user'")
layer = ds.GetLayerByName('tracks')
# set fields, etc.
layer.CreateFeature(outFeature)

Think I could accomplish it via SQL statements and ds.ExecuteSQL(), and
I've found examples using psycopg2 (or SQLAlchemy) instead. Just wondering
if it's directly possible using Python OGR/GDAL.

Thanks,
Gerard
_______________________________________________
gdal-dev mailing list
[email protected]
https://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to