This is an automated email from the ASF dual-hosted git repository.

asf-gitbox-commits pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git


The following commit(s) were added to refs/heads/geoapi-4.0 by this push:
     new 021bb9624f feat(Shapefile): add incremental id shapefile test
021bb9624f is described below

commit 021bb9624f7208ae83a08bf96ebe5a191f804f5c
Author: jsorel <[email protected]>
AuthorDate: Wed May 6 12:33:19 2026 +0200

    feat(Shapefile): add incremental id shapefile test
---
 .../sis/storage/shapefile/ShapefileStore.java      |  10 +++++---
 .../sis/storage/shapefile/ShapefileStoreTest.java  |  28 +++++++++++++++++++++
 .../test/org/apache/sis/storage/shapefile/noid.cpg |   1 +
 .../test/org/apache/sis/storage/shapefile/noid.dbf | Bin 0 -> 147 bytes
 .../test/org/apache/sis/storage/shapefile/noid.prj |   1 +
 .../test/org/apache/sis/storage/shapefile/noid.shp | Bin 0 -> 128 bytes
 .../test/org/apache/sis/storage/shapefile/noid.shx | Bin 0 -> 108 bytes
 7 files changed, 36 insertions(+), 4 deletions(-)

diff --git 
a/incubator/src/org.apache.sis.storage.shapefile/main/org/apache/sis/storage/shapefile/ShapefileStore.java
 
b/incubator/src/org.apache.sis.storage.shapefile/main/org/apache/sis/storage/shapefile/ShapefileStore.java
index 67609473c8..62d013bba7 100644
--- 
a/incubator/src/org.apache.sis.storage.shapefile/main/org/apache/sis/storage/shapefile/ShapefileStore.java
+++ 
b/incubator/src/org.apache.sis.storage.shapefile/main/org/apache/sis/storage/shapefile/ShapefileStore.java
@@ -131,6 +131,7 @@ import org.opengis.filter.LogicalOperatorName;
 import org.opengis.filter.SpatialOperatorName;
 import org.opengis.filter.ValueReference;
 import org.apache.sis.geometry.wrapper.*;
