Package: geosparql-dggs
RDFlib GeoSPARQL Functions for DGGSThis library provides support for theGeoSPARQL 1.1 Simple Features Relation Familyfor geometries expressed asDGGS Literals.
Currently,rHEALPix DGGSGrids are supported.InstallationFrom the python package index, PyPi:https://pypi.org/project/geosparql-dggs/pip install geosparql-dggsThis package depends on to support the functions' use against graphsRDFlib. The functions themselves depend on therHEAL-sflibrary, which in turn depends on therHEAL-geolibrary for the base classes
which represent DGGS Cells and collections of Cells.UseThese functions are implemented in RDFlib Python in the filegsdggs/sf_functions.pyand are imported intogsdggs/__init__.pyand registered there in RDFlib as SPARQL extension functions with their IRIs.This means they can be used like this (full working script):fromrdflibimportLiteral,Graph,Namespace,URIReffromgsdggsimportDGGSGEO=Namespace("http://www.opengis.net/ont/geosparql#")# Define the DGGS Geometriesg=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)}"""forring.query(q):print(f"{r['a']}is within{r['b']}")The above stript outputs:https://geom-biswithinhttps://geom-aThe functions can also be used directly (without RDFLib) by direct import from _source, for example:from_sourceimportsfEqualssfEquals("R1","R1")The above stript outputs:TrueFunction DefinitionsThe 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.TestingAll tests are intests/and implemented usingpytest.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.ContributingVia GitHub, Issues & Pull Requests:https://github.com/rdflib/geosparql-dggsLicenseThis code is licensed with the BSD 3-clause license as perLICENSEwhich is the same license as used forrdflib.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}}ContactCreator & maintainer:David HabgoodApplication ArchitectSURROUND Australia Pty Ltddavid.habgood@surroundaustrlaia.comhttps://orcid.org/0000-0002-3322-1868