1

I am using ogr2ogr to export a table in Oracle to GPKG. The table in Oracle has two columns (GEOMETRY_2, GEOMETRY_20) with geometry info.

enter image description here

I am using the following ogr2ogr command to export the table into GPKG.

ogr2ogr -progress -f "GPKG" C:\Users\test\test.gpkg  OCI:{username}/{password}@{db_alias}:{table_name -sql "select * from TableName@XXX" -append -nln "TableName" -lco GEOMETRY_NAME=geometry -a_srs EPSG:31287

The command creates the GPKG as in the image. What I do not understand, which geometry columns (GEOMETRY_2, GEOMETRY_20) ogr2ogr uses to create the GEOMETRY column in GPKG. If it uses GEOMETRY_2, is there any way still have GEOMETRY_20 in the GPKG?

enter image description here

7
  • What's the difference between the two geometry columns? Aug 30 at 9:37
  • The same object is generalized with two different tolerances and the columns are representing.
    – Nil
    Aug 30 at 9:41
  • I'm not very familiar with this situation. But it's an intersting one. What happens if you load the gpkg in a GIS? Does it display the data? Aug 30 at 10:01
  • Yes, I can open the gpkg in QGIS. As far as I see, if I do not specify the geometry column name, it peaks GEOMETRY_2 and I can see the objects in QGIS. But if I run this command -sql "select ID, GEOMETRY_20 as GEOMETRY from tablename , I do get the geometry from GEOMETRY_20 and again it is displayed in QGIS
    – Nil
    Aug 30 at 10:06
  • Does that not answer your own question than? Or am I missing something? Aug 30 at 11:34
1

The documentation about how the support for multiple geometry fields is implemented in GDAL is in https://gdal.org/development/rfc/rfc41_multiple_geometry_fields.html. It does not say clearly which geometry is the default geometry but I suppose that it is the first one that GDAL finds. Better not to trust on the defaults but select the geometry explicitly with SQL just like you have already done.

When it comes to GeoPackage, you are out of luck because the GeoPackage standard allows only one geometry field. Excerpt from the standard:

Requirement 30

A feature table SHALL have only one geometry column. Feature data models [B23] from non-GeoPackage implementations that have multiple geometry columns per feature table MAY be transformed into GeoPackage implementations with a separate feature table for each geometry type whose rows have matching integer primary key values that allow them to be joined in a view with the same column definitions as the non-GeoPackage feature data model with multiple geometry columns.

You must select some other format or model your data in a different way. SpatiaLite does support multiple geometry columns and is otherwise rather close to GeoPackage.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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