coolaturon
coolaturon

Reputation: 127

SPARQL: using function bif:st_distance and bif:st_points do not work outside SERVICE

I'm trying to write a SPARQL request, where I want to query country names from my own dataset, use the dbpedia resource to retrieve the countrie's latitude and longitude and then calculate the distance among them with the bif:st_distance function. The latitude and longitude I want to use are floats, so I have to convert them to points with bif:st_point first, since the function takes points only.

On my local machine I'm running a apache jena-fuseki server with my dataset loaded. I tried the following:

PREFIX rate: <http://MYNAME.bplaced.net/rating/index.ttl#>
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX bif: <bif:>
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX afn: <http://jena.apache.org/ARQ/function#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?from ?to ?latituded ?longituded ?latitudeo ?longitudeo ?distance WHERE{
  
    {SELECT ?from ?to (AVG(?latd) as ?latituded) 
        (AVG(?longd) as ?longituded)
        (AVG(?lato) as ?latitudeo)
        (AVG(?longo) as ?longitudeo) WHERE {
            ?rating rate:from dbr:Germany.                  
            ?rating rate:year "1965"^^xsd:gYear.
            ?rating rate:from ?from.
            ?rating rate:to ?to.
            SERVICE <http://dbpedia.org/sparql>{
                ?from geo:lat ?latd.
                ?from geo:long ?longd.
                ?to geo:lat ?lato.
                ?to geo:long ?longo.
            }
      
        } GROUP BY ?from ?to
    }

BIND(bif:st_distance(
    bif:st_point(?latituded,?longituded),
    bif:st_point(?latitudeo,?longitudeo)
)AS ?distance).
}

This leaves me with this result: The query result

As you can see: The distance column remains empty. I am sure it has something to do with whether or not the BIND statement is located within the SERVICE. Might some values be invisible to the BIND?

What am I doing wrong or what can I do differently to solve this? Thanks in advance!

Upvotes: 0

Views: 260

Answers (1)

chrisis
chrisis

Reputation: 1993

The spatial functions in the bif namespace are specific to Virtuoso, the software used by DBpedia. Therefore they will only work in the SERVICE clause where the query is executed on the Virtuoso server. So either use these functions in the SERVICE clause or take a look at the Jena spatial functions.

Upvotes: 3

Related Questions