fix(cql2_json): correct Envelope axis order for bbox literals - #174
Open
C1-BA-B1-F3 wants to merge 2 commits into
Open
C1-BA-B1-F3 wants to merge 2 commits into
C1-BA-B1-F3 wants to merge 2 commits into
Conversation
The unquoted attribute regex /[a-zA-Z][a-zA-Z_:0-9.]+/ required at least two characters, so expressions like 'a = 1' or 'S_INTERSECTS(g, BBOX(...))' failed to parse. Change the trailing .+ to .* so a single-letter identifier is accepted. Fixes geopython#165
A GeoJSON bbox literal is [minx, miny, maxx, maxy], but parsers/cql2_json/parser.py unpacked it directly into values.Envelope(*bbox) whose field order is (x1, x2, y1, y2) == (minx, maxx, miny, maxy). The two conventions were conflated, so longitudes and latitudes were silently swapped. Reindex explicitly: Envelope(b[0], b[2], b[1], b[3]). Fixes geopython#163
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A GeoJSON
bboxliteral is[minx, miny, maxx, maxy](RFC 7946 §5), butparsers/cql2_json/parser.pyunpacked it directly intovalues.Envelope(*bbox):values.Envelopefield order is(x1, x2, y1, y2) == (minx, maxx, miny, maxy)(consistent with the cql2_text parser and the SQLAlchemy backend since #147). Unpacking the GeoJSON array positionally conflated the two orderings, silently swapping longitudes and latitudes.Concrete effect (from the issue):
{"bbox": [-74.1, 40.5, -73.9, 41.0]}(a ~20 km box over New York) was parsed asEnvelope(x1=-74.1, x2=40.5, y1=-73.9, y2=41.0), makingS_INTERSECTSmatch a large part of the hemisphere.Fix
Reindex explicitly:
values.Envelope(b[0], b[2], b[1], b[3]).Test plan
test_bbox_envelope_axis_orderandtest_bbox_envelope_globalcover both a local NYC box and the global box.pytest tests/parsers/cql2_json/— 43/43 pass (41 pre-existing + 2 new).bboxinside GeoJSONGeometryobjects are unaffected (those go throughvalues.Geometry, notvalues.Envelope).Fixes #163