This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

Query for all cities in Arab world with Sophox

0

I've just discovered this new Sophox API.

I would to get all cities (place=city) in the Arab World. I assume that it would be much easier to query for this using Wikidata than filtering the global dump.

The arab countries have the following Wikidata IDs: Q79 Q262 Q1049 Q796 Q1028 Q851 Q805 Q858 Q1045 Q948 Q878 Q810 Q1016 Q1176995 Q822 Q842 Q817 Q1025 Q846 Q398 Q977 Q970

Is this possible and how would it look like? Thanks in advance.

asked 03 Jul '18, 20:14

Nehaj's gravatar image

Nehaj
31558
accept rate: 0%

updated my reply with an example

(28 Nov '18, 18:58) nyuriks

One Answer:

1

Nehaj, updating my reply. Sophox is back up. Here's a sample query, but unfortunately it is very slow - I suspect it needs some federated query optimizations:

PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>

SELECT * WHERE {
  VALUES ?countries { wd:Q79 wd:Q262 wd:Q1049 wd:Q796 wd:Q1028 wd:Q851 wd:Q805 wd:Q858 wd:Q1045 wd:Q948 wd:Q878 wd:Q810 wd:Q1016 wd:Q1176995 wd:Q822 wd:Q842 wd:Q817 wd:Q1025 wd:Q846 wd:Q398 wd:Q977 wd:Q970 }

  ?osmid osmt:place "city" ;
         osmt:wikidata ?wd .

  SERVICE <https://query.wikidata.org/sparql> {
    ?wd wdt:P17 ?countries .
  }

} limit 10

answered 05 Jul '18, 07:26

nyuriks's gravatar image

nyuriks
71226
accept rate: 0%

edited 28 Nov '18, 18:56

Source code available on GitHub .