6

When creating a new table (PostGIS) using OGR/GDAL (2.1+), is there a way to select a specific name for the geometry field (such as geom), rather than using the default name?

I created a new table via python3 ogr/grdal liek this:

ds = gdal.OpenEx(connection_string, gdal.OF_VECTOR | gdal.OF_UPDATE)
lyr = ds.CreateLayer( "mylayer", XXX, ogr.wkbLineString)

The problem is that I can't find a parameter to specify the name of the geometry field, only its type. In the table created, the geometry field seems to be called wkb_geometry by default:

wkb_geometry geometry(LineString,26945)

Is there a parameter or option to let CreateLayer() use a different name such as geom?

Related question: Use Postgis to convert wkb_geometry data type to geom datatype

1 Answer 1

5

As you can see from http://gdal.org/python/osgeo.ogr.DataSource-class.html#CreateLayer, CreateLayer support also "options" which are "None" by default.

The papszOptions argument can be used to control driver specific creation options. These options are normally documented in the format specific documentation.

Usage example for PostgeSQL and Python can be found from the GDAL autotest script https://trac.osgeo.org/gdal/browser/trunk/autotest/ogr/ogr_pg.py

See for example row 5191:

lyr = gdaltest.pg_ds.CreateLayer('ogr_pg_82', geom_type = ogr.wkbNone, options = ['GEOMETRY_NAME=another_name'])

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.