Skip to content

fix(cql2_json): correct Envelope axis order for bbox literals - #174

Open
C1-BA-B1-F3 wants to merge 2 commits into
geopython:mainfrom
C1-BA-B1-F3:fix/cql2-json-bbox-axis-order
Open

C1-BA-B1-F3 wants to merge 2 commits into
geopython:mainfrom
C1-BA-B1-F3:fix/cql2-json-bbox-axis-order

Conversation

@C1-BA-B1-F3

Copy link
Copy Markdown

Summary

A GeoJSON bbox literal is [minx, miny, maxx, maxy] (RFC 7946 §5), but parsers/cql2_json/parser.py unpacked it directly into values.Envelope(*bbox):

return values.Envelope(*node["bbox"])

values.Envelope field 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 as Envelope(x1=-74.1, x2=40.5, y1=-73.9, y2=41.0), making S_INTERSECTS match a large part of the hemisphere.

Fix

Reindex explicitly: values.Envelope(b[0], b[2], b[1], b[3]).

Test plan

  • New regression tests test_bbox_envelope_axis_order and test_bbox_envelope_global cover both a local NYC box and the global box.
  • pytest tests/parsers/cql2_json/ — 43/43 pass (41 pre-existing + 2 new).
  • Existing geometry tests that embed bbox inside GeoJSON Geometry objects are unaffected (those go through values.Geometry, not values.Envelope).

Fixes #163

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cql2-json: {"bbox": ...} literals scramble axes through values.Envelope field order

1 participant