[gdal-dev] ogr python pg GetLayerByName / CreateLayer

Martin Landa landa.martin at gmail.com
Tue May 20 00:42:16 PDT 2014


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...

Layer not found, creating...

Using GDAL 1.12dev, PostGIS 2.1.

Thanks, Martin

-- 
Martin Landa * http://geo.fsv.cvut.cz/gwiki/Landa


More information about the gdal-dev mailing list