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

Extent aggregate problem #25

Open
GeoUser983 opened this issue Jan 8, 2016 · 2 comments
Open

Extent aggregate problem #25

GeoUser983 opened this issue Jan 8, 2016 · 2 comments

Comments

@GeoUser983
Copy link

I'm using the 0.8 version and there is a problem with ST_EXTENT:

@OverRide
protected void add(Geometry geometry) {
if (result == null) {
result = geometry;
} else {
if (geometry != null) {
result = result.union(geometry.getEnvelope());
}
}
}

If result is null you set it to geometry. The next geometry gets its envelope added with union. Now, this will work if the geometries are polygon. But when the geometry is for example LineString, the first union will create a geometry collection (linestring from the first iteration and the polygon from GetEnvelope...) which can not be unified (JTS union actually has a check: checkNotGeometryCollection(this);)

The solution is to set the result to geometry.getEnvelope in the first iteration.

@jdeolive
Copy link
Owner

jdeolive commented Jan 8, 2016

Thanks for reporting the issue. It makes sense but when I tried to reproduce I could not. Any chance you can provide a sample of geometries that lead to the issue?

@GeoUser983
Copy link
Author

Here is how i can replicate the problem. Firstly i create a database using the geotools (so all the aliases get setup) then i connected the DBeaver to this database and executed the following lines: (also note that the same thing happens on purely geotools created tables)

CREATE TABLE PUBLIC.TEST_EXTENT (
ID INTEGER NOT NULL,
GEOM BLOB
);

insert into PUBLIC.TEST_EXTENT(ID, GEOM) VALUES(1, ST_GeomFromText('LINESTRING (401144.32 4886020.44, 401169.16 4886039.33)', 2170));
insert into PUBLIC.TEST_EXTENT(ID, GEOM) VALUES(2, ST_GeomFromText('LINESTRING (401169.16 4886039.33, 401169.48 4886039.56)', 2170));
insert into PUBLIC.TEST_EXTENT(ID, GEOM) VALUES(3, ST_GeomFromText('LINESTRING (401157.54 4886055.71, 401169.48 4886039.56)', 2170));

-- all fine
SELECT ST_ENVELOPE(geom) FROM TEST_EXTENT

-- exception: General error: java.lang.IllegalArgumentException: This method does not support GeometryCollection arguments; SQL statement:
SELECT ST_Extent(geom) FROM TEST_EXTENT

And with the proposed fix, the last SQL works as intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants