Spatial Join
A spatial join combines two sets of objects by a spatial condition on their geometries, e.g. distance at most d, instead of equality of values; in SPARQL on OpenStreetMap it is written with WKT geometries and `geof:distance` in a FILTER.
Properties#
- In SPARQL (GeoSPARQL, OpenStreetMap):
- an object’s geometry is reached via
geo:hasGeometry/geo:asWKT, a Property Path, and is a literal in WKT format (geo:wktLiteral), e.g."POINT(7.842 47.998)"^^geo:wktLiteral; - the condition is a
FILTERwithgeof:distance(g1, g2, unit), with the unit given as an IRI (unit:Mfor metres).
- an object’s geometry is reached via
- Constant side. In the lecture example, one side is a single fixed point, so the “join” selects all buildings within 500 m of that point. With a variable on both sides, the same
FILTERjoins two sets of objects, like the DBIS SQL examplebus_stops JOIN restaurants ON ST_Distance(…) < 500(DBIS_VL05 > Join operation). ?building osmkey:building ?anythingmatches every OSM object with abuildingtag, whatever its value. The variable?anythingis only a placeholder.
Example#
PREFIX osmkey: <https://www.openstreetmap.org/wiki/Key:>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
PREFIX unit: <http://qudt.org/vocab/unit/>
SELECT ?building ?building_wkt WHERE {
?building osmkey:building ?anything .
?building geo:hasGeometry/geo:asWKT ?building_wkt .
FILTER (geof:distance("POINT(7.842 47.998)"^^geo:wktLiteral,
?building_wkt, unit:M) <= 500)
}
# Buildings in a 500 m radius around Freiburg Hauptbahnhof
With toy geometries: building at 200 m and at 800 m from the point give the result . The FILTER removes .
Sources#
- Slides 01, p. 24
- ADIS_VL01 > Spatial Join
- DBIS: DBIS Slides 05, p. 22 (spatial join in SQL)