-->

Get WikiData Identifier for city by GPS location

2020-04-16 19:55发布

问题:

I want to get the city /settlement at a specific gps location. meaning the closest one in a given range or at best the closest.

i found some example queries in the wikimedia data examples.

I try to adopt then but i get only errors or timeouts

here is my current query:

 SELECT *
    WHERE
    {
      ?city wdt:P31/wdt:P279* wd:Q15642541 . // only settlements
       # Search by Nearest
  SERVICE wikibase:around { 
    ?place wdt:P625 ?location . 
    bd:serviceParam wikibase:center "Point(8.4024875340491 48.9993762209831)"^^geo:wktLiteral .
    bd:serviceParam wikibase:radius "1" . 
    bd:serviceParam wikibase:distance ?distance .
  }
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
    } 
ORDER By ?distance

The query works when i left out the settlement condition. Butwhen i add it the query takes too long What am I doing wrong? Whats the correct syntax?

回答1:

I Found my bug.

here is the working query:

 SELECT DISTINCT *
    WHERE
    {
      ?place wdt:P31/wdt:P279* wd:Q515 .
       # Search by Nearest
  SERVICE wikibase:around { 
    ?place wdt:P625 ?location . 
    bd:serviceParam wikibase:center "Point(8.4024875340491 48.9993762209831)"^^geo:wktLiteral .
    bd:serviceParam wikibase:radius "10" . 
    bd:serviceParam wikibase:distance ?distance .
  }
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
    } 

Order by  ?distance