query-6ca9f1845269caa3fffea45fea1128a4

rq turtle/ttl

Map of MPs constituencies and their birthplaces

Use at

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX psv: <http://www.wikidata.org/prop/statement/value/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
PREFIX geo: <http://www.opengis.net/ont/geosparql#>
PREFIX bd: <http://www.bigdata.com/rdf#>
# distance from MPs birthplaces to their current seats
SELECT DISTINCT ?item ?itemLabel ?birthplaceLabel ?birthplacecoord ?constituencyLabel ?line ?layer ?rgb WHERE {
  ?item p:P39 ?ps . ?ps ps:P39 wd:Q77685926 . filter not exists { ?ps pq:P582 ?end } # current MPs
  ?ps pq:P4100 ?party . ?party wdt:P465 ?rgb . ?party rdfs:label ?partyLabel . filter(lang(?partyLabel) = "en") .
  ?ps pq:P768 ?constituency . ?constituency wdt:P625 ?constcoord . 
  ?item wdt:P19 ?birthplace . ?birthplace wdt:P625 ?birthcoord . 
  BIND(geof:distance(?constcoord, ?birthcoord) as ?dist) . ?birthplace wdt:P17 wd:Q145 .
  ?constituency p:P625/psv:P625/wikibase:geoLatitude ?lat1 ; p:P625/psv:P625/wikibase:geoLongitude ?lon1 .
  ?birthplace p:P625/psv:P625/wikibase:geoLatitude ?lat2 ; p:P625/psv:P625/wikibase:geoLongitude ?lon2 . 
  BIND(CONCAT('LINESTRING(', STR(?lon1), ' ', STR(?lat1), ',', STR(?lon2), ' ', STR(?lat2), ')') AS ?str) .
  BIND(STRDT(?str, geo:wktLiteral) AS ?line)
  bind(?partyLabel as ?layer)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
#defaultView:Map

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v10("?birthcoord") v9("?birthplace") v8("?constcoord") v7("?constituency") v11("?dist") v3("?end") v4("?item"):::projected v12("?lat1") v14("?lat2") v18("?layer"):::projected v17("?line"):::projected v13("?lon1") v15("?lon2") v5("?party") v1("?partyLabel") v2("?ps") v6("?rgb"):::projected v16("?str") a1((" ")) a2((" ")) a3((" ")) a4((" ")) a5((" ")) a6((" ")) a7((" ")) a8((" ")) c1(["en"]):::literal c19(["bd:serviceParam"]):::iri c5(["wd:Q77685926"]):::iri c13(["wd:Q145"]):::iri f0[["?partyLabel = 'en'"]] f0 --> v1 f1[["not "]] subgraph f1e0["Exists Clause"] e0v1 --"p:qualifier/P582"--> e0v2 e0v2("?end"):::projected e0v1("?ps"):::projected end f1--EXISTS--> f1e0 f1 --> v2 f1 --> c2 f1 --> v3 v2 --"p:qualifier/P582"--> v3 v4 --"p:P39"--> v2 v2 --"p:statement/P39"--> c5 v2 --"p:qualifier/P4100"--> v5 v5 --"p:direct/P465"--> v6 v5 --"rdfs:label"--> v1 v2 --"p:qualifier/P768"--> v7 v7 --"p:direct/P625"--> v8 v4 --"p:direct/P19"--> v9 v9 --"p:direct/P625"--> v10 bind2[/"http://www.opengis.net/def/function/geosparql/distance(?constcoord,?birthcoord)"/] v8 --o bind2 v10 --o bind2 bind2 --as--o v11 v9 --"p:direct/P17"--> c13 v7 --"p:P625"--> a1 a1 --"p:statement/value/P625"--> a2 a2 --"wikibase:geoLatitude"--> v12 v7 --"p:P625"--> a3 a3 --"p:statement/value/P625"--> a4 a4 --"wikibase:geoLongitude"--> v13 v9 --"p:P625"--> a5 a5 --"p:statement/value/P625"--> a6 a6 --"wikibase:geoLatitude"--> v14 v9 --"p:P625"--> a7 a7 --"p:statement/value/P625"--> a8 a8 --"wikibase:geoLongitude"--> v15 bind3[/"concat('LINESTRING(',str(?lon1),' ',str(?lat1),',',str(?lon2),' ',str(?lat2),')')"/] v13 --o bind3 v12 --o bind3 v15 --o bind3 v14 --o bind3 bind3 --as--o v16 bind4[/"STRDT(?str,'geo:wktLiteral')"/] v16 --o bind4 bind4 --as--o v17 bind5[/"?partyLabel"/] v1 --o bind5 bind5 --as--o v18 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c19 --"wikibase:language"--> c1 end