Colleagues and I are working with RDF dataset and RDF4J's in-Memory repository and we are trying to execute GeoSparql queries while using geometry data in WKT format, as shown below:
@prefix geo: <http://www.opengis.net/ont/geosparql#> .
@prefix sf: <http://www.opengis.net/ont/sf> .
@prefix ex: <http://example.org/> .
@prefix geof: <http://www.opengis.net/def/function/geosparql/>.
ex:eiffelTower a ex:Landmark ;
geo:hasGeometry ex:coordinates-et.
ex:coordinates-et a sf:Point;
geo:asWKT "POINT(2.2945 48.8584)"^^geo:wktLiteral .
ex:towerBridge a ex:Landmark ;
geo:hasGeometry ex:coordinates-tb.
ex:coordinates-tb a sf:Point;
geo:asWKT "POINT(-0.0754 51.5055)"^^geo:wktLiteral .
Scenario-1:
So far we managed to successfully use geof:distance
function, e.g. of a query and it's result are given below. Intention was to calculate the distance between the coordinates of two landmarks.
SELECT *
WHERE {
?lmA a ex:Landmark ;
geo:hasGeometry [ geo:asWKT ?coord1 ].
?lmB a ex:Landmark ;
geo:hasGeometry [ geo:asWKT ?coord2 ].
BIND((geof:distance(?coord1, ?coord2, uom:metre)/1000) as ?dist) .
FILTER (str(?lmA) < str(?lmB))
}
Result of Scenario-1:
lmA => ex:eiffelTower
coord1 => "POINT(2.2945 48.8584)"
lmB => ex:towerBridge
coord2 => "POINT(-0.0754 51.5055)"
dist => "339.2412973915987"
Scenario-2:
When we tried to use other functions, e.g. geof:sfWithin
, geof:sfContains
, we ran into some strange behavior. The query with geof:sfWithin
example and it's result are shown below. Intention was to get all the points that are positioned inside the given polygon.
SELECT *
WHERE {
?lmA a ex:Landmark ;
geo:hasGeometry ?Geom.
?Geom geo:asWKT ?WKT.
FILTER(geof:sfWithin(?WKT, '''
<http://www.opengis.net/def/crs/OGC/1.3/CRS84>
Polygon ((80.0 80.0, -80.0 80.0, -80.0 -80.0, 80.0 -80.0, 80.0 80.0))
'''^^geo:wktLiteral))
}
Result: -empty table-
Are we doing something wrong in our queries? Our dependencies:
rdf4j-storage 3.6.0
rdf4j-queryalgebra-geosparql 3.6.1