query-5142af06e3cc23cbd0f9e56eaa76111b
Federated queries Wikidata:WikiProject British Politicians/parlidataWorking notes at Querying Parliament Data and recovering labels from Wikidatalink at api.parliament.ukQuerying Wikidata and recovering coordinates from Parliament Data
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX psv: <http://www.wikidata.org/prop/statement/value/>
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#>
# compare lat/long of Parliament and Wikidata constituency records
PREFIX parliament:<https://id.parliament.uk/schema/>
SELECT DISTINCT ?constituency ?parlcoord ?item ?itemLabel ?wdcoord ?dist ?line 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) . filter (?dist >= 10)
# now find out the distance (in kms) and show those where distance > 10km
?item p:P625 ?statementnode. ?statementnode psv:P625 ?valuenode.
?valuenode wikibase:geoLatitude ?wikilat . ?valuenode wikibase:geoLongitude ?wikilon.
BIND(CONCAT('LINESTRING (', STR(?wikilon), ' ', STR(?wikilat), ',', STR(?long), ' ', STR(?lat), ')') AS ?str) .
BIND(STRDT(?str, geo:wktLiteral) AS ?line)
}
#defaultView:Map
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v3("?area")
v2("?constituency"):::projected
v10("?dist"):::projected
v8("?item"):::projected
v4("?lat")
v15("?line"):::projected
v5("?long")
v7("?parlcoord"):::projected
v6("?parlid")
v10("?statementnode")
v14("?str")
v11("?valuenode")
v9("?wdcoord"):::projected
v12("?wikilat")
v13("?wikilon")
c5(["en"]):::literal
c12(["wd:Q27971968"]):::iri
c3(["bd:serviceParam"]):::iri
f0[["?dist >= '10^^xsd:integer'"]]
f0 --> v10
subgraph s1["http://wikiba.se/ontology#label"]
style s1 stroke-width:4px;
c3 --"wikibase:language"--> c5
end
subgraph s2["https://api.parliament.uk/sparql"]
style s2 stroke-width:4px;
v2 --https://id.parliament.uk/schema/constituencyGroupHasConstituencyArea--> v3
v3 --https://id.parliament.uk/schema/latitude--> v4
v3 --https://id.parliament.uk/schema/longitude--> v5
bind1[/"substring(str(?constituency),'26^^xsd:integer')"/]
v2 --o bind1
bind1 --as--o v6
end
bind2[/"concat('Point(',str(?long),' ',str(?lat),s)^^<http://www.opengis.net/ont/geosparql#wktLiteral>')"/]
v5 --o bind2
v4 --o bind2
bind2 --as--o v7
v8 --"p:direct/P6213"--> v6
v8 --"p:direct/P31"--> c12
v8 --"p:direct/P625"--> v9
bind3[/"http://www.opengis.net/def/function/geosparql/distance(?parlcoord,?wdcoord)"/]
v7 --o bind3
v9 --o bind3
bind3 --as--o v10
v8 --"p:P625"--> v10
v10 --"p:statement/value/P625"--> v11
v11 --"wikibase:geoLatitude"--> v12
v11 --"wikibase:geoLongitude"--> v13
bind4[/"concat('LINESTRING (',str(?wikilon),' ',str(?wikilat),',',str(?long),' ',str(?lat),')')"/]
v13 --o bind4
v12 --o bind4
v5 --o bind4
v4 --o bind4
bind4 --as--o v14
bind5[/"STRDT(?str,'geo:wktLiteral')"/]
v14 --o bind5
bind5 --as--o v15