Skip to content

Commit

Permalink
Merge pull request #1401 from nicolas-f/fix_stextent
Browse files Browse the repository at this point in the history
Fix mixed srid error on empty geometry with ST_Extent about #1400
  • Loading branch information
ebocher authored Dec 3, 2024
2 parents 9fd7ef6 + 41b93b0 commit b318e17
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
- Add ST_OverpassDownloader function
- Fix bug when read GeometryCollection with the ST_GeomFromGeoJSON function
- Fix github actions
- Fix mixed srid error on empty geometry with ST_Extent #1400
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,16 @@ public int getInternalType(int[] inputTypes) throws SQLException {
@Override
public void add(Object o) throws SQLException {
if (o instanceof Geometry) {
Geometry geom = (Geometry) o;
int currentSRID = geom.isEmpty()?0:geom.getSRID();
if(srid==0){
srid=currentSRID;
Geometry geom = (Geometry) o;
if(!geom.isEmpty()) {
int currentSRID = geom.getSRID();
if (srid == 0) {
srid = currentSRID;
} else if (srid != currentSRID) {
throw new SQLException("Operation on mixed SRID geometries not supported");
}
aggregatedEnvelope.expandToInclude(geom.getEnvelopeInternal());
}
else if(srid!=currentSRID){
throw new SQLException("Operation on mixed SRID geometries not supported");
}
aggregatedEnvelope.expandToInclude(geom.getEnvelopeInternal());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,28 @@ public void test_NULL_ST_Extent() throws Exception {
st.execute("drop table ptClouds");
}

@Test
public void test_Empty_ST_Extent() throws Exception {
st.execute("drop table if exists ptClouds");
st.execute("create table ptClouds(id INTEGER PRIMARY KEY AUTO_INCREMENT, the_geom GEOMETRY(MultiPoint));"
+ "insert into ptClouds(the_geom) VALUES (ST_MPointFromText('MULTIPOINT(5 5, 1 2, 3 4, 99 3)',2154)),"
+ "(ST_MPointFromText('MULTIPOINT(-5 12, 11 22, 34 41, 65 124)',2154)),"
+ "(ST_MPointFromText('MULTIPOINT EMPTY',2154)),"
+ "(ST_MPointFromText('MULTIPOINT(1 12, 5 -21, 9 41, 32 124)',2154));");
ResultSet rs = st.executeQuery("select ST_Extent(the_geom) tableEnv from ptClouds;");
assertTrue(rs.next());
Object resultObj = rs.getObject("tableEnv");
assertTrue(resultObj instanceof Geometry);
Envelope result = ((Geometry) resultObj).getEnvelopeInternal();
Envelope expected = new Envelope(-5, 99, -21, 124);
assertEquals(expected.getMinX(), result.getMinX(), 1e-12);
assertEquals(expected.getMaxX(), result.getMaxX(), 1e-12);
assertEquals(expected.getMinY(), result.getMinY(), 1e-12);
assertEquals(expected.getMaxY(), result.getMaxY(), 1e-12);
assertFalse(rs.next());
st.execute("drop table ptClouds");
}

@Test
public void test_TableEnvelope() throws Exception {
st.execute("drop table if exists ptClouds");
Expand Down

0 comments on commit b318e17

Please sign in to comment.