query-6d3c80fd6d1ead9fd0d409b6645d4c34

rq turtle/ttl

title:Pairs of churches in Lithuania that are within 25 metres of each other SELECT ?church ?churchLabel ?churchloc ?dist ?other ?otherLabel WHERE { ?church wdt:P31 wd:Q16970 . # this thing is a church ?church wdt:P17 wd:Q37 . # and it's in the UK ?church wdt:P625 ?churchloc . # and it has a location ?other wdt:P31 wd:Q16970 . # another thing is also a church SERVICE wikibase:around { ?other wdt:P625 ?otherloc . bd:serviceParam wikibase:center ?churchloc . bd:serviceParam wikibase:radius "0.025" . # and is pretty much exactly on the same spot (±25m) } FILTER (STR(?church) > STR(?other)) # filter so each pair only shows up once SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" } BIND(geof:distance(?churchloc, ?otherloc) as ?dist)
} ORDER BY ?dist

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 bd: <http://www.bigdata.com/rdf#>
#title:Pairs of churches in Lithuania that are within 25 metres of each other
SELECT ?church ?churchLabel ?churchloc ?dist ?other ?otherLabel
WHERE
{
  ?church wdt:P31 wd:Q16970 .                           # this thing is a church
  ?church wdt:P17 wd:Q37 .                             # and it's in the UK
  ?church wdt:P625 ?churchloc .                         # and it has a location
  ?other wdt:P31 wd:Q16970 .                            # another thing is also a church
  SERVICE wikibase:around {
      ?other wdt:P625 ?otherloc .
      bd:serviceParam wikibase:center ?churchloc .
      bd:serviceParam wikibase:radius "0.025" .          # and is pretty much exactly on the same spot (±25m)
  } 
  FILTER (STR(?church) > STR(?other))                   # filter so each pair only shows up once
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
  BIND(geof:distance(?churchloc, ?otherloc) as ?dist)         
}
ORDER BY ?dist

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v2("?church"):::projected v4("?churchloc"):::projected v6("?dist"):::projected v3("?other"):::projected v5("?otherloc") c4(["wd:Q37"]):::iri c10(["0.025"]):::literal c7(["bd:serviceParam"]):::iri c13(["#91;AUTO_LANGUAGE#93;,en"]):::literal c2(["wd:Q16970"]):::iri f0[["str(?church) > str(?other)"]] f0 --> v2 f0 --> v3 v2 --"wdt:P31"--> c2 v2 --"wdt:P17"--> c4 v2 --"wdt:P625"--> v4 v3 --"wdt:P31"--> c2 subgraph s1["http://wikiba.se/ontology#around"] style s1 stroke-width:4px; v3 --"wdt:P625"--> v5 c7 --"wikibase:center"--> v4 c7 --"wikibase:radius"--> c10 end subgraph s2["http://wikiba.se/ontology#label"] style s2 stroke-width:4px; c7 --"wikibase:language"--> c13 end bind1[/"http://www.opengis.net/def/function/geosparql/distance(?churchloc,?otherloc)"/] v4 --o bind1 v5 --o bind1 bind1 --as--o v6