4

With this query, I can get a list of German cities around Berlin, within a radius of 50 km.

SELECT ?place ?placeLabel ?location WHERE
{
  wd:Q64 wdt:P625 ?arcLoc . 
  ?place wdt:P31 wd:Q515 .
  ?place wdt:P17 wd:Q183 .
  SERVICE wikibase:around { 
      ?place wdt:P625 ?location . 
      bd:serviceParam wikibase:center ?arcLoc . 
      bd:serviceParam wikibase:radius "50" . 
  } 
  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" . 
  }
}

How can I sort the result by proximity in Km, like it is done in this page?

4
SELECT ?place ?placeLabel ?location ?distance WHERE
    {
      wd:Q64 wdt:P625 ?arcLoc . 
      ?place wdt:P31 wd:Q515 .
      ?place wdt:P17 wd:Q183 .
      SERVICE wikibase:around { 
          ?place wdt:P625 ?location . 
          bd:serviceParam wikibase:center ?arcLoc . 
          bd:serviceParam wikibase:radius "50" . 
      } 
      SERVICE wikibase:label {
        bd:serviceParam wikibase:language "en" . 
      }
      BIND(geof:distance(?arcLoc, ?location) AS ?distance) 
    } ORDER BY ASC(?distance)

Try it!


P.S. geof: is for <http://www.opengis.net/def/geosparql/function/>.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.