Skip to content

Commit

Permalink
Merge pull request #34 from RemcoMeeuwissen/main
Browse files Browse the repository at this point in the history
Tweaked the intersects call to set the geometry srid to the srid of t…
  • Loading branch information
bitner authored Mar 27, 2023
2 parents d136d67 + 4307c3e commit 99c7de7
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 17 deletions.
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ def database_url(test_db):
test_db.run_sql_file(os.path.join(DATA_DIR, "canada.sql"))
assert test_db.has_table("canada")

test_db.run_sql_file(os.path.join(DATA_DIR, "minnesota.sql"))
assert test_db.has_table("minnesota")

return test_db.connection.engine.url


Expand Down
11 changes: 11 additions & 0 deletions tests/fixtures/minnesota.sql

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions tests/routes/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ def test_collections(app):
assert response.headers["content-type"] == "application/json"
body = response.json()
assert ["links", "numberMatched", "numberReturned", "collections"] == list(body)
assert body["numberMatched"] == 12
assert body["numberReturned"] == 12
assert body["numberMatched"] == 13
assert body["numberReturned"] == 13

ids = [x["id"] for x in body["collections"]]
assert "public.landsat_wrs" in ids
Expand All @@ -27,23 +27,23 @@ def test_collections_search(app):
"""Test /collections endpoint."""
response = app.get("/collections", params={"limit": 1})
body = response.json()
assert body["numberMatched"] == 12
assert body["numberMatched"] == 13
assert body["numberReturned"] == 1
rels = [x["rel"] for x in body["links"]]
assert "next" in rels
assert "prev" not in rels

response = app.get("/collections", params={"limit": 1, "offset": 1})
body = response.json()
assert body["numberMatched"] == 12
assert body["numberMatched"] == 13
assert body["numberReturned"] == 1
rels = [x["rel"] for x in body["links"]]
assert "next" in rels
assert "prev" in rels

response = app.get("/collections", params={"limit": 1, "offset": 11})
response = app.get("/collections", params={"limit": 1, "offset": 12})
body = response.json()
assert body["numberMatched"] == 12
assert body["numberMatched"] == 13
assert body["numberReturned"] == 1
rels = [x["rel"] for x in body["links"]]
assert "next" not in rels
Expand Down
11 changes: 11 additions & 0 deletions tests/routes/test_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,17 @@ def test_items_geo_filter_cql2(app):
assert body["numberMatched"] == 78


def test_items_geo_filter_cql2_non_4326_crs(app):
response = app.get(
"/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)))"
)

assert response.status_code == 200
body = response.json()
assert len(body["features"]) == 2
assert body["numberMatched"] == 2


def test_items_function_filter_cql2(app):
response = app.get(
"/collections/public.landsat_wrs/items?filter-lang=cql2-text&filter=left(pr,2)='13'"
Expand Down
52 changes: 41 additions & 11 deletions tipg/filter/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,47 @@ class Operator:
"not_in": lambda f, a: ~f == any(a),
"any": lambda f, a: f.any(a),
"not_any": lambda f, a: f.not_(f.any(a)),
"INTERSECTS": lambda f, a: Func("st_intersects", f, a),
"DISJOINT": lambda f, a: Func("st_disjoint", f, a),
"CONTAINS": lambda f, a: Func("st_contains", f, a),
"WITHIN": lambda f, a: Func("st_within", f, a),
"TOUCHES": lambda f, a: Func("st_touches", f, a),
"CROSSES": lambda f, a: Func("st_crosses", f, a),
"OVERLAPS": lambda f, a: Func("st_overlaps", f, a),
"EQUALS": lambda f, a: Func("st_equals", f, a),
"RELATE": lambda f, a, pattern: Func("st_relate", f, a, pattern),
"DWITHIN": lambda f, a, distance: Func("st_dwithin", f, a, distance),
"BEYOND": lambda f, a, distance: ~Func("st_dwithin", f, a, distance),
"INTERSECTS": lambda f, a: Func(
"st_intersects",
f,
Func("st_transform", a, Func("st_srid", f)),
),
"DISJOINT": lambda f, a: Func(
"st_disjoint", f, Func("st_transform", a, Func("st_srid", f))
),
"CONTAINS": lambda f, a: Func(
"st_contains", f, Func("st_transform", a, Func("st_srid", f))
),
"WITHIN": lambda f, a: Func(
"st_within", f, Func("st_transform", a, Func("st_srid", f))
),
"TOUCHES": lambda f, a: Func(
"st_touches", f, Func("st_transform", a, Func("st_srid", f))
),
"CROSSES": lambda f, a: Func(
"st_crosses",
f,
Func("st_transform", a, Func("st_srid", f)),
),
"OVERLAPS": lambda f, a: Func(
"st_overlaps",
f,
Func("st_transform", a, Func("st_srid", f)),
),
"EQUALS": lambda f, a: Func(
"st_equals",
f,
Func("st_transform", a, Func("st_srid", f)),
),
"RELATE": lambda f, a, pattern: Func(
"st_relate", f, Func("st_transform", a, Func("st_srid", f)), pattern
),
"DWITHIN": lambda f, a, distance: Func(
"st_dwithin", f, Func("st_transform", a, Func("st_srid", f)), distance
),
"BEYOND": lambda f, a, distance: ~Func(
"st_dwithin", f, Func("st_transform", a, Func("st_srid", f)), distance
),
"+": lambda f, a: f + a,
"-": lambda f, a: f - a,
"*": lambda f, a: f * a,
Expand Down

0 comments on commit 99c7de7

Please sign in to comment.