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

desruisseaux pushed a commit to branch wip/h2gis
in repository https://gitbox.apache.org/repos/asf/sis.git

commit f6d758684111aa3ca33c1c609cb1feba6865ea5b
Author: Martin Desruisseaux <martin.desruisse...@geomatys.com>
AuthorDate: Mon Dec 27 19:18:10 2021 +0100

    Initial attempt to support H2GIS (work in progress).
    Current version fails with the following exception:
    
        Exception calling user-defined function: "load(conn1: 
url=jdbc:default:connection user=): org/h2/value/ValueInt"; SQL statement:
        CALL H2GIS_SPATIAL() [90105-204]
        (…snip…)
        Caused by: java.lang.ClassNotFoundException: org.h2.value.ValueInt
    
    It may be a mismatch on the H2 version used.
    We should retest later with next H2GIS version.
---
 ide-project/NetBeans/nbproject/project.properties  |  6 ++
 pom.xml                                            |  6 ++
 storage/sis-sqlstore/pom.xml                       |  5 ++
 .../org/apache/sis/internal/sql/h2gis/H2Test.java  | 89 ++++++++++++++++++++++
 .../sis/internal/sql/h2gis/SpatialFeatures.sql     | 22 ++++++
 5 files changed, 128 insertions(+)

diff --git a/ide-project/NetBeans/nbproject/project.properties 
b/ide-project/NetBeans/nbproject/project.properties
index 70520b4..1e22900 100644
--- a/ide-project/NetBeans/nbproject/project.properties
+++ b/ide-project/NetBeans/nbproject/project.properties
@@ -125,6 +125,8 @@ hamcrest.version     = 1.3
 derby.version        = 10.14.2.0
 hsqldb.version       = 2.6.1
 h2.version           = 2.0.204
+h2gis.version        = 1.5.0
+cts.version          = 1.5.2
 postgresql.version   = 42.3.1
 
 #
@@ -152,6 +154,10 @@ javac.test.classpath=\
     
${maven.repository}/org/postgresql/postgresql/${postgresql.version}/postgresql-${postgresql.version}.jar:\
     
${maven.repository}/org/hsqldb/hsqldb/${hsqldb.version}/hsqldb-${hsqldb.version}.jar:\
     ${maven.repository}/com/h2database/h2/${h2.version}/h2-${h2.version}.jar:\
+    
${maven.repository}/org/orbisgis/h2gis/${h2gis.version}/h2gis-${h2gis.version}.jar:\
+    
${maven.repository}/org/orbisgis/h2gis-api/${h2gis.version}/h2gis-api-${h2gis.version}.jar:\
+    
${maven.repository}/org/orbisgis/h2gis-utilities/${h2gis.version}/h2gis-utilities-${h2gis.version}.jar:\
+    
${maven.repository}/org/orbisgis/cts/${cts.version}/cts-${cts.version}.jar:\
     
${maven.repository}/gov/nist/math/jama/${jama.version}/jama-${jama.version}.jar:\
     
${maven.repository}/net/sf/geographiclib/GeographicLib-Java/${geographlib.version}/GeographicLib-Java-${geographlib.version}.jar:\
     
${maven.repository}/junit/junit/${junit.version}/junit-${junit.version}.jar:\
diff --git a/pom.xml b/pom.xml
index 941c704..4b861a8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -502,6 +502,12 @@
         <scope>test</scope>
       </dependency>
       <dependency>
+        <groupId>org.orbisgis</groupId>     <!-- LGPL but used only for tests. 
No code depends on it. -->
+        <artifactId>h2gis</artifactId>
+        <version>1.5.0</version>
+        <scope>test</scope>
+      </dependency>
+      <dependency>
         <groupId>org.postgresql</groupId>
         <artifactId>postgresql</artifactId>
         <version>42.3.1</version>
diff --git a/storage/sis-sqlstore/pom.xml b/storage/sis-sqlstore/pom.xml
index 3053c18..b614ab9 100644
--- a/storage/sis-sqlstore/pom.xml
+++ b/storage/sis-sqlstore/pom.xml
@@ -140,6 +140,11 @@
       <scope>test</scope>
     </dependency>
     <dependency>
+      <groupId>org.orbisgis</groupId>
+      <artifactId>h2gis</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
       <groupId>org.postgresql</groupId>
       <artifactId>postgresql</artifactId>
       <scope>test</scope>
