Skip to content

Instantly share code, notes, and snippets.

@santileortiz
Last active April 4, 2020 04:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save santileortiz/2c9ddf52363fa92ae3ff6f251cd417fe to your computer and use it in GitHub Desktop.
Save santileortiz/2c9ddf52363fa92ae3ff6f251cd417fe to your computer and use it in GitHub Desktop.
Wikidata query that returns country coordinates
SELECT ?code ?countryLabel ?coordinates WHERE
{
?country wdt:P31 wd:Q3624078 ;
p:P625 ?location .
#not a former country
FILTER NOT EXISTS {?country wdt:P31 wd:Q3024240}
#and no an ancient civilisation (needed to exclude ancient Egypt)
FILTER NOT EXISTS {?country wdt:P31 wd:Q28171280}
# This doesn't bring all countries. It misses Armenia for example.
#?country wdt:P31 wd:Q6256 ;
# p:P625 ?location .
?country wdt:P298 ?code .
BIND (
CONCAT(
IF(?latitude < 0, CONCAT(STR(-ROUND(?latitude*100)/100),"S "), CONCAT(STR(ROUND(?latitude*100)/100),"N ")),
IF(?longitude < 0, CONCAT(STR(-ROUND(?longitude*100)/100),"E"), CONCAT(STR(ROUND(?longitude*100)/100),"W"))
) AS ?coordinates)
?location psv:P625 ?coordinate_node .
?coordinate_node wikibase:geoLatitude ?latitude .
?coordinate_node wikibase:geoLongitude ?longitude .
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment