1

I tried calling gdf.geometry.name and I always get back "geometry" as the geometry column name. Using GDAL's ogrinfo, I get the actual name which is "geom".

Is there another way of getting the correct geometry column name without parsing the output from ogr?

0

1 Answer 1

4

Not sure if it's possible via GeoPandas but at least quite easy with ogr Python bindings (you have them if you have Geopandas). The dirty way e.g parsing is not required.

import ogr
# PostgreSQL recipe
databaseServer,databaseName,databaseUser,databasePW = 'your_host', 'your_dbname', 'your_user', 'your_password'
connString = f"PG: host={databaseServer} dbname={databaseName} user={databaseUser} password={databasePW}" 

conn = ogr.Open(connString)

l = conn.GetLayerByName('your_layer_name')
print(l.GetGeometryColumn())

# GPKG recipe

conGpkg = "your_gpkg.gpkg"
conn1 = ogr.Open(conGpkg)
# List layers names
layers = [layer.GetName() for layer in conn1]
# First layer name
layer1 = layers[0]

l1 = conn1.GetLayerByName(layer1)
print(l1.GetGeometryColumn())
0

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.