+import org.opengis.feature.PropertyNotFoundException;
 
 
 /**
@@ -337,10 +338,11 @@ public final class ShapefileStore extends DataStore 
implements WritableFeatureSe
          * @throws DataStoreException
          */
         private boolean mustGenerateId() throws DataStoreException {
-            getType();
-            if (idField != null) return false;
-            if (readProperties == null) return true;
-            return readProperties.contains(AttributeConvention.IDENTIFIER);
+            try {
+                return getType().getProperty(AttributeConvention.IDENTIFIER) 
instanceof AttributeType;
+            } catch (PropertyNotFoundException ex) {
+                return false;
+            }
         }
 
         /**
diff --git 
a/incubator/src/org.apache.sis.storage.shapefile/test/org/apache/sis/storage/shapefile/ShapefileStoreTest.java
 
b/incubator/src/org.apache.sis.storage.shapefile/test/org/apache/sis/storage/shapefile/ShapefileStoreTest.java
index 1efde9200a..d6cdaefcf6 100644
--- 
a/incubator/src/org.apache.sis.storage.shapefile/test/org/apache/sis/storage/shapefile/ShapefileStoreTest.java
+++ 
b/incubator/src/org.apache.sis.storage.shapefile/test/org/apache/sis/storage/shapefile/ShapefileStoreTest.java
@@ -49,6 +49,7 @@ import org.junit.jupiter.api.io.TempDir;
 import org.opengis.feature.AttributeType;
 import org.opengis.feature.Feature;
 import org.opengis.feature.FeatureType;
+import org.opengis.feature.PropertyType;
 import org.opengis.filter.BinaryComparisonOperator;
 import org.opengis.filter.FilterFactory;
 
@@ -324,6 +325,33 @@ public class ShapefileStoreTest {
         }
     }
 
+    /**
+     * Test incremental id creation.
+     */
+    @Test
+    public void testGeneratedId() throws DataStoreException, IOException, 
URISyntaxException {
+        final URL url = 
ShapefileStoreTest.class.getResource("/org/apache/sis/storage/shapefile/noid.shp");
+        try (final ShapefileStore store = new 
ShapefileStore(Paths.get(url.toURI()))) {
+
+            final FeatureType type = store.getType();
+            System.out.println(type);
+            final PropertyType generatedID = 
type.getProperty(AttributeConvention.IDENTIFIER);
+            assertTrue(generatedID instanceof AttributeType);
+            assertEquals(5, type.getProperties(true).size());
+
+            try (Stream<Feature> stream = store.features(false)) {
+                Iterator<Feature> iterator = stream.iterator();
+                assertTrue(iterator.hasNext());
+                Feature feature1 = iterator.next();
+                assertEquals(0, 
feature1.getPropertyValue(AttributeConvention.IDENTIFIER));
+                assertEquals("some text", feature1.getPropertyValue("text"));
+
+                assertFalse(iterator.hasNext());
+            }
+        }
+
+    }
+
     private static FeatureType createType() {
         final FeatureTypeBuilder ftb = new FeatureTypeBuilder();
         ftb.setName("test");
diff --git 
a/incubator/src/org.apache.sis.storage.shapefile/test/org/apache/sis/storage/shapefile/noid.cpg
 
b/incubator/src/org.apache.sis.storage.shapefile/test/org/apache/sis/storage/shapefile/noid.cpg
new file mode 100644
index 0000000000..3ad133c048
--- /dev/null
+++ 
b/incubator/src/org.apache.sis.storage.shapefile/test/org/apache/sis/storage/shapefile/noid.cpg
@@ -0,0 +1 @@
+UTF-8
\ No newline at end of file
diff --git 
a/incubator/src/org.apache.sis.storage.shapefile/test/org/apache/sis/storage/shapefile/noid.dbf
 
b/incubator/src/org.apache.sis.storage.shapefile/test/org/apache/sis/storage/shapefile/noid.dbf
new file mode 100644
index 0000000000..3aeb04cab3
Binary files /dev/null and 
b/incubator/src/org.apache.sis.storage.shapefile/test/org/apache/sis/storage/shapefile/noid.dbf
 differ
diff --git 
a/incubator/src/org.apache.sis.storage.shapefile/test/org/apache/sis/storage/shapefile/noid.prj
 
b/incubator/src/org.apache.sis.storage.shapefile/test/org/apache/sis/storage/shapefile/noid.prj
new file mode 100644
index 0000000000..f45cbadf00
--- /dev/null
+++ 
b/incubator/src/org.apache.sis.storage.shapefile/test/org/apache/sis/storage/shapefile/noid.prj
@@ -0,0 +1 @@
+GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]
\ No newline at end of file
diff --git 
a/incubator/src/org.apache.sis.storage.shapefile/test/org/apache/sis/storage/shapefile/noid.shp
 
b/incubator/src/org.apache.sis.storage.shapefile/test/org/apache/sis/storage/shapefile/noid.shp
new file mode 100644
index 0000000000..276880b539
Binary files /dev/null and 
b/incubator/src/org.apache.sis.storage.shapefile/test/org/apache/sis/storage/shapefile/noid.shp
 differ
diff --git 
a/incubator/src/org.apache.sis.storage.shapefile/test/org/apache/sis/storage/shapefile/noid.shx
 
b/incubator/src/org.apache.sis.storage.shapefile/test/org/apache/sis/storage/shapefile/noid.shx
new file mode 100644
index 0000000000..5f77d8f2eb
Binary files /dev/null and 
b/incubator/src/org.apache.sis.storage.shapefile/test/org/apache/sis/storage/shapefile/noid.shx
 differ

Reply via email to