Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions pygeofilter/parsers/cql2_text/grammar.lark
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@


?spatial_predicate: _binary_spatial_predicate_func "(" expression "," expression ")" -> binary_spatial_predicate
| "RELATE" "(" expression "," expression "," SINGLE_QUOTED ")" -> relate_spatial_predicate
| _binary_spatial_predicate_func "(" expression "," bbox ")" -> binary_spatial_predicate

!_binary_spatial_predicate_func: "S_INTERSECTS"i
| "S_DISJOINT"i
Expand Down Expand Up @@ -120,17 +118,14 @@ func.2: attribute "(" expression ("," expression)* ")" -> function
| BOOLEAN
| SINGLE_QUOTED
| ewkt_geometry -> geometry
| envelope
| bbox
| bbox_literal

?full_number: number
| "-" number -> neg

?number: FLOAT | INT

envelope: "ENVELOPE"i "(" number number number number ")"

bbox: "BBOX"i "(" full_number "," full_number "," full_number "," full_number ")"
bbox_literal: "BBOX"i "(" full_number "," full_number "," full_number "," full_number ")"

BOOLEAN.2: ( "TRUE"i | "FALSE"i)

Expand Down
10 changes: 2 additions & 8 deletions pygeofilter/parsers/cql2_text/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,13 @@ def binary_temporal_predicate(self, lhs, op, rhs):
op = op.lower()
return TEMPORAL_PREDICATES_MAP[op](lhs, rhs)

def relate_spatial_predicate(self, lhs, rhs, pattern):
return ast.Relate(lhs, rhs, pattern)

def distance_spatial_predicate(self, op, lhs, rhs, distance, units):
cls = ast.DistanceWithin if op == "DWITHIN" else ast.DistanceBeyond
return cls(lhs, rhs, distance, units)

def distance_units(self, value):
return value

def bbox_spatial_predicate(self, lhs, minx, miny, maxx, maxy, crs=None):
return ast.BBox(lhs, minx, miny, maxx, maxy, crs)

def function(self, func_name, *expressions):
name = func_name.name.lower()
if name == "casei":
Expand Down Expand Up @@ -190,8 +184,8 @@ def SINGLE_QUOTED(self, token):
def geometry(self, value):
return values.Geometry(value)

def bbox(self, x1, y1, x2, y2):
return values.Envelope(x1, x2, y1, y2)
def bbox_literal(self, west, south, east, north):
return values.Envelope(west, east, south, north)

def interval(self, start, end):
return values.Interval(start, end)
Expand Down
11 changes: 11 additions & 0 deletions tests/parsers/cql2_text/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,17 @@ def test_intersects_geometry():
assert isinstance(result.rhs, values.Geometry)


def test_intersects_bbox_literal():
result = parse("S_INTERSECTS(attr, BBOX(-118, 33, -117, 34))")
assert isinstance(result, ast.GeometryIntersects)
assert result.lhs == ast.Attribute("attr")
assert isinstance(result.rhs, values.Envelope)
assert result.rhs.x1 == -118
assert result.rhs.y1 == 33
assert result.rhs.x2 == -117
assert result.rhs.y2 == 34


def test_attribute_boolean_literal_true():
result = parse("attr = TRUE")
assert result == ast.Equal(
Expand Down
Loading