geosparql distances - geovistory/wiki Wiki

Examples

Community Data, distances between all places

Some specific filters and features are added for the sake of example

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX xml: <http://www.w3.org/XML/1998/namespace>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX ontome: <https://ontome.net/ontology/>
PREFIX geov: <http://geovistory.org/resource/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
prefix spatialF: <http://jena.apache.org/function/spatial#>
prefix units: <http://www.opengis.net/def/uom/OGC/1.0/> 

SELECT  (spatialF:distance(?place, ?place1, units:kilometre) as ?km_distance) ?subject ?geoPlaceLabel ?long ?lat ?subject1 ?geoPlaceLabel1 ?long1 ?lat1
WHERE {
  { SELECT * 
    WHERE {?subject ^ontome:p147 ?presence.
  ?subject rdfs:label    ?geoPlaceLabel.
        ?presence ontome:p148 ?place.
      
   bind(replace(str(?place), '<http://www.opengis.net/def/crs/EPSG/0/4326>', "", "i") as ?rep)
   bind( replace( str(?rep), "^[^0-9\\.-]*([-]?[0-9\\.]+) .*$", "$1" ) as ?long )
   bind( replace( str(?rep), "^.* ([-]?[0-9\\.]+)[^0-9\\.]*$", "$1" ) as ?lat )
    }
  }   

 { SELECT * 
    WHERE {?subject1 ^ontome:p147 ?presence1.
  ?subject1 rdfs:label    ?geoPlaceLabel1.
        ?presence1 ontome:p148 ?place1.
    
   bind(replace(str(?place1), '<http://www.opengis.net/def/crs/EPSG/0/4326>', "", "i") as ?rep1)
   bind( replace( str(?rep1), "^[^0-9\\.-]*([-]?[0-9\\.]+) .*$", "$1" ) as ?long1 )
   bind( replace( str(?rep1), "^.* ([-]?[0-9\\.]+)[^0-9\\.]*$", "$1" ) as ?lat1 )}
  }   


  FILTER(str(?subject) < str(?subject1) && CONTAINS(?geoPlaceLabel1, 'Bern CH'))
}
LIMIT 30

Basic query structure (to be commented)

PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
prefix spatialF: <http://jena.apache.org/function/spatial#>
prefix units: <http://www.opengis.net/def/uom/OGC/1.0/>

SELECT (spatialF:distance(?o, ?o1, units:kilometre) as ?dis) ?s ?o ?s1 ?o1 
WHERE {
   ?s geo:hasGeometry/geo:asWKT ?o.
   ?s1 geo:hasGeometry/geo:asWKT ?o1
  FILTER(str(?s) < str(?s1))
}