Skip to content

feat: added s_dwithin predicate - #166

Open
jkaniuka wants to merge 4 commits into
geopython:mainfrom
piappl:feat/cql2
Open

jkaniuka wants to merge 4 commits into
geopython:mainfrom
piappl:feat/cql2

Conversation

@jkaniuka

@jkaniuka jkaniuka commented Aug 29, 2026 •

Copy link
Copy Markdown

Adds support for s_dwithin predicate to query GeoJSON records whose feature.geometry is within a given distance from a specified point.

Here ➡️ pygeoapi/pull/2403 is a link to corresponding PR that modifies the Mongo provider in pygeoapi. Our goal is to enable queries like the one below:

{
    "filter-lang": "cql2-json",
    "filter": {
        "op": "s_dwithin",
        "args": [
            {"property": "feature.geometry"},
            {
                "type": "Point",
                "coordinates": [13.0, 65.0]
            },
            250000,
            "meters"
        ]
    }
}

Thanks to @Jacob7052 for the implementation 😎

@tomkralidis

Copy link
Copy Markdown
Member

@jkaniuka thanks for this. Can you add a test to this PR? Diff below (works locally):

diff --git a/tests/parsers/cql_json/test_parser.py b/tests/parsers/cql_json/test_parser.py
index 5d45142..4e433c7 100644
--- a/tests/parsers/cql_json/test_parser.py
+++ b/tests/parsers/cql_json/test_parser.py
@@ -597,18 +597,17 @@ def test_overlaps_attr_multilinestring():
 
 # # dwithin/beyond
 
-# def test_dwithin_attr_polygon():
-#     result = parse('DWITHIN(geometry, POLYGON((1 1,2 2,0 3,1 1)), 5, feet)')
-#     print(get_repr(result))
-#     assert result == ast.SpatialDistancePredicateNode(
-#         ast.Attribute('geometry'),
-#         ast.LiteralExpression(
-#             geometry.Polygon([(1, 1), (2, 2), (0, 3), (1, 1)])
-#         ),
-#         ast.SpatialDistanceOp('DWITHIN'),
-#         distance=5,
-#         units='feet',
-#     )
+def test_dwithin_attr_polygon():
+    result = parse('DWITHIN(geometry, POLYGON((1 1,2 2,0 3,1 1)), 5, feet)')
+    assert result == ast.SpatialDistancePredicateNode(
+        ast.Attribute('geometry'),
+        ast.LiteralExpression(
+            geometry.Polygon([(1, 1), (2, 2), (0, 3), (1, 1)])
+        ),
+        ast.SpatialDistanceOp('DWITHIN'),
+        distance=5,
+        units='feet',
+    )
 
 
 # def test_beyond_attr_polygon():

@jkaniuka

jkaniuka commented Oct 1, 2026

Copy link
Copy Markdown
Author

@tomkralidis Test added but there is some kind of issue with JSON decoder. Did you encounter it locally?

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.

2 participants