Skip to main content

RDFlib GeoSPARQL Functions for DGGS

This library provides support for the GeoSPARQL 1.1 Simple Features Relation Family for geometries expressed as DGGS Literals. Currently, rHEALPix DGGS Grids are supported.

Installation

From the python package index, PyPi: https://pypi.org/project/geosparql-dggs/
pip install geosparql-dggs

This package depends on to support the functions' use against graphs RDFlib. The functions themselves depend on the rHEAL-sf library, which in turn depends on the rHEAL-geo library for the base classes which represent DGGS Cells and collections of Cells.

Use

These functions are implemented in RDFlib Python in the file gsdggs/sf_functions.py and are imported into gsdggs/__init__.py and registered there in RDFlib as SPARQL extension functions with their IRIs.

This means they can be used like this (full working script):

from rdflib import Literal, Graph, Namespace, URIRef
from gsdggs import DGGS

GEO = Namespace("http://www.opengis.net/ont/geosparql#")

# Define the DGGS Geometries
g = Graph()
geom_a = URIRef('https://geom-a')
geom_b = URIRef('https://geom-b')
geom_c = URIRef('https://geom-c')
g.add((geom_a, GEO.hasGeometry, Literal('CELLLIST ((R0 R10 R13 R16 R30 R31 R32 R40))')))
g.add((geom_b, GEO.hasGeometry, Literal('CELLLIST ((R06 R07 R30 R31))')))
g.add((geom_c, GEO.hasGeometry, Literal('CELLLIST ((R11 R12 R14 R15))')))

q = """
    PREFIX geo: <http://www.opengis.net/ont/geosparql#>
    PREFIX dggs: <https://placeholder.com/dggsfuncs/>
    SELECT ?a ?b 
        {?a geo:hasGeometry ?a_geom .
         ?b geo:hasGeometry ?b_geom .
         FILTER dggs:sfWithin(?a_geom, ?b_geom)
    }"""
for r in g.query(q):
    print(f"{r['a']} is within {r['b']}")

The above stript outputs:

https://geom-b is within https://geom-a

The functions can also be used directly (without RDFLib) by direct import from _source, for example:

from _source import sfEquals

sfEquals("R1", "R1")

The above stript outputs:

True

Function Definitions

The Simple Feature relations have been interpreted in the following way for the context of a nested square DGGS grid (such as rHEALPix grids).

  • dggs:sfEqual: Two sets of cells are equal if they have the same identifier.
  • dggs:sfWithin: One set of cells (A) is within some other set of cells (B) if the addition of A's cells to B results in a set of cells equal to B, where A is not equal to B.
  • dggs:sfContains: One set of cells (A) is contains some other set of cells (B) if the addition of A's cells to B results in a set of cells equal to A, where A is not equal to B.
  • dggs:sfIntersects: One set of cells (A) intersects some other set of cells (B) where they share any two cells, or any cell in A is the parent or child of a cell in B, or any cell in A or B touches.
  • dggs:sfTouches: One set of cells (A) touches some other set of cells (B) where the cells meet at an edge, or vertex.
  • dggs:sfDisjoint: One set of cells (A) is disjoint with some other set of cells (B) where they do not share any two cells, no cell in A is the parent or child of a cell in B, and no cells in A and B touch.
  • dggs:sfOverlaps: One set of cells (A) overlaps some other set of cells (B) where the addition of A's cells to B results in a set of cells different from A and B, and A and B are not disjoint and do not touch.

Testing

All tests are in tests/ and implemented using pytest.

There are individual tests for each function, along with more granular tests for supporting Python classes (Cells and CellCollections), as well as application of the functions without RDF.

Contributing

Via GitHub, Issues & Pull Requests:

License

This code is licensed with the BSD 3-clause license as per LICENSE which is the same license as used for rdflib.

Citation

@software{https://github.com/rdflib/geosparql-dggs,
  author = {{David Habgood}},
  title = {RDFlib GeoSPARQL Functions for DGGS},
  version = {0.0.1},
  date = {2021},
  url = {https://github.com/rdflib/geosparql-dggs}
}

Contact

Creator & maintainer:
David Habgood
Application Architect
SURROUND Australia Pty Ltd
david.habgood@surroundaustrlaia.com

https://orcid.org/0000-0002-3322-1868

Release files for geosparql-dggs 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for geosparql-dggs 0.2
File Size Uploaded
geosparql-dggs-0.2.tar.gz 5.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for geosparql-dggs 0.2
File Interpreter ABI Platform
geosparql_dggs-0.2-py3-none-any.whl Python 3 none any Details

Total release size: 10.7 kB

Release files / geosparql-dggs-0.2.tar.gz

Download URL geosparql-dggs-0.2.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0ffb5dd0d2c66854ce264b64562eb990278d7bf7e715853001b05f7ecd4b97b3
BLAKE2b-256 checksum
How to use checksums
d0737c3991c9e57682a15f49f65555f00fc007fa20fa2121afac4fc57c641894
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

Release files / geosparql_dggs-0.2-py3-none-any.whl

Download URL geosparql_dggs-0.2-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
297eedc399711c5c307b612bcdc4f55ead86ee7e3a5e486976725218cdd8d773
BLAKE2b-256 checksum
How to use checksums
352e530337caad93d2c5919db93fcff6481756a97dfd2c5dd990550cce35b433
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

Release history Release notifications | RSS feed

This release

0.2 This release

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page