query-380cf5ba5c878a98f98bf4b013d39c17

rq turtle/ttl

Propertiesinstance of (P31)subclass of (P279)coordinate location (P625)

Use at

PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX prov: <http://www.w3.org/ns/prov#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
SELECT ?gemeinde ?coords1 ?coords2 ?distance (COUNT(DISTINCT ?coords1Reference) AS ?coords1References) (COUNT(DISTINCT ?coords2Reference) AS ?coords2References) 
WHERE {
  ?gemeinde wdt:P31/wdt:P279* wd:Q262166;
            p:P625 ?coords1Statement, ?coords2Statement.
  FILTER(?coords1Statement != ?coords2Statement)
  FILTER(STR(?coords1Statement) < STR(?coords2Statement))
  ?coords1Statement ps:P625 ?coords1.
  OPTIONAL { ?coords1Statement prov:wasDerivedFrom ?coords1Reference. }
  ?coords2Statement ps:P625 ?coords2.
  OPTIONAL { ?coords2Statement prov:wasDerivedFrom ?coords2Reference. }
  BIND(geof:distance(?coords1, ?coords2) AS ?distance)
}
GROUP BY ?gemeinde ?coords1 ?coords2 ?distance
ORDER BY ASC(?distance) ASC(?coords1References + ?coords2References)

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v7("?coords1"):::projected v8("?coords1Reference"):::projected v11("?coords1References") v4("?coords1Statement") v9("?coords2"):::projected v10("?coords2Reference"):::projected v11("?coords2References") v5("?coords2Statement") v11("?distance"):::projected v6("?gemeinde"):::projected a1((" ")) c3(["wd:Q262166"]):::iri f0[["str(?coords1Statement) < str(?coords2Statement)"]] f0 --> v4 f0 --> v5 f1[["?coords1Statement != ?coords2Statement"]] f1 --> v4 f1 --> v5 v6 --"p:direct/P31"--> a1 a1 --"p:direct/P279"--> c3 v6 --"p:P625"--> v4 v6 --"p:P625"--> v5 v4 --"p:statement/P625"--> v7 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v4 -."prov:wasDerivedFrom".-> v8 end v5 --"p:statement/P625"--> v9 subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v5 -."prov:wasDerivedFrom".-> v10 end bind2[/"http://www.opengis.net/def/function/geosparql/distance(?coords1,?coords2)"/] v7 --o bind2 v9 --o bind2 bind2 --as--o v11 bind5[/"count(?coords1Reference)"/] v8 --o bind5 bind5 --as--o v11 bind6[/"count(?coords2Reference)"/] v10 --o bind6 bind6 --as--o v11