query-e3a30303d103a9271d98c7609ebb5908
Query Airports with Coordinates, IATA Code, and Location ServedHi y'all! I'm working on updating an app that uses IATA codes to identify datacenters. The trouble is, as far as I can tell, there aren't any datasets that quite match exactly what I need, which is: )Point(-122.375 37.618888888)The Geographic Coordinates of the Airport( )San Francisco, California, USAThe Place said airport serves/is in( )SFOThe IATA code of an airport(or if they do, they don't cover all of the airports I need. Then I noticed that Wikidata has this exact data readily available. The trouble is, I'm not exactly sure how to access it. ]):California I first tried selecting everything manually(the following query is slightly adjusted to only retrieve the highest "region" available, which should be the state[
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT ?airport ?cityLabel ?countryLabel ?iataCode ?coordinates ?regionLabel WHERE {
?airport wdt:P31 wd:Q1248784;
wdt:P131 ?city;
wdt:P17 ?country;
wdt:P625 ?coordinates;
wdt:P239 ?iataCode.
{
SELECT ?city (MAX(?adminDivision) AS ?region) WHERE {
?city wdt:P131 ?adminDivision.
FILTER(?adminDivision != ?country)
}
GROUP BY ?city
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}