query-c6c799aa578bb6349e37409f1ba75d59
Jheald
Use at
- https://query.wikidata.org/sparql
PREFIX mwapi: <http://wikiba.se/ontology#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX schema: <http://schema.org/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX pr: <http://www.wikidata.org/prop/reference/>
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#>
SELECT ?item ?title ?wd_coord ?wiki_coord ?dist
{
{
SELECT DISTINCT ?item
{
?item wdt:P31 / wdt:P279 * wd:Q55488 .
?item wdt:P17 wd:Q145 .
FILTER STRENDS(STR(?item), "0")
}
} ?item p:P625 ?s .
?s ps:P625 ?wd_coord .
?s prov:wasDerivedFrom ?ref .
?ref pr:P143 wd:Q328 .
?sitelink schema:about ?item .
?sitelink schema:isPartOf <https://en.wikipedia.org/> .
?sitelink schema:name ?title .
SERVICE wikibase:mwapi
{
bd:serviceParam wikibase:endpoint "en.wikipedia.org" .
bd:serviceParam wikibase:api "Generator" .
bd:serviceParam mwapi:generator "allpages" .
bd:serviceParam mwapi:gapfrom ?title .
bd:serviceParam mwapi:gapto ?title .
bd:serviceParam mwapi:prop "coordinates" .
?lat wikibase:apiOutput "coordinates/co/@lat" .
?lon wikibase:apiOutput "coordinates/co/@lon" .
}
BIND (STRDT(CONCAT("Point(", ?lon, " ", ?lat, ")"), geo:wktLiteral) AS ?wiki_coord)
BIND (geof:distance(?wd_coord, ?wiki_coord) AS ?dist)
FILTER (! BOUND(?dist) || ?dist > 0.0)
}
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v11("?dist"):::projected
v2("?item"):::projected
v8("?lat")
v9("?lon")
v5("?ref")
v3("?s")
v6("?sitelink")
v7("?title"):::projected
v4("?wd_coord"):::projected
v10("?wiki_coord"):::projected
a1((" "))
c15([https://en.wikipedia.org/]):::iri
c20(["en.wikipedia.org"]):::literal
c18(["bd:serviceParam"]):::iri
c24(["allpages"]):::literal
c31(["coordinates/co/@lon"]):::literal
c5(["wd:Q55488"]):::iri
c28(["coordinates"]):::literal
c30(["coordinates/co/@lat"]):::literal
c12(["wd:Q328"]):::iri
c7(["wd:Q145"]):::iri
c22(["Generator"]):::literal
f0[["(not bound(?dist) || ?dist > '0.0^^xsd:decimal')"]]
f0 --> v11
f1[["ends-with(str(?item),'0')"]]
f1 --> v2
v2 --"p:direct/P31"--> a1
a1 --"p:direct/P279"--> c5
v2 --"p:direct/P17"--> c7
v2 --"p:P625"--> v3
v3 --"p:statement/P625"--> v4
v3 --"prov:wasDerivedFrom"--> v5
v5 --"p:reference/P143"--> c12
v6 --"schema:about"--> v2
v6 --"schema:isPartOf"--> c15
v6 --"schema:name"--> v7
subgraph s1["http://wikiba.se/ontology#mwapi"]
style s1 stroke-width:4px;
c18 --"mwapi:endpoint"--> c20
c18 --"mwapi:api"--> c22
c18 --"mwapi:generator"--> c24
c18 --"mwapi:gapfrom"--> v7
c18 --"mwapi:gapto"--> v7
c18 --"mwapi:prop"--> c28
v8 --"mwapi:apiOutput"--> c30
v9 --"mwapi:apiOutput"--> c31
end
bind2[/"STRDT(concat('Point(',?lon,' ',?lat,')'),'geo:wktLiteral')"/]
v9 --o bind2
v8 --o bind2
bind2 --as--o v10
bind3[/"http://www.opengis.net/def/function/geosparql/distance(?wd_coord,?wiki_coord)"/]
v4 --o bind3
v10 --o bind3
bind3 --as--o v11