Skip to content

Commit 99c7de7

Browse files
authored
Merge pull request #34 from RemcoMeeuwissen/main
Tweaked the intersects call to set the geometry srid to the srid of t…
2 parents d136d67 + 4307c3e commit 99c7de7

File tree

5 files changed

+72
-17
lines changed

5 files changed

+72
-17
lines changed

tests/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ def database_url(test_db):
4949
test_db.run_sql_file(os.path.join(DATA_DIR, "canada.sql"))
5050
assert test_db.has_table("canada")
5151

52+
test_db.run_sql_file(os.path.join(DATA_DIR, "minnesota.sql"))
53+
assert test_db.has_table("minnesota")
54+
5255
return test_db.connection.engine.url
5356

5457

tests/fixtures/minnesota.sql

Lines changed: 11 additions & 0 deletions
Large diffs are not rendered by default.

tests/routes/test_collections.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ def test_collections(app):
88
assert response.headers["content-type"] == "application/json"
99
body = response.json()
1010
assert ["links", "numberMatched", "numberReturned", "collections"] == list(body)
11-
assert body["numberMatched"] == 12
12-
assert body["numberReturned"] == 12
11+
assert body["numberMatched"] == 13
12+
assert body["numberReturned"] == 13
1313

1414
ids = [x["id"] for x in body["collections"]]
1515
assert "public.landsat_wrs" in ids
@@ -27,23 +27,23 @@ def test_collections_search(app):
2727
"""Test /collections endpoint."""
2828
response = app.get("/collections", params={"limit": 1})
2929
body = response.json()
30-
assert body["numberMatched"] == 12
30+
assert body["numberMatched"] == 13
3131
assert body["numberReturned"] == 1
3232
rels = [x["rel"] for x in body["links"]]
3333
assert "next" in rels
3434
assert "prev" not in rels
3535

3636
response = app.get("/collections", params={"limit": 1, "offset": 1})
3737
body = response.json()
38-
assert body["numberMatched"] == 12
38+
assert body["numberMatched"] == 13
3939
assert body["numberReturned"] == 1
4040
rels = [x["rel"] for x in body["links"]]
4141
assert "next" in rels
4242
assert "prev" in rels
4343

44-
response = app.get("/collections", params={"limit": 1, "offset": 11})
44+
response = app.get("/collections", params={"limit": 1, "offset": 12})
4545
body = response.json()
46-
assert body["numberMatched"] == 12
46+
assert body["numberMatched"] == 13
4747
assert body["numberReturned"] == 1
4848
rels = [x["rel"] for x in body["links"]]
4949
assert "next" not in rels

tests/routes/test_items.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,17 @@ def test_items_geo_filter_cql2(app):
310310
assert body["numberMatched"] == 78
311311

312312

313+
def test_items_geo_filter_cql2_non_4326_crs(app):
314+
response = app.get(
315+
"/collections/public.minnesota/items?filter-lang=cql2-text&filter=S_INTERSECTS(geom, POLYGON((-95.5389899 47.5578719,-95.5018943 46.4902864,-94.1637708 46.4891952,-94.1277889 47.5804373,-95.5389899 47.5578719)))"
316+
)
317+
318+
assert response.status_code == 200
319+
body = response.json()
320+
assert len(body["features"]) == 2
321+
assert body["numberMatched"] == 2
322+
323+
313324
def test_items_function_filter_cql2(app):
314325
response = app.get(
315326
"/collections/public.landsat_wrs/items?filter-lang=cql2-text&filter=left(pr,2)='13'"

tipg/filter/filters.py

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,47 @@ class Operator:
5858
"not_in": lambda f, a: ~f == any(a),
5959
"any": lambda f, a: f.any(a),
6060
"not_any": lambda f, a: f.not_(f.any(a)),
61-
"INTERSECTS": lambda f, a: Func("st_intersects", f, a),
62-
"DISJOINT": lambda f, a: Func("st_disjoint", f, a),
63-
"CONTAINS": lambda f, a: Func("st_contains", f, a),
64-
"WITHIN": lambda f, a: Func("st_within", f, a),
65-
"TOUCHES": lambda f, a: Func("st_touches", f, a),
66-
"CROSSES": lambda f, a: Func("st_crosses", f, a),
67-
"OVERLAPS": lambda f, a: Func("st_overlaps", f, a),
68-
"EQUALS": lambda f, a: Func("st_equals", f, a),
69-
"RELATE": lambda f, a, pattern: Func("st_relate", f, a, pattern),
70-
"DWITHIN": lambda f, a, distance: Func("st_dwithin", f, a, distance),
71-
"BEYOND": lambda f, a, distance: ~Func("st_dwithin", f, a, distance),
61+
"INTERSECTS": lambda f, a: Func(
62+
"st_intersects",
63+
f,
64+
Func("st_transform", a, Func("st_srid", f)),
65+
),
66+
"DISJOINT": lambda f, a: Func(
67+
"st_disjoint", f, Func("st_transform", a, Func("st_srid", f))
68+
),
69+
"CONTAINS": lambda f, a: Func(
70+
"st_contains", f, Func("st_transform", a, Func("st_srid", f))
71+
),
72+
"WITHIN": lambda f, a: Func(
73+
"st_within", f, Func("st_transform", a, Func("st_srid", f))
74+
),
75+
"TOUCHES": lambda f, a: Func(
76+
"st_touches", f, Func("st_transform", a, Func("st_srid", f))
77+
),
78+
"CROSSES": lambda f, a: Func(
79+
"st_crosses",
80+
f,
81+
Func("st_transform", a, Func("st_srid", f)),
82+
),
83+
"OVERLAPS": lambda f, a: Func(
84+
"st_overlaps",
85+
f,
86+
Func("st_transform", a, Func("st_srid", f)),
87+
),
88+
"EQUALS": lambda f, a: Func(
89+
"st_equals",
90+
f,
91+
Func("st_transform", a, Func("st_srid", f)),
92+
),
93+
"RELATE": lambda f, a, pattern: Func(
94+
"st_relate", f, Func("st_transform", a, Func("st_srid", f)), pattern
95+
),
96+
"DWITHIN": lambda f, a, distance: Func(
97+
"st_dwithin", f, Func("st_transform", a, Func("st_srid", f)), distance
98+
),
99+
"BEYOND": lambda f, a, distance: ~Func(
100+
"st_dwithin", f, Func("st_transform", a, Func("st_srid", f)), distance
101+
),
72102
"+": lambda f, a: f + a,
73103
"-": lambda f, a: f - a,
74104
"*": lambda f, a: f * a,

0 commit comments

Comments
 (0)