Skip to content

Commit

Permalink
Add 'distance(geometry, geometry)' exrepssion function
Browse files Browse the repository at this point in the history
  • Loading branch information
svniemeijer committed Mar 8, 2024
1 parent 9defdb5 commit a66ddee
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
* Allow argument to muninn.open() to be a direct url or path to a muninn
configuration file.

* Added 'distance(geometry,geometry)' expression function.

* Fixed issue when pulling a product that is a directory using the S3 remote
backend.

Expand Down
7 changes: 6 additions & 1 deletion docs/expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ range formed by the second pair of timestamps. Both time ranges are closed.
The function ``covers(geometry, geometry)`` returns true if the first geometry
covers the second geometry.

The function ``distance(geometry, geometry)`` returns the distance between
the two geometries with unit degrees.

The function ``intersects(geometry, geometry)`` returns true if the first
geometry intersects the second geometry.

Expand Down Expand Up @@ -148,7 +151,9 @@ UTC.

``covers(core.validity_start, core.validity_stop, @start, @stop)``

``not covers(core.footprint, POINT (5.0 52.0))``
``not covers(core.footprint, POINT(5.0 52.0))``

``distance(core.footprint, POINT(5.0 52.0)) < 5``

``is_derived_from(32a61528-a712-427a-b28f-8ebd5b472b16)``

Expand Down
4 changes: 4 additions & 0 deletions muninn/database/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,10 @@ def _rewriter_table(self):
rewriter_table[Prototype("covers", (Geometry, Geometry), Boolean)] = \
sql.binary_function_rewriter("ST_Covers")

# use faster non-spheroid distance calculation by passing use_spheroid = false
rewriter_table[Prototype("distance", (Geometry, Geometry), Real)] = \
lambda arg0, arg1: "ST_Distance(%s, %s, false)" % (arg0, arg1)

rewriter_table[Prototype("intersects", (Geometry, Geometry), Boolean)] = \
sql.binary_function_rewriter("ST_Intersects")

Expand Down
3 changes: 3 additions & 0 deletions muninn/database/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,9 @@ def _rewriter_table(self):
rewriter_table[Prototype("covers", (Geometry, Geometry), Boolean)] = \
lambda arg0, arg1: "(ST_Covers(%s, %s)=1)" % (arg0, arg1)

rewriter_table[Prototype("distance", (Geometry, Geometry), Real)] = \
lambda arg0, arg1: "ST_Distance(%s, %s)" % (arg0, arg1)

rewriter_table[Prototype("intersects", (Geometry, Geometry), Boolean)] = \
lambda arg0, arg1: "(ST_Intersects(%s, %s)=1)" % (arg0, arg1)

Expand Down
1 change: 1 addition & 0 deletions muninn/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
#
function_table.add(Prototype("covers", (Geometry, Geometry), Boolean))
function_table.add(Prototype("covers", (Timestamp, Timestamp, Timestamp, Timestamp), Boolean))
function_table.add(Prototype("distance", (Geometry, Geometry), Real))
function_table.add(Prototype("intersects", (Geometry, Geometry), Boolean))
function_table.add(Prototype("intersects", (Timestamp, Timestamp, Timestamp, Timestamp), Boolean))
function_table.add(Prototype("is_defined", (Long,), Boolean))
Expand Down

0 comments on commit a66ddee

Please sign in to comment.