We're updating the issue view to help you get more done. 

GeoPackage DataStore cannot write Z coordinates

Description

When using a SimpleFeatureStore from a DataStore created by the GeoPkgDataStoreFactory, Z-coordinates are not written to the GeoPackage.

E.g.

1 2 3 4 DataStore dataStore = new GeoPkgDataStoreFactory().createDataStore(singletonMap("database", Paths.get("./z-test.gpkg").toFile())); dataStore.createSchema(myCollectionWithZCoords.getSchema()); SimpleFeatureStore featureStore = (SimpleFeatureStore) dataStore.getFeatureSource(myCollectionWithZCoords.getSchema().getTypeName()); featureStore.addFeatures(myCollectionWithZCoords);

results in a GeoPackage with 2D coordinates.

As far as I have been able to trace it, the reason is that GeoPkgDialect#postCreateTable(...) creates a new FeatureEntry with no way to .setZ(true).
Other SqlDialect implementations seem to expect/respect a Hints.COORDINATE_DIMENSION on the GeometryDescriptor, e.g.

1 type.getGeometryDescriptor().getUserData().put(Hints.COORDINATE_DIMENSION, 3);

which, while somewhat obscure, seems to be a consistent and robust way of doing it.

It is, in fact, possible to get the GeoPkgDialect to write Z coordinates by manually creating a FeatureEntry and storing it on the feature type's UserData, but this seems more like a quirk than an intended feature, and feels rather brittle.

It seems like it would be fairly easy to let the GeoPkgDialect be configured with the COORDINATE_DIMENSION hint for consistency.

-In an ideal world, the DataStores could be aware of the axes of the CRS, but that is probably non-trivial, and we'd likely need the hint option still.

Environment

None

Status

Assignee

Unassigned

Reporter

Jes Wulfsberg Nielsen

Triage

None

Components

Affects versions

21.2

Priority

Medium