query-042c28c6ba64927eb3f9ce52e75f6b1f

rq turtle/ttl

compare lat/long of Parliament and Wikidata constituency records PREFIX parliament:https://id.parliament.uk/schema/

SELECT DISTINCT ?constituency ?lat ?long ?parlcoord ?item ?itemLabel ?wdcoord ?dist WHERE { SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } SERVICE https://api.parliament.uk/sparql { ?constituency parliament:constituencyGroupHasConstituencyArea ?area . ?area parliament:latitude ?lat . ?area parliament:longitude ?long . bind(SUBSTR(str(?constituency),26) as ?parlid) . } BIND(concat("Point(",str(?long)," ",str(?lat),")"^^geo:wktLiteral) as ?parlcoord) # get constituencies from Parliament with coordinates ?item wdt:P6213 ?parlid . ?item wdt:P31 wd:Q27971968 . ?item wdt:P625 ?wdcoord . # now get them from Wikidata with coordinates BIND(geof:distance(?parlcoord, ?wdcoord) as ?dist) # now find out the distance (in kms) }

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX bd: <http://www.bigdata.com/rdf#>
# compare lat/long of Parliament and Wikidata constituency records
PREFIX parliament:<https://id.parliament.uk/schema/>

SELECT DISTINCT ?constituency ?lat ?long ?parlcoord ?item ?itemLabel ?wdcoord ?dist WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
  SERVICE <https://api.parliament.uk/sparql> 
          { ?constituency parliament:constituencyGroupHasConstituencyArea ?area .
            ?area parliament:latitude ?lat . ?area parliament:longitude ?long . 
            bind(SUBSTR(str(?constituency),26) as ?parlid) . }
  BIND(concat("Point(",str(?long)," ",str(?lat),")"^^geo:wktLiteral) as ?parlcoord) 
  # get constituencies from Parliament with coordinates
  ?item wdt:P6213 ?parlid . ?item wdt:P31 wd:Q27971968 . ?item wdt:P625 ?wdcoord . 
  # now get them from Wikidata with coordinates
  BIND(geof:distance(?parlcoord, ?wdcoord) as ?dist) 
  # now find out the distance (in kms)
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v2("?area") v1("?constituency"):::projected v9("?dist"):::projected v7("?item"):::projected v3("?lat"):::projected v4("?long"):::projected v6("?parlcoord"):::projected v5("?parlid") v8("?wdcoord"):::projected c2(["bd:serviceParam"]):::iri c4(["en"]):::literal c11(["wd:Q27971968"]):::iri subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c2 --"wikibase:language"--> c4 end subgraph s2["https://api.parliament.uk/sparql"] style s2 stroke-width:4px; v1 --https://id.parliament.uk/schema/constituencyGroupHasConstituencyArea--> v2 v2 --https://id.parliament.uk/schema/latitude--> v3 v2 --https://id.parliament.uk/schema/longitude--> v4 bind0[/"substring(str(?constituency),'26^^xsd:integer')"/] v1 --o bind0 bind0 --as--o v5 end bind1[/"concat('Point(',str(?long),' ',str(?lat),s)^^<http://www.opengis.net/ont/geosparql#wktLiteral>')"/] v4 --o bind1 v3 --o bind1 bind1 --as--o v6 v7 --"wdt:P6213"--> v5 v7 --"wdt:P31"--> c11 v7 --"wdt:P625"--> v8 bind2[/"http://www.opengis.net/def/function/geosparql/distance(?parlcoord,?wdcoord)"/] v6 --o bind2 v8 --o bind2 bind2 --as--o v9