This is an automated email from the ASF dual-hosted git repository. jsorel pushed a commit to branch feat/ogr in repository https://gitbox.apache.org/repos/asf/sis.git
commit afbaafb4f9ef10f599c57584a8af3f0bdb9caca7 Author: jsorel <johann.so...@geomatys.com> AuthorDate: Wed Oct 9 10:55:36 2024 +0200 Decode OGR vector layers, rebuild FeatureTypes --- .../org.apache.sis.feature/main/module-info.java | 1 + .../org.apache.sis.storage.DataStoreProvider | 2 +- .../main/module-info.java | 4 + .../main/org/apache/sis/storage/gdal/GDAL.java | 110 ++++++++++++ .../org/apache/sis/storage/gdal/GDALStore.java | 5 +- .../org/apache/sis/storage/gdal/OGRFeatureSet.java | 141 ++++++++++++++++ .../org/apache/sis/storage/gdal/OGRFieldType.java | 85 ++++++++++ .../apache/sis/storage/gdal/OGRwkbByteOrder.java | 36 ++++ .../sis/storage/gdal/OGRwkbGeometryType.java | 186 +++++++++++++++++++++ .../main/org/apache/sis/storage/gdal/Opener.java | 2 +- .../org/apache/sis/storage/gdal/SpatialRef.java | 13 ++ 11 files changed, 582 insertions(+), 3 deletions(-) diff --git a/endorsed/src/org.apache.sis.feature/main/module-info.java b/endorsed/src/org.apache.sis.feature/main/module-info.java index a99f398169..0fa39a382d 100644 --- a/endorsed/src/org.apache.sis.feature/main/module-info.java +++ b/endorsed/src/org.apache.sis.feature/main/module-info.java @@ -55,6 +55,7 @@ module org.apache.sis.feature { org.apache.sis.storage.shapefile, // In the "incubator" sub-project. org.apache.sis.portrayal, org.apache.sis.portrayal.map, // In the "incubator" sub-project. + org.apache.sis.storage.gdal, // In the "optional" sub-project. org.apache.sis.gui; // In the "optional" sub-project. exports org.apache.sis.geometry.wrapper to diff --git a/optional/src/org.apache.sis.storage.gdal/main/META-INF.services/org.apache.sis.storage.DataStoreProvider b/optional/src/org.apache.sis.storage.gdal/main/META-INF.services/org.apache.sis.storage.DataStoreProvider index 25f274232b..fe0f6d43f6 100644 --- a/optional/src/org.apache.sis.storage.gdal/main/META-INF.services/org.apache.sis.storage.DataStoreProvider +++ b/optional/src/org.apache.sis.storage.gdal/main/META-INF.services/org.apache.sis.storage.DataStoreProvider @@ -1,4 +1,4 @@ # Workaround for Maven bug https://issues.apache.org/jira/browse/MNG-7855 # The content of this file is automatically derived from module-info.class file. # Should be used only if the JAR file was on class-path rather than module-path. -org.apache.sis.storage.gdal.GdalStoreProvider +org.apache.sis.storage.gdal.GDALStoreProvider diff --git a/optional/src/org.apache.sis.storage.gdal/main/module-info.java b/optional/src/org.apache.sis.storage.gdal/main/module-info.java index e4d87b9584..c7c98de106 100644 --- a/optional/src/org.apache.sis.storage.gdal/main/module-info.java +++ b/optional/src/org.apache.sis.storage.gdal/main/module-info.java @@ -52,6 +52,10 @@ module org.apache.sis.storage.gdal { requires transitive org.apache.sis.referencing; requires transitive org.apache.sis.storage; + // Optional dependencies to be provided by user. + requires static esri.geometry.api; + requires static org.locationtech.jts; + exports org.apache.sis.storage.gdal; provides org.apache.sis.storage.DataStoreProvider diff --git a/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/GDAL.java b/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/GDAL.java index c70763fc39..69703f405b 100644 --- a/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/GDAL.java +++ b/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/GDAL.java @@ -274,6 +274,86 @@ final class GDAL extends NativeFunctions { */ final MethodHandle adviseRead; + /** + * <abbr>GDAL</abbr> {@code CPLErr GDALDatasetGetLayerCount(Pointer hDS)}. + * Get the number of layers in this dataset. + */ + final MethodHandle datasetGetLayerCount; + + /** + * <abbr>GDAL</abbr> {@code CPLErr GDALDatasetGetLayer(Pointer hDS, int index)}. + * Fetch a layer by index. + */ + final MethodHandle datasetGetLayer; + + /** + * <abbr>OGR</abbr> {@code Pointer CPLErr OGR_L_GetLayerDefn(Pointer hDS)}. + * Fetch the schema information for this layer. + */ + final MethodHandle ogrLayerGetLayerDefn; + + /** + * <abbr>OGR</abbr> {@code Pointer CPLErr OGR_L_GetName(Pointer hDS)}. + * Return the layer name. + */ + final MethodHandle ogrLayerGetName; + + /** + * <abbr>OGR</abbr> {@code Pointer CPLErr OGR_FD_GetFieldCount(Pointer hDS)}. + * Fetch number of fields on the passed feature definition. + */ + final MethodHandle ogrFeatureDefinitionGetFieldCount; + + /** + * <abbr>OGR</abbr> {@code Pointer CPLErr OGR_FD_GetFieldDefn(Pointer hDS)}. + * Fetch field definition of the passed feature definition. + */ + final MethodHandle ogrFeatureDefinitionGetFieldDefinition; + + /** + * <abbr>OGR</abbr> {@code int CPLErr OGR_Fld_GetType(Pointer hDS, int index)}. + * Fetch type of this field. + */ + final MethodHandle ogrFeatureDefinitionGetFieldType; + + /** + * <abbr>OGR</abbr> {@code Pointer CPLErr OGR_Fld_GetNameRef(Pointer hDS)}. + * Fetch name of this field. + */ + final MethodHandle ogrFeatureDefinitionGetFieldName; + + /** + * <abbr>OGR</abbr> {@code int CPLErr OGR_FD_GetGeomFieldCount(Pointer hDS)}. + * Fetch number of geometry fields on this feature. + */ + final MethodHandle ogrFeatureDefinitionGetGeomFieldCount; + + /** + * <abbr>OGR</abbr> {@code OGRGeomFieldDefnH OGR_FD_GetGeomFieldDefn(OGRFeatureDefnH hDefn, int iGeomField)}. + * Fetch geometry field definition of the passed feature definition. + */ + final MethodHandle ogrFeatureDefinitionGetGeomFieldDefinition; + + /** + * <abbr>OGR</abbr> {@code int CPLErr OGR_Fld_GetType(Pointer hDS, int index)}. + * Fetch geometry type of this field. + */ + final MethodHandle ogrFeatureDefinitionGetGeomFieldType; + + /** + * <abbr>OGR</abbr> {@code OGRwkbGeometryType CPL_DLL OGR_GFld_GetType( OGRGeomFieldDefnH )}. + * Fetch name of this field. + */ + final MethodHandle ogrFeatureDefinitionGetGeomFieldName; + + /** + * <abbr>OGR</abbr> {@code OGRSpatialReferenceH CPL_DLL OGR_GFld_GetSpatialRef(OGRGeomFieldDefnH)}. + * Fetch spatial reference system of this field. + */ + final MethodHandle ogrFeatureDefinitionGetGeomFieldSpatialRef; + + + /** * Creates the handles for all <abbr>GDAL</abbr> functions which will be needed. * @@ -288,6 +368,7 @@ final class GDAL extends NativeFunctions { final var acceptPointerReturnInt = FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS); final var acceptTwoPtrsReturnDouble = FunctionDescriptor.of(ValueLayout.JAVA_DOUBLE, ValueLayout.ADDRESS, ValueLayout.ADDRESS); final var acceptTwoPtrsReturnPointer = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS); + final var acceptPointerAndIntReturnPointer = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_INT); // Memory management free = lookup("VSIFree", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS)); @@ -394,6 +475,35 @@ final class GDAL extends NativeFunctions { ValueLayout.JAVA_INT, // GDALDataType eBDataType ValueLayout.ADDRESS)); // CSLConstList papszOptions + // Dataset layer API + datasetGetLayerCount = lookup("GDALDatasetGetLayerCount", acceptPointerReturnInt); + + datasetGetLayer = lookup("GDALDatasetGetLayer", acceptPointerAndIntReturnPointer); + + // OGR API + ogrLayerGetLayerDefn = lookup("OGR_L_GetLayerDefn", acceptPointerReturnPointer); + + ogrLayerGetName = lookup("OGR_L_GetName", acceptPointerReturnPointer); + + ogrFeatureDefinitionGetFieldCount = lookup("OGR_FD_GetFieldCount", acceptPointerReturnInt); + + ogrFeatureDefinitionGetFieldDefinition = lookup("OGR_FD_GetFieldDefn", acceptPointerAndIntReturnPointer); + + ogrFeatureDefinitionGetFieldType = lookup("OGR_Fld_GetType", acceptPointerReturnInt); + + ogrFeatureDefinitionGetFieldName = lookup("OGR_Fld_GetNameRef", acceptPointerReturnPointer); + + ogrFeatureDefinitionGetGeomFieldCount = lookup("OGR_FD_GetGeomFieldCount", acceptPointerReturnInt); + + ogrFeatureDefinitionGetGeomFieldDefinition = lookup("OGR_FD_GetGeomFieldDefn", acceptPointerAndIntReturnPointer); + + ogrFeatureDefinitionGetGeomFieldType = lookup("OGR_GFld_GetType", acceptPointerReturnInt); + + ogrFeatureDefinitionGetGeomFieldName = lookup("OGR_GFld_GetNameRef", acceptPointerReturnPointer); + + ogrFeatureDefinitionGetGeomFieldSpatialRef = lookup("OGR_GFld_GetSpatialRef", acceptPointerReturnPointer); + + // Set error handling first in order to redirect initialization warnings. setErrorHandler(null); diff --git a/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/GDALStore.java b/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/GDALStore.java index 748dc7d15c..f9613508ac 100644 --- a/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/GDALStore.java +++ b/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/GDALStore.java @@ -50,6 +50,7 @@ import org.apache.sis.util.privy.Constants; import org.apache.sis.util.privy.UnmodifiableArrayList; import org.apache.sis.util.iso.DefaultNameFactory; import org.apache.sis.system.Cleaners; +import org.apache.sis.util.ArraysExt; /** @@ -373,7 +374,9 @@ public class GDALStore extends DataStore implements Aggregate { if (subdatasets != null && !subdatasets.isEmpty()) { components = subdatasets; } else { - components = UnmodifiableArrayList.wrap(TiledResource.groupBySizeAndType(this, gdal, handle())); + final TiledResource[] rasters = TiledResource.groupBySizeAndType(this, gdal, handle()); + final OGRFeatureSet[] vectors = OGRFeatureSet.listVectors(this, gdal, handle()); + components = UnmodifiableArrayList.wrap(ArraysExt.concatenate(rasters, vectors)); } } finally { ErrorHandler.throwOnFailure(this, "components"); diff --git a/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/OGRFeatureSet.java b/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/OGRFeatureSet.java new file mode 100644 index 0000000000..d34b11ac6d --- /dev/null +++ b/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/OGRFeatureSet.java @@ -0,0 +1,141 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sis.storage.gdal; + +import java.lang.foreign.MemorySegment; +import java.util.stream.Stream; +import org.apache.sis.feature.builder.AttributeRole; +import org.apache.sis.feature.builder.AttributeTypeBuilder; +import org.apache.sis.feature.builder.FeatureTypeBuilder; +import org.apache.sis.feature.privy.AttributeConvention; +import org.apache.sis.referencing.crs.AbstractCRS; +import org.apache.sis.referencing.cs.AxesConvention; +import org.apache.sis.storage.AbstractFeatureSet; +import org.apache.sis.storage.DataStoreException; +import org.apache.sis.storage.panama.NativeFunctions; +import org.locationtech.jts.geom.LineString; +import org.locationtech.jts.geom.MultiLineString; +import org.locationtech.jts.geom.MultiPolygon; +import org.locationtech.jts.geom.Polygon; +import org.opengis.feature.Feature; +import org.opengis.feature.FeatureType; +import org.opengis.referencing.crs.CoordinateReferenceSystem; + +/** + * + * @author Johann Sorel (Geomatys) + */ +final class OGRFeatureSet extends AbstractFeatureSet { + + private final GDALStore store; + private final GDAL gdal; + private final MemorySegment dataset; + private final MemorySegment layer; + private FeatureType type; + + OGRFeatureSet(final GDALStore store, final GDAL gdal, final MemorySegment dataset, MemorySegment layer) { + super(store); + this.store = store; + this.gdal = gdal; + this.dataset = dataset; + this.layer = layer; + } + + @Override + public synchronized FeatureType getType() throws DataStoreException { + if (type != null) return type; + + try { + final MemorySegment driver = (MemorySegment) gdal.getDatasetDriver.invokeExact(dataset); + final String driverName = NativeFunctions.toString((MemorySegment) gdal.getName.invokeExact(driver)); + + final MemorySegment layerDef = (MemorySegment) gdal.ogrLayerGetLayerDefn.invokeExact(layer); + final String name = NativeFunctions.toString( ((MemorySegment) gdal.ogrLayerGetName.invokeExact(layer))); + + final FeatureTypeBuilder ftb = new FeatureTypeBuilder(); + ftb.addAttribute(Long.class).setName(AttributeConvention.IDENTIFIER_PROPERTY); + ftb.setName(name); + + // List feature type fields + final String[] fields = new String[(int)gdal.ogrFeatureDefinitionGetFieldCount.invokeExact(layerDef)]; + for (int i = 0 ; i<fields.length; i++) { + final MemorySegment fieldDef = (MemorySegment) gdal.ogrFeatureDefinitionGetFieldDefinition.invokeExact(layerDef,i); + final OGRFieldType type = OGRFieldType.valueOf((int) gdal.ogrFeatureDefinitionGetFieldType.invokeExact(fieldDef)); + final String fieldName = NativeFunctions.toString( (MemorySegment)gdal.ogrFeatureDefinitionGetFieldName.invokeExact(fieldDef)); + final Class<?> valueClass = type.getJavaClass(); + ftb.addAttribute(valueClass).setName(fieldName); + fields[i] = fieldName; + } + + // List geometric feature type fields + final String[] geomFields = new String[(int) gdal.ogrFeatureDefinitionGetGeomFieldCount.invokeExact(layerDef)]; + for(int i=0; i<geomFields.length; i++) { + final MemorySegment ogrGeomFieldDefnH = (MemorySegment) gdal.ogrFeatureDefinitionGetGeomFieldDefinition.invokeExact(layerDef,i); + final OGRwkbGeometryType typrgeom = OGRwkbGeometryType.valueOf( (int) gdal.ogrFeatureDefinitionGetGeomFieldType.invokeExact(ogrGeomFieldDefnH)); + geomFields[i] = NativeFunctions.toString((MemorySegment)gdal.ogrFeatureDefinitionGetGeomFieldName.invokeExact(ogrGeomFieldDefnH)); + if(geomFields[i].isEmpty()) geomFields[i] = "geometry"+i; + + //read CRS + final MemorySegment crsRef = (MemorySegment) gdal.ogrFeatureDefinitionGetGeomFieldSpatialRef.invokeExact(ogrGeomFieldDefnH); + final SpatialRef spatialRef = SpatialRef.createWithHandle(store, gdal, crsRef); + CoordinateReferenceSystem crs = spatialRef.parseCRS("listVectors"); + //force longitude first + crs = ((AbstractCRS)crs).forConvention(AxesConvention.RIGHT_HANDED); + + Class<?> geomClass = typrgeom.getJavaClass(); + if (driverName.toLowerCase().contains("shapefile")) { + //OGR Hack : shapefile geometry type is not correctly detected + //this seems to be because ogr shp driver do not make a difference betwen geom types + //https://code.djangoproject.com/ticket/7218 + if (Polygon.class.equals(geomClass)) geomClass = MultiPolygon.class; + if (LineString.class.equals(geomClass)) geomClass = MultiLineString.class; + } + + final AttributeTypeBuilder<?> attBuilder = ftb.addAttribute(geomClass).setName(geomFields[i]).setCRS(crs); + if (i == 0) attBuilder.addRole(AttributeRole.DEFAULT_GEOMETRY); // first geometry as default + } + type = ftb.build(); + } catch (Throwable e) { + throw GDAL.propagate(e); + } + return type; + } + + @Override + public Stream<Feature> features(boolean parallel) throws DataStoreException { + throw new DataStoreException("Not supported yet."); + } + + /** + * Returns featuresets found. + * + * @throws DataStoreException if an error occurred. + */ + static OGRFeatureSet[] listVectors(final GDALStore parent, final GDAL gdal, final MemorySegment dataset) + throws DataStoreException { + try { + final OGRFeatureSet[] array = new OGRFeatureSet[(int) gdal.datasetGetLayerCount.invokeExact(dataset)]; + for (int iLayer = 0; iLayer < array.length ; iLayer++) { + final MemorySegment layer = (MemorySegment) gdal.datasetGetLayer.invokeExact(dataset, iLayer); + array[iLayer] = new OGRFeatureSet(parent, gdal, dataset, layer); + } + return array; + } catch (Throwable e) { + throw GDAL.propagate(e); + } + } +} diff --git a/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/OGRFieldType.java b/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/OGRFieldType.java new file mode 100644 index 0000000000..12d52d136e --- /dev/null +++ b/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/OGRFieldType.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sis.storage.gdal; + +/** + * + * @author Hilmi Bouallegue (Geomatys) + * @author Johann Sorel (Geomatys) + */ +enum OGRFieldType { + /** Simple 32bit integer */ + OFTInteger(Integer.class), + /** List of 32bit integers */ + OFTIntegerList(Object.class), + /** Double Precision floating point */ + OFTReal(Double.class), + /** List of doubles */ + OFTRealList(Object.class), + /** String of ASCII chars */ + OFTString(String.class), + /** Array of strings */ + OFTStringList(Object.class), + /** deprecated */ + OFTWideString(String.class), + /** deprecated */ + OFTWideStringList(Object.class), + /** Raw Binary data */ + OFTBinary(Object.class), + /** Date */ + OFTDate(Object.class), + /** Time */ + OFTTime(Object.class), + /** Date and Time */ + OFTDateTime(Object.class), + /** Single 64bit integer */ + OFTInteger64(Long.class), + /** List of 64bit integers */ + OFTInteger64List(Object.class), + OFTMaxType(Object.class); + + private final Class javaClass; + + OGRFieldType(Class javaClass){ + this.javaClass =javaClass; + } + + public Class getJavaClass(){ + return javaClass; + } + + public static OGRFieldType valueOf(int value) { + switch (value) { + case 0 : return OFTInteger; + case 1 : return OFTIntegerList; + case 2 : return OFTReal; + case 3 : return OFTRealList; + case 4 : return OFTString; + case 5 : return OFTStringList; + case 6 : return OFTWideString; + case 7 : return OFTWideStringList; + case 8 : return OFTBinary; + case 9 : return OFTDate; + case 10 : return OFTTime; + case 11 : return OFTDateTime; + case 12 : return OFTInteger64; + case 13 : return OFTInteger64List; + } + throw new IllegalArgumentException("Unknown type " + value); + } + +} diff --git a/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/OGRwkbByteOrder.java b/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/OGRwkbByteOrder.java new file mode 100644 index 0000000000..48e2692642 --- /dev/null +++ b/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/OGRwkbByteOrder.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sis.storage.gdal; + +/** + * + * @author Hilmi Bouallegue (Geomatys) + */ +enum OGRwkbByteOrder { +// MSB/Sun/Motoroloa: Most Significant Byte First. + wkbXDR, +// LSB/Intel/Vax: Least Significant Byte First. + wkbNDR; + + public static OGRwkbByteOrder valueOf(int value) { + switch (value) { + case 0 : return wkbXDR; + case 1 : return wkbNDR; + } + throw new IllegalArgumentException("Unknown type " + value); + } +} diff --git a/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/OGRwkbGeometryType.java b/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/OGRwkbGeometryType.java new file mode 100644 index 0000000000..31d01a84f2 --- /dev/null +++ b/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/OGRwkbGeometryType.java @@ -0,0 +1,186 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sis.storage.gdal; + +import org.locationtech.jts.geom.*; + + +/** + * + * @author Hilmi Bouallegue (Geomatys) + * @author Johann Sorel (Geomatys) + */ +enum OGRwkbGeometryType { + wkbUnknown(Geometry.class), + wkbPoint(Point.class), + wkbLineString(LineString.class), + wkbPolygon(Polygon.class), + wkbMultiPoint(MultiPoint.class), + wkbMultiLineString(MultiLineString.class), + wkbMultiPolygon(MultiPolygon.class), + wkbGeometryCollection(GeometryCollection.class), + wkbCircularString(Geometry.class), + wkbCompoundCurve(Geometry.class), + wkbCurvePolygon(Geometry.class), + wkbMultiCurve(Geometry.class), + wkbMultiSurface(Geometry.class), + wkbCurve(Geometry.class), + wkbSurface(Geometry.class), + wkbPolyhedralSurface(Geometry.class), + wkbTIN(Geometry.class), + wkbTriangle(Geometry.class), + wkbNone(Geometry.class), + wkbLinearRing(Geometry.class), + wkbCircularStringZ(Geometry.class), + wkbCompoundCurveZ(Geometry.class), + wkbCurvePolygonZ(Geometry.class), + wkbMultiCurveZ(Geometry.class), + wkbMultiSurfaceZ(Geometry.class), + wkbCurveZ(Geometry.class), + wkbSurfaceZ(Geometry.class), + wkbPolyhedralSurfaceZ(Geometry.class), + wkbTINZ(Geometry.class), + wkbTriangleZ(Geometry.class), + wkbPointM(Geometry.class), + wkbLineStringM(Geometry.class), + wkbPolygonM(Geometry.class), + wkbMultiPointM(Geometry.class), + wkbMultiLineStringM(Geometry.class), + wkbMultiPolygonM(Geometry.class), + wkbGeometryCollectionM(Geometry.class), + wkbCircularStringM(Geometry.class), + wkbCompoundCurveM(Geometry.class), + wkbCurvePolygonM(Geometry.class), + wkbMultiCurveM(Geometry.class), + wkbMultiSurfaceM(Geometry.class), + wkbCurveM(Geometry.class), + wkbSurfaceM(Geometry.class), + wkbPolyhedralSurfaceM(Geometry.class), + wkbTINM(Geometry.class), + wkbTriangleM(Geometry.class), + wkbPointZM(Geometry.class), + wkbLineStringZM(Geometry.class), + wkbPolygonZM(Geometry.class), + wkbMultiPointZM(Geometry.class), + wkbMultiLineStringZM(Geometry.class), + wkbMultiPolygonZM(Geometry.class), + wkbGeometryCollectionZM(Geometry.class), + wkbCircularStringZM(Geometry.class), + wkbCompoundCurveZM(Geometry.class), + wkbCurvePolygonZM(Geometry.class), + wkbMultiCurveZM(Geometry.class), + wkbMultiSurfaceZM(Geometry.class), + wkbCurveZM(Geometry.class), + wkbSurfaceZM(Geometry.class), + wkbPolyhedralSurfaceZM(Geometry.class), + wkbTINZM(Geometry.class), + wkbTriangleZM(Geometry.class), + wkbPoint25D(Geometry.class), + wkbLineString25D(Geometry.class), + wkbPolygon25D(Geometry.class), + wkbMultiPoint25D(Geometry.class), + wkbMultiLineString25D(Geometry.class), + wkbMultiPolygon25D(Geometry.class), + wkbGeometryCollection25D(Geometry.class); + + private final Class javaClass; + + OGRwkbGeometryType(Class javaClass){ + this.javaClass =javaClass; + } + + public Class getJavaClass(){ + return javaClass; + } + + public static OGRwkbGeometryType valueOf(int value) { + switch (value) { + case 0 : return wkbUnknown; + case 1 : return wkbPoint; + case 2 : return wkbLineString; + case 3 : return wkbPolygon; + case 4 : return wkbMultiPoint; + case 5 : return wkbMultiLineString; + case 6 : return wkbMultiPolygon; + case 7 : return wkbGeometryCollection; + case 8 : return wkbCircularString; + case 9 : return wkbCompoundCurve; + case 10 : return wkbCurvePolygon; + case 11 : return wkbMultiCurve; + case 12 : return wkbMultiSurface; + case 13 : return wkbCurve; + case 14 : return wkbSurface; + case 15 : return wkbPolyhedralSurface; + case 16 : return wkbTIN; + case 17 : return wkbTriangle; + case 18 : return wkbNone; + case 19 : return wkbLinearRing; + case 20 : return wkbCircularStringZ; + case 21 : return wkbCompoundCurveZ; + case 22 : return wkbCurvePolygonZ; + case 23 : return wkbMultiCurveZ; + case 24 : return wkbMultiSurfaceZ; + case 25 : return wkbCurveZ; + case 26 : return wkbSurfaceZ; + case 27 : return wkbPolyhedralSurfaceZ; + case 28 : return wkbTINZ; + case 29 : return wkbTriangleZ; + case 30 : return wkbPointM; + case 31 : return wkbLineStringM; + case 32 : return wkbPolygonM; + case 33 : return wkbMultiPointM; + case 34 : return wkbMultiLineStringM; + case 35 : return wkbMultiPolygonM; + case 36 : return wkbGeometryCollectionM; + case 37 : return wkbCircularStringM; + case 38 : return wkbCompoundCurveM; + case 39 : return wkbCurvePolygonM; + case 40 : return wkbMultiCurveM; + case 41 : return wkbMultiSurfaceM; + case 42 : return wkbCurveM; + case 43 : return wkbSurfaceM; + case 44 : return wkbPolyhedralSurfaceM; + case 45 : return wkbTINM; + case 46 : return wkbTriangleM; + case 47 : return wkbPointZM; + case 48 : return wkbLineStringZM; + case 49 : return wkbPolygonZM; + case 50 : return wkbMultiPointZM; + case 51 : return wkbMultiLineStringZM; + case 52 : return wkbMultiPolygonZM; + case 53 : return wkbGeometryCollectionZM; + case 54 : return wkbCircularStringZM; + case 55 : return wkbCompoundCurveZM; + case 56 : return wkbCurvePolygonZM; + case 57 : return wkbMultiCurveZM; + case 58 : return wkbMultiSurfaceZM; + case 59 : return wkbCurveZM; + case 60 : return wkbSurfaceZM; + case 61 : return wkbPolyhedralSurfaceZM; + case 62 : return wkbTINZM; + case 63 : return wkbTriangleZM; + case 64 : return wkbPoint25D; + case 65 : return wkbLineString25D; + case 66 : return wkbPolygon25D; + case 67 : return wkbMultiPoint25D; + case 68 : return wkbMultiLineString25D; + case 69 : return wkbMultiPolygon25D; + case 70 : return wkbGeometryCollection25D; + } + throw new IllegalArgumentException("Unknown type " + value); + } +} diff --git a/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/Opener.java b/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/Opener.java index 4b737797ec..59b699c11a 100644 --- a/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/Opener.java +++ b/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/Opener.java @@ -69,7 +69,7 @@ final class Opener implements Runnable { * @throws DataStoreException if <var>GDAL</var> cannot open the data set. */ Opener(final GDALStoreProvider owner, final String url, final String... allowedDrivers) throws DataStoreException { - this(owner, url, new OpenFlag[] {OpenFlag.RASTER, OpenFlag.SHARED}, allowedDrivers, null, null); + this(owner, url, new OpenFlag[] {OpenFlag.RASTER, OpenFlag.VECTOR, OpenFlag.SHARED}, allowedDrivers, null, null); } /** diff --git a/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/SpatialRef.java b/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/SpatialRef.java index 912c6a1707..813108973c 100644 --- a/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/SpatialRef.java +++ b/optional/src/org.apache.sis.storage.gdal/main/org/apache/sis/storage/gdal/SpatialRef.java @@ -97,6 +97,19 @@ final class SpatialRef { return new SpatialRef(owner, gdal, handle); } + /** + * Creates a new instance. + * + * @param owner the dataset which is providing the <abbr>CRS</abbr> definition. + * @param gdal sets of handles for invoking <abbr>GDAL</abbr> functions. + * @param spatialRefHandle pointer to native SpatialRef. + * @return wrapper for the <abbr>CRS</abbr> definition provided by <abbr>GDAL</abbr>, or {@code null} if none. + * @throws DataStoreException if an error occurred while fetching information from <abbr>GDAL</abbr>. + */ + static SpatialRef createWithHandle(final GDALStore owner, final GDAL gdal, final MemorySegment spatialRefHandle) throws DataStoreException { + return new SpatialRef(owner, gdal, spatialRefHandle); + } + /** * Parses the <abbr>CRS</abbr> of the data set by parsing its <abbr>WKT</abbr> representation. * This method must be invoked from a method synchronized on {@link GDALStore}.