Last active
April 4, 2020 04:23
-
-
Save santileortiz/2c9ddf52363fa92ae3ff6f251cd417fe to your computer and use it in GitHub Desktop.
Wikidata query that returns country coordinates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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