GeoSPARQL support

compared with
Current by Pavel Mihaylov
on Oct 20, 2015 11:36.

Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (35)

View Page History

A simplified diagram of some geometry classes and properties:


!GeoSPARQL-geometry.PNG|width=700!

GraphDB 6.X5 introduces support for GeoSPARQL.

h1. Installation

The GeoSPARQL support is implemented as a GraphDB plugin, which is currently not included installed by default. To include install the plugin follow these steps:

# Locate the plugin {{zip}} file in the {{plugins/geosparql-plugin}} folder of the GraphDB distribution.
# Unzip the file into your plugins directory (by default {{{*}root_of_unpacked_web_app/WEB-INF/classes/plugins{*}}}). {{root_of_unpacked_web_app/WEB-INF/classes/plugins}}).

h1. Usage examples
{note}
Note that you still have to enable the plugin after you install it. See [#Enable plugin] for more information.
{note}

h1. Usage

h3. Plugin control predicates

h4. Enable plugin

When the plugin is enabled it will index all existing GeoSPARQL data in the repository and automatically reindex any updates.

{code}
PREFIX : <http://www.ontotext.com/plugins/geosparql#>
{code}

NOTE: The object literal can be written also as an _xsd boolean_ type by including a _xsd_ prefix:

h4. Disable plugin

When the plugin is disabled it will not index any data or process updates. It will not handle any of the GeoSPARQL predicates either.

{code}
PREFIX : <http://www.ontotext.com/plugins/geosparql#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

INSERT DATA {
_:s :enabled "true"^^xsd:boolean "false" .
}
{code}


h4. Disable plugin
h4. Force reindex GeoSPARQL geometry data

Usually this is a configuration option which could be used in cases where your index files
are either corrupted or have been mistakenly deleted.

{code}
PREFIX : <http://www.ontotext.com/plugins/geosparql#>

INSERT DATA {
_:s :enabled "false" .
_:s :forceReindex ""
}
{code}

NOTE: The object literal can be written also as an _xsd boolean_ type by including a _xsd_ prefix:
h3. GeoSPARQL Predicates

Some examples of select queries on geographic data. For demo purposes just import the following files:
* [GeoSPARQL support^simple_features_geometries.rdf]
* [GeoSPARQL support^geosparql-example.rdf]

and run the following queries queries on them:

* Example 1
{code}
PREFIX : <http://www.ontotext.com/plugins/geosparql#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX my: <http://example.org/ApplicationSchema#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>

INSERT DATA {
_:s :enabled "false"^^xsd:boolean .
SELECT ?f
WHERE {
my:A my:hasExactGeometry ?aGeom .
?aGeom geo:asWKT ?aWKT .
?f my:hasExactGeometry ?fGeom .
?fGeom geo:asWKT ?fWKT .
FILTER (geof:sfContains(?aWKT, ?fWKT) && !sameTerm(?aGeom, ?fGeom))
}
{code}

h4. Force Reindex GeoSPARQL geometry data
* Example 2
{code}
PREFIX my: <http://example.org/ApplicationSchema#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>

Usually this is a configuration option which could be used in cases where your index files
are either corrupted or have been mistakenly deleted.
SELECT ?f
WHERE {
?f my:hasPointGeometry ?fGeom .
?fGeom geo:asWKT ?fWKT .
FILTER (geof:sfWithin(?fWKT, '''
<http://www.opengis.net/def/crs/OGC/1.3/CRS84>
Polygon ((-83.4 34.0, -83.1 34.0, -83.1 34.2, -83.4 34.2, -83.4 34.0))
'''^^geo:wktLiteral))
}
{code}

* Example 3
{code}
PREFIX : <http://www.ontotext.com/plugins/geosparql#>
PREFIX my: <http://example.org/ApplicationSchema#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>

INSERT DATA {
_:s :forceReindex ""
SELECT ?f
WHERE {
?f my:hasExactGeometry ?fGeom .
?fGeom geo:asWKT ?fWKT .
my:A my:hasExactGeometry ?aGeom .
?aGeom geo:asWKT ?aWKT .
my:D my:hasExactGeometry ?dGeom .
?dGeom geo:asWKT ?dWKT .
FILTER (geof:sfTouches(?fWKT, geof:union(?aWKT, ?dWKT)))
}
{code}

h3. GeoSPARQL Predicates

* Example 4
{code}
PREFIX uom: <http://www.opengis.net/def/uom/OGC/1.0/>
PREFIX my: <http://example.org/ApplicationSchema#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>

SELECT ?f
WHERE {
my:C my:hasExactGeometry ?cGeom .
?cGeom geo:asWKT ?cWKT .
?f my:hasExactGeometry ?fGeom .
?fGeom geo:asWKT ?fWKT .
FILTER (?fGeom != ?cGeom)
} ORDER BY ASC(geof:distance(?cWKT, ?fWKT, uom:metre)) LIMIT 3
{code}

* Example 5
{code}
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX my: <http://example.org/ApplicationSchema#>

SELECT ?f
WHERE {
?f geo:sfOverlaps my:AExactGeom
}
{code}

* Example 6

{note}
Using geometry literals in the object position is a GraphDB extension and not part of the GeoSPARQL specification.
{note}

{code}
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX my: <http://example.org/ApplicationSchema#>

SELECT ?f
WHERE {
?f geo:sfOverlaps "Polygon((-83.6 34.1, -83.2 34.1, -83.2 34.5, -83.6 34.5, -83.6 34.1))"^^geo:wktLiteral
}
{code}


For more information regarding GeoSPARQL predicates and functions please look at the [current official spec |http://www.opengis.net/doc/IS/geosparql/1.0]: OGC 11-052r4, Version: 1.0, Approval Date: 2012-04-27, Publication Date: 2012-09-10.