query-cf37ce418980be9abc0ed117832239e8

rq turtle/ttl

Improve sorting of coordinates 21:51, 27 June 2019 (UTC)) talk (Bouzinac has the behaviour to sort numbers alphabetically. Is there a way to improve the sorting, so that really close elements are together ? ORDER BY ?coordHello This query has to export all airports that are in the USA. Sadly, there are many duplicates. I'd like to improve the sort of this query (that would help find duplicates) The current

Use at

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 ps: <http://www.wikidata.org/prop/statement/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX geof: <http://www.opengis.net/def/function/geosparql/>
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX wdno: <http://www.wikidata.org/prop/novalue/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT DISTINCT ?locLabel ?airport ?airportLabel ?coord ?long ?lat ?ICAO ?IATA ?Local_Code ?dist
{
  {
  SELECT DISTINCT ?loc ?airport (SAMPLE(?_coord) AS ?coord) (SAMPLE(?_long) AS ?long) (SAMPLE(?_lat) AS ?lat) ?ICAO ?IATA (SAMPLE(?Local_Code) AS ?Local_Code)
  {
    ?airport wdt:P31/(wdt:P279*) wd:Q62447;
      wdt:P17 wd:Q30.
    MINUS { ?airport wdt:P576 _:b2. }
    MINUS { ?airport wdt:P582 _:b3. }
    MINUS { ?airport wdt:P31/(wdt:P279*) wd:Q1311670. }
    MINUS { ?airport wdt:P31/(wdt:P279*) wd:Q7373622. }
    MINUS { ?airport wdt:P31/(wdt:P279*) wd:Q2265915. }
    MINUS { ?airport wdt:P31/(wdt:P279*) wd:Q44665966. }
    MINUS { ?airport wdt:P31/(wdt:P279*) wd:Q782667. }
    MINUS { ?airport rdf:type wdno:P17. }
    OPTIONAL {
      ?airport p:P625 [
        a wikibase:BestRank; ps:P625 ?_coord;
        psv:P625 [ wikibase:geoLongitude ?_long; wikibase:geoLatitude ?_lat ]
      ] .
    } .
    OPTIONAL { ?airport wdt:P239 ?ICAO. }
    OPTIONAL { ?airport wdt:P238 ?IATA. }
    OPTIONAL { ?airport wdt:P240 ?Local_Code. }
    OPTIONAL {
      ?airport wdt:P131* ?loc.
      ?loc wdt:P31 ?type.
      ?type (wdt:P279*) wd:Q35657.
    } .
  } GROUP BY ?loc ?airport ?ICAO ?IATA
  } .
  wd:Q934 wdt:P625 ?pole .
  BIND( geof:distance( ?pole, ?coord ) AS ?dist ) .
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en,fr,[AUTO_LANGUAGE]". }
}
ORDER BY ?dist
#ORDER BY ?long ?lat

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v7("?IATA"):::projected v6("?ICAO"):::projected v14("?Local_Code"):::projected v3("?_coord") v5("?_lat") v4("?_long") v2("?airport"):::projected v11("?coord"):::projected v15("?dist"):::projected v13("?lat"):::projected v9("?loc") v12("?long"):::projected v14("?pole") v10("?type") a2((" ")) a3((" ")) a1((" ")) a4((" ")) a5((" ")) a6((" ")) a7((" ")) a8((" ")) a9((" ")) a10((" ")) c9(["wd:Q7373622"]):::iri c10(["wd:Q2265915"]):::iri c5(["wd:Q30"]):::iri c14(["p:novalue/P17"]):::iri c3(["wd:Q62447"]):::iri c29(["bd:serviceParam"]):::iri c26(["wd:Q934"]):::iri c8(["wd:Q1311670"]):::iri c31(["en,fr,#91;AUTO_LANGUAGE#93;"]):::literal c25(["wd:Q35657"]):::iri c12(["wd:Q782667"]):::iri c15(["wikibase:BestRank"]):::iri c11(["wd:Q44665966"]):::iri v2 --"p:direct/P31"--> a1 a1 --"p:direct/P279"--> c3 v2 --"p:direct/P17"--> c5 subgraph minus0["MINUS"] style minus0 stroke-width:6px,fill:pink,stroke:red; v2 --"p:direct/P576"--> a2 end subgraph minus1["MINUS"] style minus1 stroke-width:6px,fill:pink,stroke:red; v2 --"p:direct/P582"--> a3 end subgraph minus2["MINUS"] style minus2 stroke-width:6px,fill:pink,stroke:red; v2 --"p:direct/P31"--> a4 a4 --"p:direct/P279"--> c8 end subgraph minus3["MINUS"] style minus3 stroke-width:6px,fill:pink,stroke:red; v2 --"p:direct/P31"--> a5 a5 --"p:direct/P279"--> c9 end subgraph minus4["MINUS"] style minus4 stroke-width:6px,fill:pink,stroke:red; v2 --"p:direct/P31"--> a6 a6 --"p:direct/P279"--> c10 end subgraph minus5["MINUS"] style minus5 stroke-width:6px,fill:pink,stroke:red; v2 --"p:direct/P31"--> a7 a7 --"p:direct/P279"--> c11 end subgraph minus6["MINUS"] style minus6 stroke-width:6px,fill:pink,stroke:red; v2 --"p:direct/P31"--> a8 a8 --"p:direct/P279"--> c12 end subgraph minus7["MINUS"] style minus7 stroke-width:6px,fill:pink,stroke:red; v2 --"a"--> c14 end subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; a9 -."a".-> c15 a9 --"p:statement/P625"--> v3 a10 --"wikibase:geoLongitude"--> v4 a10 --"wikibase:geoLatitude"--> v5 a9 --"p:statement/value/P625"--> a10 v2 --"p:P625"--> a9 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:direct/P239".-> v6 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:direct/P238".-> v7 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:direct/P240".-> v14 end subgraph optional4["(optional)"] style optional4 fill:#bbf,stroke-dasharray: 5 5; v2 -."p:direct/P131".-> v9 v9 --"p:direct/P31"--> v10 v10 --"p:direct/P279"--> c25 end bind12[/"sample(?_coord)"/] v3 --o bind12 bind12 --as--o v11 bind13[/"sample(?_long)"/] v4 --o bind13 bind13 --as--o v12 bind14[/"sample(?_lat)"/] v5 --o bind14 bind14 --as--o v13 bind15[/"sample(?Local_Code)"/] v14 --o bind15 bind15 --as--o v14 c26 --"p:direct/P625"--> v14 bind16[/"http://www.opengis.net/def/function/geosparql/distance(?pole,?coord)"/] v14 --o bind16 v11 --o bind16 bind16 --as--o v15 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c29 --"wikibase:language"--> c31 end