Skip to content

Commit

Permalink
Merge pull request #1395 from ebocher/new_functions
Browse files Browse the repository at this point in the history
Add ST_CoverageUnion and upgrade github actions
  • Loading branch information
ebocher authored Sep 18, 2024
2 parents 666f5f4 + 70c39f8 commit 8e1efd3
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ jobs:
steps:
# Checkout the source code of the project
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

# Setup the jdk using version 11 of Adoptium Temurin
- name: Setup java 11 using Adoptium Temurin
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/CI release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ jobs:
steps:
# Checkout the source code of the project
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

# Setup the jdk using version 11 of Adoptium Temurin
- name: Setup java 11 using Adoptium Temurin
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/CI_snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ jobs:
steps:
# Checkout the source code of the project
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

# Setup the jdk using version 11 of Adoptium Temurin
- name: Setup java 11 using Adoptium Temurin
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:
- name: Unzip production artifacts
run: unzip h2gis-dist/target/h2gis-standalone-bin.zip
- name: Archive production artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: h2gis-standalone-bin
path: h2gis-standalone/
5 changes: 3 additions & 2 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
- Write empty geometry with the shapefile driver
- Do not ask for SRID when geometry is empty
- Add the name of the file in the FGB header
- Fix null way id on OSM file-
- Fix null way id on OSM file
- Use new sonatype auth
- Add ST_SnapToSelf function
- Upgrade to H2 2.3.230
- Upgrade to JTS 1.20
- Upgrade to H2 2.3.232
- Upgrade to H2 2.3.232
- Add ST_CoverageUnion function
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.h2gis.functions.spatial.buffer.*;
import org.h2gis.functions.spatial.clean.ST_MakeValid;
import org.h2gis.functions.spatial.convert.*;
import org.h2gis.functions.spatial.coverage.ST_CoverageUnion;
import org.h2gis.functions.spatial.create.*;
import org.h2gis.functions.spatial.crs.*;
import org.h2gis.functions.spatial.distance.*;
Expand Down Expand Up @@ -341,7 +342,8 @@ public static Function[] getBuiltInsFunctions() {
new ST_IsGeographicCRS(),
new ST_SnapToGrid(),
new ST_SnapToSelf(),
new ST_CoveredBy()
new ST_CoveredBy(),
new ST_CoverageUnion()
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* H2GIS is a library that brings spatial support to the H2 Database Engine
* <a href="http://www.h2database.com">http://www.h2database.com</a>. H2GIS is developed by CNRS
* <a href="http://www.cnrs.fr/">http://www.cnrs.fr/</a>.
* <p>
* This code is part of the H2GIS project. H2GIS is free software;
* you can redistribute it and/or modify it under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation;
* version 3.0 of the License.
* <p>
* H2GIS is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details <http://www.gnu.org/licenses/>.
* <p>
* <p>
* For more information, please consult: <a href="http://www.h2gis.org/">http://www.h2gis.org/</a>
* or contact directly: info_at_h2gis.org
*/
package org.h2gis.functions.spatial.coverage;


import org.h2gis.api.DeterministicScalarFunction;
import org.locationtech.jts.coverage.CoverageUnion;
import org.locationtech.jts.geom.Geometry;

/**
* @author Erwan Bocher, CNRS
*/
public class ST_CoverageUnion extends DeterministicScalarFunction {


public ST_CoverageUnion() {
addProperty(PROP_REMARKS, "A function which unions a set of polygons forming a polygonal coverage. \n" +
"The result is a polygonal geometry covering the same area as the coverage.\n" +
"It uses the CoverageUnion algorithm");
}


@Override
public String getJavaStaticMethod() {
return "execute";
}

/**
* Run the coverage union
* @param geoms the input array of geometries
* @return the union of the input array of geometries
*/
public static Geometry execute(Geometry[] geoms){
if(geoms==null){
return null;
}
return CoverageUnion.union(geoms);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ public void testRelate() throws SQLException, ParseException {
assertTrue(RelateNG.relate(gc0, gc1, RelatePredicate.intersects()));
}

@Disabled
@Test
public void testBufferPrecision() throws SQLException, ParseException {
WKTReader wktReader = new WKTReader();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* H2GIS is a library that brings spatial support to the H2 Database Engine
* <a href="http://www.h2database.com">http://www.h2database.com</a>. H2GIS is developed by CNRS
* <a href="http://www.cnrs.fr/">http://www.cnrs.fr/</a>.
* <p>
* This code is part of the H2GIS project. H2GIS is free software;
* you can redistribute it and/or modify it under the terms of the GNU
* Lesser General Public License as published by the Free Software Foundation;
* version 3.0 of the License.
* <p>
* H2GIS is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details <http://www.gnu.org/licenses/>.
* <p>
* <p>
* For more information, please consult: <a href="http://www.h2gis.org/">http://www.h2gis.org/</a>
* or contact directly: info_at_h2gis.org
*/
package org.h2gis.functions.spatial.coverage;

import org.h2gis.functions.factory.H2GISDBFactory;
import org.junit.jupiter.api.*;
import org.locationtech.jts.geom.GeometryFactory;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

import static org.h2gis.unitTest.GeometryAsserts.assertGeometryBarelyEquals;

public class CoverageFunctionTest {
private static Connection connection;
private Statement st;
private static final GeometryFactory FACTORY = new GeometryFactory();

@BeforeAll
public static void tearUp() throws Exception {
// Keep a connection alive to not close the DataBase on each unit test
connection = H2GISDBFactory.createSpatialDataBase(CoverageFunctionTest.class.getSimpleName());
}

@AfterAll
public static void tearDown() throws Exception {
connection.close();
}

@BeforeEach
public void setUpStatement() throws Exception {
st = connection.createStatement();
}

@AfterEach
public void tearDownStatement() throws Exception {
st.close();
}

@Test
public void test_ST_CoverageUnion1() throws Exception {
ResultSet res = st.executeQuery("WITH coverage(id, geom) AS (VALUES\n" +
" (1, 'POLYGON ((10 10, 10 150, 80 190, 110 150, 90 110, 40 110, 50 60, 10 10))'::geometry),\n" +
" (2, 'POLYGON ((120 10, 10 10, 50 60, 100 70, 120 10))'::geometry),\n" +
" (3, 'POLYGON ((140 80, 120 10, 100 70, 40 110, 90 110, 110 150, 140 80))'::geometry),\n" +
" (4, 'POLYGON ((140 190, 120 170, 140 130, 160 150, 140 190))'::geometry),\n" +
" (5, 'POLYGON ((180 160, 170 140, 140 130, 160 150, 140 190, 180 160))'::geometry)\n" +
")\n" +
"SELECT ST_CoverageUnion(ARRAY_AGG(geom))\n" +
" FROM coverage;\n");
res.next();
assertGeometryBarelyEquals("MULTIPOLYGON (((10 150, 80 190, 110 150, 140 80, 120 10, 10 10, 10 150), (50 60, 100 70, 40 110, 50 60)), ((120 170, 140 190, 180 160, 170 140, 140 130, 120 170)))",res.getObject(1));
res.close();
}
}

0 comments on commit 8e1efd3

Please sign in to comment.