Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mixed srid error on empty geometry with ST_Extent about #1400 #1401

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading