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

Geometry.reverse inconsistency #305

Closed
FObermaier opened this issue Aug 28, 2018 · 8 comments
Closed

Geometry.reverse inconsistency #305

FObermaier opened this issue Aug 28, 2018 · 8 comments

Comments

@FObermaier
Copy link
Contributor

The implementations of Geometry.reverse can be categorized by ones using Geometry.copy and others that don't:

This has the effect that Geometry.SRID and Geometry.UserData are copied for Polygon and Point but not for the others.

This is inconsistent. I have no preference which way is better.

@FObermaier FObermaier changed the title Geometry.Reverse inconsistency Geometry.reverse inconsistency Aug 28, 2018
@dr-jts
Copy link
Contributor

dr-jts commented Dec 11, 2018

It's inefficient to use copy in most cases, because that copies the internal coordinate sequences which are going to be replaced anyway.

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.

@dr-jts
Copy link
Contributor

dr-jts commented Dec 13, 2018

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).

@FObermaier
Copy link
Contributor Author

The SRID should be set by the factory, so that's taken care of.

This is only true if Geometry.srid == Geometry.getFactory().getSRID(). Once Geometry.setSRID(sridValue) has been called on a geometry this is not guaranteed to be true.

@FObermaier
Copy link
Contributor Author

FObermaier commented Jan 23, 2020

Other issues found while working on a fix:

  • MultiPoint does not override GeometryCollection.reverse() so a reversed MULTIPOINT becomes a GEOMETRYCOLLECTION
  • MultiLineString.reverse() reverses the order of the LineStrings, GeometryCollection and MultiPolygon don't

FObermaier added a commit to FObermaier/jts that referenced this issue Jan 23, 2020
* 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>
@dr-jts
Copy link
Contributor

dr-jts commented Jan 23, 2020

The SRID should be set by the factory, so that's taken care of.

This is only true if Geometry.srid == Geometry.getFactory().getSRID(). Once Geometry.setSRID(sridValue) has been called on a geometry this is not guaranteed to be true.

Good point. I guess the SRID will then need to be copied manually.

@dr-jts
Copy link
Contributor

dr-jts commented Jan 23, 2020

Other issues found while working on a fix:

  • MultiPoint does not override GeometryCollection.reverse() so a reversed MULTIPOINT becomes a GEOMETRYCOLLECTION
  • MultiLineString.reverse() reverses the order of the LineStrings, GeometryCollection and MultiPolygon don't

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 MultiLineString should be changed.

@dr-jts
Copy link
Contributor

dr-jts commented Jan 23, 2020

@FObermaier are you working on a PR for this?

FObermaier added a commit to FObermaier/jts that referenced this issue Jan 24, 2020
* 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>
FObermaier added a commit to FObermaier/jts that referenced this issue Jan 24, 2020
* 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>
FObermaier added a commit to FObermaier/jts that referenced this issue Jan 24, 2020
* LengthIndexedLineTest.testExtractLineReverseMulti

relates to locationtech#305

Signed-off-by: Felix Obermaier <felix.obermaier@netcologne.de>
dr-jts pushed a commit that referenced this issue Jan 27, 2020
* 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>
@dr-jts
Copy link
Contributor

dr-jts commented Jan 27, 2020

Closed by #513

@dr-jts dr-jts closed this as completed Jan 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants