-
Notifications
You must be signed in to change notification settings - Fork 443
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
Allow GeoJSONWriter to force polygons to be CCW #694
Allow GeoJSONWriter to force polygons to be CCW #694
Conversation
…s fails Signed-off-by: Rui Brito <ruibritopt@gmail.com>
Signed-off-by: Rui Brito <ruibritopt@gmail.com>
Signed-off-by: Rui Brito <ruibritopt@gmail.com>
Signed-off-by: Rui Brito <ruibritopt@gmail.com>
I would prefer to not bake this into the GeoJSONWriter. Instead could create a ForceRHR function to process each geometry beforehand? |
@dr-jts That is a valid point. If I understand your comment correctly, we would end up with a function like |
Actually it will be more efficient if the orientation is modified on a per-ring basis in the writer. In this case, it would be best to not change the current behaviour. So an option can be added to the |
…e logic Signed-off-by: Rui Brito <ruibritopt@gmail.com>
…ransformation functions Signed-off-by: Rui Brito <ruibritopt@gmail.com>
…rays so I switched to use list Signed-off-by: Rui Brito <ruibritopt@gmail.com>
@dr-jts I extended the GeoJsonWriter class to have an attribute Please let me know what you think. I'm willing to make any changes necessary. Also, if the idea of implementing the same logic on the reader side is appealing, let me know and I will make another PR. Thank you |
|
||
final LinearRing rightHandRuleRing; | ||
if (isExteriorRing) { | ||
rightHandRuleRing = isRingClockWise? ring.reverse() : ring; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to copy the ring if it is unchanged, to avoid aliasing errors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the change I made resolves this concern.
if (isExteriorRing) { | ||
rightHandRuleRing = isRingClockWise? ring.reverse() : ring; | ||
} else { | ||
rightHandRuleRing = isRingClockWise? ring : ring.reverse(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copy here too
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class TransformationUtils { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about calling this OrientationTransformer
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed this recommendation 👍
* @param geometry to be transformed | ||
* @return Geometry under the Right Hand Rule specifications | ||
*/ | ||
public static Geometry enforceRightHandRuleOrientation(final Geometry geometry) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just call this transformRightHandRule
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed this recommendation 👍
Yes, that looks good.
It's good to have the RHR conversion factored out. But I don't think it's necessary to bake it into |
Maybe consider avoiding the term RHR, since it is used by other software such as PostGIS to mean the opposite of what it means here. |
This is a good point. To be fair, the GeoJSON spec uses the term "right-hand rule", and defines that to mean "shell is CCW". That seems to be the most commonly accepted definition of RHR. The PostGIS usage is opposite, and is deprecated (discussion here). (SQL Server seems to have the same problem). But it's good to avoid stepping into that minefield. Also, two important design criteria for an API are consistency and parsimony of terminology. The term "CCW" is already used for this concept in JTS, and it is unambiguous. So this PR should change to using that acronym. So use The GeoJSONWriter Javadoc can point out that in the GeoJSON context "right-hand rule" = CCW. |
…to CCW Signed-off-by: Rui Brito <ruibritopt@gmail.com>
Signed-off-by: Rui Brito <ruibritopt@gmail.com>
@@ -88,6 +89,16 @@ public void setEncodeCRS(boolean isEncodeCRS) { | |||
this.isEncodeCRS = isEncodeCRS; | |||
} | |||
|
|||
/** | |||
* Sets whether the GeoJSON should be output following counter-clocked orientation aka Right Hand Rule defined in RFC7946 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be "counter-clockwise".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Silly mistake, thank you for spotting it.
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class OrientationTransformer { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add class Javadoc. Can be something simple like
Utilities to modify the ring orientation of polygonal geometries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took your recommendation verbatim
Looking good. Just a couple of small things to fix, and it will be good to merge. |
Signed-off-by: Rui Brito <ruibritopt@gmail.com>
* | ||
* @param enforceCCW true if the GeoJSON should be output following the RFC7946 counter-clockwise orientation aka Right Hand Rule | ||
*/ | ||
public void setEnforceCCW(boolean enforceCCW) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One final request. In the interest of brevity, can this be changed to setForceCCW
and isForceCCW
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done and done. Don't hold back on the requests, they have all been on the money and I'm a big fan of things done right 😄👍👍
Signed-off-by: Rui Brito <ruibritopt@gmail.com>
…-hand-rule' into feat/RFC-7946-geojson-spec-right-hand-rule
A best-effort PR to enforce the right hand rule for polygon ring orientation in the latest GeoJson specification and discussed in issue #681
Signed-off-by: Rui Brito ruibritopt@gmail.com