-
Notifications
You must be signed in to change notification settings - Fork 440
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
Geometry.reverse inconsistency #305
Comments
It's inefficient to use But the SRID should be copied. Not sure about the userData, since that may or may not be desired depending on use case. Probably there should be a protected copySRID method which can be called by Geometry methods which should preserve it. |
Further thinking: all the reverse methods should NOT use copy, they should use the factory create methods. This makes them consistent. The SRID should be set by the factory, so that's taken care of. Copying user data is in general not done for constructed geometries, since the library can't know if that was the client intention or not. So this is left up to client code. It might be nice to have a convenience method defined for this (which would definitely help if and when there is more than one field to copy). |
This is only true if |
Other issues found while working on a fix:
|
* Add protected reverseInternal function to Geometry, implement in Point, LineString, LinearRing, Polygon and GeometryCollection * Remove abstract from Geometry.reverse function, implementation calls reverseInternal and copies Envelope and SRID values * To avoid breaking change make Geometry.reverse overrides return super.reverse() * Add unit test Note: The reversal of items in MultiLineString has been removed. relates to locationtech#305 Signed-off-by: Felix Obermaier <felix.obermaier@netcologne.de>
Good point. I guess the SRID will then need to be copied manually. |
Good catch. My thinking on the semantics for this method is that ONLY the order of the Coordinate sequences is reversed, NOT the order of the component geometries in their parents. So the code for |
@FObermaier are you working on a PR for this? |
* Add protected reverseInternal function to Geometry, implement in Point, LineString, LinearRing, Polygon and GeometryCollection * Remove abstract from Geometry.reverse function, implementation calls reverseInternal and copies Envelope and SRID values * To avoid breaking change make Geometry.reverse overrides return super.reverse() * Add unit test Note: The reversal of items in MultiLineString has been removed. relates to locationtech#305 Signed-off-by: Felix Obermaier <felix.obermaier@netcologne.de>
* Fix ExtractLineByLocation to not use deprecated Geometry.reverse() overrides * Remove dead code relates to locationtech#305 Signed-off-by: Felix Obermaier <felix.obermaier@netcologne.de>
* LengthIndexedLineTest.testExtractLineReverseMulti relates to locationtech#305 Signed-off-by: Felix Obermaier <felix.obermaier@netcologne.de>
* Make Geometry.reverse() consistent * Add protected reverseInternal function to Geometry, implement in Point, LineString, LinearRing, Polygon and GeometryCollection * Remove abstract from Geometry.reverse function, implementation calls reverseInternal and copies Envelope and SRID values * To avoid breaking change make Geometry.reverse overrides return super.reverse() * Add unit test * Add @deprecated to Geometry.reverse() overrides * Fix ExtractLineByLocation to not use deprecated Geometry.reverse() overrides * Remove dead code * Fix unit test LengthIndexedLineTest.testExtractLineReverseMulti Note: The reversal of items in MultiLineString has been removed. relates to #305 Signed-off-by: Felix Obermaier <felix.obermaier@netcologne.de>
Closed by #513 |
The implementations of
Geometry.reverse
can be categorized by ones usingGeometry.copy
and others that don't:Reverse using
copy
jts/modules/core/src/main/java/org/locationtech/jts/geom/Point.java
Lines 193 to 196 in 8d433ca
jts/modules/core/src/main/java/org/locationtech/jts/geom/Polygon.java
Lines 432 to 440 in 8d433ca
Reverse not using
copy
jts/modules/core/src/main/java/org/locationtech/jts/geom/LineString.java
Lines 183 to 189 in 8d433ca
jts/modules/core/src/main/java/org/locationtech/jts/geom/LinearRing.java
Lines 135 to 141 in 8d433ca
jts/modules/core/src/main/java/org/locationtech/jts/geom/MultiPolygon.java
Lines 123 to 131 in 8d433ca
jts/modules/core/src/main/java/org/locationtech/jts/geom/MultiPolygon.java
Lines 123 to 131 in 8d433ca
jts/modules/core/src/main/java/org/locationtech/jts/geom/GeometryCollection.java
Lines 281 to 289 in 8d433ca
This has the effect that
Geometry.SRID
andGeometry.UserData
are copied forPolygon
andPoint
but not for the others.This is inconsistent. I have no preference which way is better.
The text was updated successfully, but these errors were encountered: