[Gdal-dev] Opening PostGIS databases with Python & OGR
Frank Warmerdam
warmerdam at pobox.com
Fri Jul 27 10:54:06 EDT 2007
Sean Fulton wrote:
> However, if the database already has an existing layer (e.g. added with
> ogr2ogr) using ogr.Open() from Python works. Can I get ogr.Open() to
> give an error message? Is there a CPLGetLastErrorMsg() equivalent in
> the Python API?
Sean,
If you open the database in update mode (pass a second argument with the
value 1 to Open()) then OGR should be able to open a postgres database
with no apparent layers. This is a quirk of the postgres driver in OGR
which assumes something must have gone wrong if it didn't find any layers.
You can call gdal.GetLastErrorMsg() in Python, but unfortunately it won't
return anything in this case since this code does not issue an error
message ... just return an error code.
OGR started out mostly avoiding use of CPL errors, instead returning
error codes from functions. Since the beginning CPL error reporting has
become fairly common in OGR but is still not comprehensive. This mixture
of error handling modes is an unfortunate weakness of OGR as it stands.
Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush | President OSGeo, http://osgeo.org
More information about the Gdal-dev
mailing list