ace@aced:/home/shared/srcsAced/gdalautotest_trunk$ ipython Python 2.5.2 (r252:60911, Jan 4 2009, 21:59:32) In [1]: import ogr/usr/local/lib/python2.5/site-packages/osgeo/gdal.py:81: DeprecationWarning: ogr.py was placed in a namespace, it is now available as osgeo.ogr In [2]: import gdal In [3]: pg_ds = ogr.Open( 'PG:dbname=autotest password=aced1234', update = 1 ) In [4]: pg_dr = ogr.GetDriverByName( 'PostgreSQL' ) In [9]: sql_lyr = pg_ds.ExecuteSQL('SELECT postgis_version()') In [10]: tRes = sql_lyr.next() In [14]: tRes.items() Out[14]: {'postgis_version': '1.5 USE_GEOS=1 USE_PROJ=1 USE_STATS=1 USE_LIBXML2=1'} In [16]: pg_ds.ReleaseResultSet(sql_lyr) In [22]: pg_lyr = pg_ds.CreateLayer( 'tpoly',options = [ 'DIM=3' ] ) In [23]: pg_lyr.TestCapability(ogr.OLCFastSpatialFilter) Out[23]: True In [24]: pg_lyr.TestCapability(ogr.OLCFastGetExtent) Out[24]: True In [25]: pg_lyr.TestCapability(ogr.OLCRandomRead) Out[25]: True In [26]: pg_lyr.TestCapability(ogr.OLCFastFeatureCount) Out[26]: True In [28]: pg_lyr.TestCapability(ogr.OLCFastSetNextByIndex) Out[28]: True In [29]: try: ....: ogr.OLCStringsAsUTF8 ....: if not pg_lyr.TestCapability(ogr.OLCStringsAsUTF8): ....: print 'fail' ....: ....: except: ....: pass ....: Out[29]: 'StringsAsUTF8' In [32]: def quick_create_layer_def( lyr, field_list): ....: for field in field_list: ....: name = field[0] ....: if len(field) > 1: ....: type = field[1] ....: else: ....: type = ogr.OFTString ....: field_defn = ogr.FieldDefn( name, type ) ....: if len(field) > 2: ....: field_defn.SetWidth( int(field[2]) ) ....: if len(field) > 3: ....: field_defn.SetPrecision( int(field[3]) ) ....: lyr.CreateField( field_defn ) ....: field_defn.Destroy() ....: ....: In [33]: quick_create_layer_def( pg_lyr, ....: [ ('AREA', ogr.OFTReal), ....: ('EAS_ID', ogr.OFTInteger), ....: ('PRFEDEA', ogr.OFTString), ....: ('SHORTNAME', ogr.OFTString, 8) ] ) ERROR 1: ALTER TABLE "tpoly" ADD COLUMN "area" FLOAT8 ERROR: relation "tpoly" does not exist ERROR 1: ALTER TABLE "tpoly" ADD COLUMN "eas_id" INTEGER ERROR: relation "tpoly" does not exist ERROR 1: ALTER TABLE "tpoly" ADD COLUMN "prfedea" VARCHAR ERROR: relation "tpoly" does not exist ERROR 1: ALTER TABLE "tpoly" ADD COLUMN "shortname" CHAR(8) ERROR: relation "tpoly" does not exist In [34]: pg_ds.CreateLayer( 'tpoly',options = [ 'DIM=3' ] ) ERROR 1: Layer tpoly already exists, CreateLayer failed. Use the layer creation option OVERWRITE=YES to replace it. ## at this point, there is one schema, public ## and the db looks like this autotest=# \d List of relations Schema | Name | Type | Owner --------+-------------------+-------+------- public | geography_columns | view | ace public | geometry_columns | table | ace public | spatial_ref_sys | table | ace (3 rows)