[gdal-dev] ogr python pg GetLayerByName / CreateLayer
Even Rouault
even.rouault at mines-paris.org
Tue May 20 01:29:33 PDT 2014
Selon Martin Landa <landa.martin at gmail.com>:
> Hi all,
>
> sample script to reproduce:
>
> """
> from osgeo import ogr
>
> odrv = ogr.GetDriverByName("PostgreSQL")
> ods = odrv.Open("PG:dbname=pgis_vfr", True)
> layerName = 'obce'
> if not ods.GetLayerByName(layerName):
> print "Layer not found, creating..."
> ods.CreateLayer(layerName, None, ogr.wkbPoint, [])
> else:
> print "Layer found"
>
> ods.SyncToDisk()
> ods.Destroy()
> """
>
> 1) first run - table exists in DB
>
> Layer found
>
> 2) drop table obce;
>
> 3) second run
>
> ERROR 1: No field definitions found for 'obce', is it a table?
> <- this goes from GetLayerByName() / ReadTableDefinition()
> <- why report it as an error, I just what to check if layer exists...
Since that path is also taken when discovering existing spatial layers, this
could make some sense at the time where geometry_columns was a table and not a
view as in PostGIS 2.X now, and you could imagine some inconsistency where a
table would remain declared in geometry_columns but did not exist.
>
> Layer not found, creating...
>
> Using GDAL 1.12dev, PostGIS 2.1.
Is it new to the -dev version ? I don't think so, but anyway, feel free to
change the error into a CPLDebug message. The error seems to be emitted there
http://trac.osgeo.org/gdal/browser/trunk/gdal/ogr/ogrsf_frmts/pg/ogrpgtablelayer.cpp#L380
>
> Thanks, Martin
>
> --
> Martin Landa * http://geo.fsv.cvut.cz/gwiki/Landa
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>
More information about the gdal-dev
mailing list