2

I'm trying to calculate the distance between two points using geosparql. I have objects like the following image (same properties, different values):

enter image description here

And I'm executing that query in sparql:

PREFIX geos: <http://www.opengis.net/ont/geosparql#>
PREFIX geosf: <http://www.opengis.net/def/function/geosparql/>
PREFIX : <http://www.semanticweb.org/frubi/ontologies/2017/10/puntsWIFI#>

SELECT ?distance
WHERE {
    ?wifipoint1 :hasGeometry ?geo1 .
    ?geo1 geos:asWKT ?wpoint1 .
    FILTER sameterm(?wifipoint1, <http://www.semanticweb.org/frubi/ontologies/2017/10/puntsWIFI#NYWifiFree103>) 
    ?wifipoint2 :hasGeometry ?geo2 .
    ?geo2 geos:asWKT ?wpoint2 .
    FILTER sameterm(?wifipoint2, <http://www.semanticweb.org/frubi/ontologies/2017/10/puntsWIFI#NYWifiFree105>) .
    ?distance geosf:distance(?wpoint1 ?wpoint2 <http://qudt.org/vocab/unit#Kilometer>)
}

Without adding the distance, I'm able to get the following result:

enter image description here

But at the moment I add the distance I get empty rows. Any idea?

Notes:

  • I need to calculate the distance between two wifipoints (NYWifiFree103 and NYWifiFree105) which have each one a point.

  • I'm executing that queries in stardog.

** EDIT **

I simplified the query:

PREFIX geos: <http://www.opengis.net/ont/geosparql#>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
PREFIX : <http://www.semanticweb.org/frubi/ontologies/2017/10/puntsWIFI#>

SELECT (geof:distance(?wpoint1, ?wpoint2, <http://qudt.org/vocab/unit#Kilometer>) as ?distance)
WHERE {
    ?wifipoint1 :hasGeometry ?geo1 .
    ?geo1 geos:asWKT ?wpoint1 .
    FILTER sameterm(?wifipoint1, <http://www.semanticweb.org/frubi/ontologies/2017/10/puntsWIFI#NYWifiFree103>) .
    ?wifipoint2 :hasGeometry ?geo2 .
    ?geo2 geos:asWKT ?wpoint2 .
    FILTER sameterm(?wifipoint2, <http://www.semanticweb.org/frubi/ontologies/2017/10/puntsWIFI#NYWifiFree105>)
}

When I set in geof:distance two harcoded wktLiteral returns me correct distance, but using Points does not return nothing.

3 Answers3

2

The geof:distance function accepts Geometries as its first two parameters. So with your simplified query, using geof:distance(?geo1, ?geo2, unit:Kilometer) should give you the result you desire. The Stardog Blog has a geospatial primer post that you may find useful.

snowell
  • 181
  • 2
0

AKSW is correct, you should use the built in geof:distance function for the calculation.

Michael
  • 4,858
  • 19
  • 32
0

I have the same problem with GraphDB. instead of distance it returns 2 fields empty and I have already enabled geosparql

Here is my code:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX : <http://www.semanticweb.org/evangelos/ontologies/2019/2/untitled-ontology-2#>
prefix geo: <http://www.opengis.net/ont/geosparql#>
prefix geof: <http://www.opengis.net/def/function/geosparql/>
prefix unit: <http://qudt.org/vocab/unit#>
prefix sf: <http://www.opengis.net/ont/sf#>
prefix test24: <http://www.semanticweb.org/evangelos/ontologies/2019/2/untitled-ontology-2#>
prefix omgeo: <http://www.ontotext.com/owlim/geo#>

SELECT (geof:distance(?point, ?point2, <http://qudt.org/vocab/unit#Kilometer>) as ?distance)
WHERE
{
    :MouseioMetaksisSoufliou :hasGPSCoordinates ?geom2.
    ?geom2 geo:asWKT ?point.
    ?geom3 geo:asWKT ?point2.
    FILTER (?geom2 != ?geom3)
} 
GGEv
  • 843
  • 9
  • 23