Get a Counties List
I need a list of counties of Germany (Landkreise), of France (Arrondissements) and of some other countries. Such lists are in Wikipedia in form of a table, i.e. Liste der Landkreise in Deutschland (no English version available) or List of arrondissements of France.
To extract the table Convert Wiki Tables to CSV works really well. Of course, every country has its special cases, i.e. in Germany there is "Aachen" and "Städteregion Aachen". I manually removed all cities that are part of a larger region for the German Landkreise.
But is there a way to get a better list out of Wikidata? I build a minimal SPARQL query using the query builder:
Which results in this SPARQL query:
SELECT DISTINCT ?item ?itemLabel WHERE { SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". } { SELECT DISTINCT ?item WHERE { ?item p:P31 ?statement0. ?statement0 (ps:P31/(wdt:P279*)) wd:Q106658. } } }
The resulting list of districts has 690 elements which is clearly too many, because Germany currently has 294 rural districts. There are too many because historical districts are in there too, i.e. Borken or Zeitz district (GDR). A lot of them have properties for them being former districts, i.e. "dissolved, abolished or demolished date" or "replaced by", but a SPARQL query to filter all of them feels like too much trouble. Another way to filter would be to download the list of 690 entries and filter with code for the fields that mark former districts.
I will revisit the wikidata-query-and-filtering-with-code idea, if the manually edited wikipedia table extract has too many issues. For now I will keep going with the filtered wikitable extract.