-
Notifications
You must be signed in to change notification settings - Fork 759
[GH-2885] Add ST_GeomFromBox2D and ST_AsText(box2d) #2899
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -868,6 +868,33 @@ public static String asWKT(Geometry geometry) { | |
| return GeomUtils.getWKT(geometry); | ||
| } | ||
|
|
||
| /** | ||
| * PostGIS-format text for a Box2D: {@code BOX(x1 y1, x2 y2)}. NULL on null input. | ||
| * | ||
| * <p>Values are emitted exactly as stored on the Box2D — this method does not normalize the | ||
| * corners. Sedona's Box2D allows {@code xmin > xmax} (or {@code ymin > ymax}); that ordering is | ||
| * reserved for a future antimeridian-wraparound semantics on geography bboxes (cf. sedona-db's | ||
| * {@code WraparoundInterval}). The text faithfully reflects what {@code ST_XMin} / {@code | ||
| * ST_XMax} / etc. would return. | ||
| * | ||
| * <p>Not WKT (WKT has no {@code BOX} type), so this lives outside the {@code asWKT} family to | ||
| * keep that API a true geometry serializer. | ||
| */ | ||
| public static String box2dAsText(Box2D box) { | ||
| if (box == null) { | ||
| return null; | ||
| } | ||
| return "BOX(" | ||
| + box.getXMin() | ||
| + " " | ||
| + box.getYMin() | ||
| + ", " | ||
| + box.getXMax() | ||
| + " " | ||
| + box.getYMax() | ||
| + ")"; | ||
|
Comment on lines
+887
to
+895
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keeping the as-stored emit semantics — but tightened the Javadoc in c8eecaf to make the contract explicit. Reasoning: the rest of the Box2D API (ST_XMin/XMax/YMin/YMax) returns stored values, not normalized values; if box2dAsText normalized, text output would diverge from accessor output and round-trip via text would be lossy. The swapped-corner ordering is reserved for future antimeridian semantics on geography bboxes (cf. sedona-db WraparoundInterval) and was decided in #2883. Inputs that arrive swapped today are user error rather than a contract violation, and faithful text output is the right debug aid. |
||
| } | ||
|
|
||
| public static byte[] asEWKB(Geometry geometry) { | ||
| return GeomUtils.getEWKB(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.
Added direct
ConstructorsTest.geomFromBox2Din 8007abd covering happy path, degenerate box (collapsed to a point), and null input.