diff --git 
a/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/h2gis/H2Test.java
 
b/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/h2gis/H2Test.java
new file mode 100644
index 0000000..f40c1a6
--- /dev/null
+++ 
b/storage/sis-sqlstore/src/test/java/org/apache/sis/internal/sql/h2gis/H2Test.java
@@ -0,0 +1,89 @@
+/*
+ * 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.internal.sql.h2gis;
+
+import java.util.stream.Stream;
+import org.apache.sis.setup.OptionKey;
+import org.apache.sis.setup.GeometryLibrary;
+import org.apache.sis.storage.FeatureSet;
+import org.apache.sis.storage.StorageConnector;
+import org.apache.sis.storage.sql.ResourceDefinition;
+import org.apache.sis.storage.sql.SQLStore;
+import org.apache.sis.storage.sql.SQLStoreProvider;
+import org.apache.sis.test.sql.TestDatabase;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+// Optional dependencies
+import org.locationtech.jts.geom.Geometry;
+
+// Branch-dependent imports
+import org.opengis.feature.Feature;
+
+
+/**
+ * Tests using H2 GIS.
+ *
+ * @author  Alexis Manin (Geomatys)
+ * @author  Martin Desruisseaux (Geomatys)
+ * @version 1.2
+ * @since   1.2
+ * @module
+ */
+public final strictfp class H2Test extends TestCase {
+    /**
+     * Number of feature instances found.
+     * This is used for making sure that the feature stream was not empty.
+     *
+     * @see #validate(Feature)
+     */
+    private int featureCount;
+
+    /**
+     * Tests reading features.
+     *
+     * @throws Exception if an error occurred while testing the database.
+     */
+    @Test
+    public void testSpatialFeatures() throws Exception {
+        try (TestDatabase database = 
TestDatabase.createOnH2("SpatialFeatures")) {
+            database.executeSQL(H2Test.class, "file:SpatialFeatures.sql");
+            final StorageConnector connector = new 
StorageConnector(database.source);
+            connector.setOption(OptionKey.GEOMETRY_LIBRARY, 
GeometryLibrary.JTS);
+            final ResourceDefinition table = ResourceDefinition.table(null, 
null, "SpatialData");
+            try (SQLStore store = new SQLStore(new SQLStoreProvider(), 
connector, table)) {
+                final FeatureSet resource = store.findResource("SpatialData");
+                try (Stream<Feature> features = resource.features(false)) {
+                    features.forEach(this::validate);
+                    assertEquals("featureCount", 3, featureCount);
+                }
+            }
+        }
+    }
+
+    /**
+     * Invoked for each feature instances for performing some checks on the 
feature.
+     * This method performs only a superficial verification of geometries.
+     */
+    private void validate(final Feature feature) {
+        featureCount++;
+        final Geometry geometry = (Geometry) 
feature.getPropertyValue("geometry");
+        // TODO: verify geometries.
+    }
+}
diff --git 
a/storage/sis-sqlstore/src/test/resources/org/apache/sis/internal/sql/h2gis/SpatialFeatures.sql
 
b/storage/sis-sqlstore/src/test/resources/org/apache/sis/internal/sql/h2gis/SpatialFeatures.sql
new file mode 100644
index 0000000..a640741
--- /dev/null
+++ 
b/storage/sis-sqlstore/src/test/resources/org/apache/sis/internal/sql/h2gis/SpatialFeatures.sql
@@ -0,0 +1,22 @@
+-- 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.
+
+
+-- Create a temporary database on H2GIS for testing geometries.
+
+CREATE ALIAS IF NOT EXISTS H2GIS_SPATIAL FOR 
"org.h2gis.functions.factory.H2GISFunctions.load";
+CALL H2GIS_SPATIAL();
+
+CREATE TABLE "SpatialData" (
+    "geometry"   LINESTRING,
+    "identifier" INT,
+
+    CHECK ST_SRID("geometry") = 4326,
+    CONSTRAINT "PK_SpatialData" PRIMARY KEY ("identifier")
+);
+
+INSERT INTO "SpatialData" VALUES
+  (ST_GeomFromText('LINESTRING(32  2, 18  6, -3 13)', 4326), 3),
+  (ST_GeomFromText('LINESTRING(67 12, 42 17, 45 25)', 4326), 1),
+  (ST_GeomFromText('LINESTRING(94 84, 74 72, 82 69)', 4326), 8)

Reply via email to