Skip to content

Instantly share code, notes, and snippets.

@StellarStoic
Created December 10, 2023 18:27
Show Gist options
  • Save StellarStoic/76fb9fcc8710f637f3fc308adaad85e1 to your computer and use it in GitHub Desktop.
Save StellarStoic/76fb9fcc8710f637f3fc308adaad85e1 to your computer and use it in GitHub Desktop.
airport SPARQL query
SELECT
?airportName ?pageBanner ?logo ?icao ?iata ?faa ?website ?operator ?opening ?status ?elevation ?elevationUnitLabel ?image
?runway ?runwayLabel ?lengthValue ?lengthUnitLabel ?widthValue ?widthUnitLabel ?materialLabel
WHERE {
BIND(wd:Q8685 AS ?airport) # JFK International Airport's Wikidata ID
# Fetching general airport information
OPTIONAL { ?airport wdt:P373 ?airportName. }
OPTIONAL { ?airport wdt:P948 ?pageBanner. }
OPTIONAL { ?airport wdt:P154 ?logo. }
OPTIONAL { ?airport wdt:P239 ?icao. }
OPTIONAL { ?airport wdt:P238 ?iata. }
OPTIONAL { ?airport wdt:P240 ?faa. }
OPTIONAL { ?airport wdt:P856 ?website. }
OPTIONAL { ?airport wdt:P137 ?operator. }
OPTIONAL { ?airport wdt:P571 ?opening. }
OPTIONAL { ?airport wdt:P5817 ?status. }
# the elevationUnitLabel has been retreived successfully
OPTIONAL {
?airport p:P2044 ?elevationStatement.
?elevationStatement psv:P2044 ?elevationValueNode.
?elevationValueNode wikibase:quantityAmount ?elevation.
OPTIONAL {
?elevationValueNode wikibase:quantityUnit ?elevationUnit.
?elevationUnit rdfs:label ?elevationUnitLabel FILTER(LANG(?elevationUnitLabel) = "en")
}
}
OPTIONAL { ?airport wdt:P18 ?image. }
# Fetching runway specific information
OPTIONAL {
?airport p:P529 ?runwayStatement.
?runwayStatement ps:P529 ?runway.
# Accessing the runway label
OPTIONAL {
?runway wdt:P1813 ?runwayLabel.
}
# Accessing the length qualifier
OPTIONAL {
?runwayStatement pq:P2043 ?lengthValue.
}
# Accessing the width qualifier
OPTIONAL {
?runwayStatement pq:P2049 ?widthValue.
}
# Accessing the material qualifier
OPTIONAL {
?runwayStatement pq:P186 ?material.
OPTIONAL { ?material rdfs:label ?materialLabel FILTER(LANG(?materialLabel) = "en") }
}
}
}
@StellarStoic
Copy link
Author

StellarStoic commented Dec 10, 2023

Answer #1 with original units

SELECT
    ?airportName ?pageBanner ?logo ?icao ?iata ?faa ?website ?operator ?opening ?status ?elevation ?elevationUnitLabel ?image
    ?runway ?lengthValue ?lengthUnitLabel ?widthValue ?widthUnitLabel ?materialLabel
WHERE {
    BIND(wd:Q8685 AS ?airport)  # JFK International Airport's Wikidata ID
    # Fetching general airport information
    OPTIONAL { ?airport wdt:P373 ?airportName. }
    OPTIONAL { ?airport wdt:P948 ?pageBanner. }
    OPTIONAL { ?airport wdt:P154 ?logo. }
    OPTIONAL { ?airport wdt:P239 ?icao. }
    OPTIONAL { ?airport wdt:P238 ?iata. }
    OPTIONAL { ?airport wdt:P240 ?faa. }
    OPTIONAL { ?airport wdt:P856 ?website. }
    OPTIONAL { ?airport wdt:P137 ?operator. }
    OPTIONAL { ?airport wdt:P571 ?opening. }
    OPTIONAL { ?airport wdt:P5817 ?status. }
    OPTIONAL {
        ?airport p:P2044 ?elevationStatement.
        ?elevationStatement psv:P2044 ?elevationValueNode.
        ?elevationValueNode wikibase:quantityAmount ?elevation.
        OPTIONAL {
            ?elevationValueNode wikibase:quantityUnit ?elevationUnit.
            ?elevationUnit rdfs:label ?elevationUnitLabel FILTER(LANG(?elevationUnitLabel) = "en")
        }
    }
    OPTIONAL { ?airport wdt:P18 ?image. }
    # Fetching runway specific information
    OPTIONAL {
        ?airport p:P529 ?runwayStatement.
        ?runwayStatement ps:P529 ?runway.
        # Accessing the length qualifier
        OPTIONAL {
            ?runwayStatement pqv:P2043 ?lengthNode.
            ?lengthNode wikibase:quantityAmount ?lengthValue.
            ?lengthNode wikibase:quantityUnit ?lengthUnit.
        }
        # Accessing the width qualifier
        OPTIONAL {
            ?runwayStatement pqv:P2049 ?widthNode.
            ?widthNode wikibase:quantityAmount ?widthValue.
            ?widthNode wikibase:quantityUnit ?widthUnit.
        }
        # Accessing the material qualifier
        OPTIONAL {
            ?runwayStatement pq:P186 ?material.
            OPTIONAL { ?material rdfs:label ?materialLabel FILTER(LANG(?materialLabel) = "en") }
        }
    }
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } 
}

@StellarStoic
Copy link
Author

StellarStoic commented Dec 10, 2023

Answer #2 with original unit converted into meters

SELECT
    ?airportName ?pageBanner ?logo ?icao ?iata ?faa ?website ?operator ?opening ?status ?elevation ?elevationUnitLabel ?image
    ?runway ?lengthValue ?lengthUnitLabel ?widthValue ?widthUnitLabel ?materialLabel
WHERE {
    BIND(wd:Q8685 AS ?airport)  # JFK International Airport's Wikidata ID
    # Fetching general airport information
    OPTIONAL { ?airport wdt:P373 ?airportName. }
    OPTIONAL { ?airport wdt:P948 ?pageBanner. }
    OPTIONAL { ?airport wdt:P154 ?logo. }
    OPTIONAL { ?airport wdt:P239 ?icao. }
    OPTIONAL { ?airport wdt:P238 ?iata. }
    OPTIONAL { ?airport wdt:P240 ?faa. }
    OPTIONAL { ?airport wdt:P856 ?website. }
    OPTIONAL { ?airport wdt:P137 ?operator. }
    OPTIONAL { ?airport wdt:P571 ?opening. }
    OPTIONAL { ?airport wdt:P5817 ?status. }
    OPTIONAL {
        ?airport p:P2044 ?elevationStatement.
        ?elevationStatement psn:P2044 ?elevationValueNode.
        ?elevationValueNode wikibase:quantityAmount ?elevation.
        OPTIONAL {
            ?elevationValueNode wikibase:quantityUnit ?elevationUnit.
            ?elevationUnit rdfs:label ?elevationUnitLabel FILTER(LANG(?elevationUnitLabel) = "en")
        }
    }
    OPTIONAL { ?airport wdt:P18 ?image. }
    # Fetching runway specific information
    OPTIONAL {
        ?airport p:P529 ?runwayStatement.
        ?runwayStatement ps:P529 ?runway.
        # Accessing the length qualifier
        OPTIONAL {
            ?runwayStatement pqn:P2043 ?lengthNode.
            ?lengthNode wikibase:quantityAmount ?lengthValue.
            ?lengthNode wikibase:quantityUnit ?lengthUnit.
        }
        # Accessing the width qualifier
        OPTIONAL {
            ?runwayStatement pqn:P2049 ?widthNode.
            ?widthNode wikibase:quantityAmount ?widthValue.
            ?widthNode wikibase:quantityUnit ?widthUnit.
        }
        # Accessing the material qualifier
        OPTIONAL {
            ?runwayStatement pq:P186 ?material.
            OPTIONAL { ?material rdfs:label ?materialLabel FILTER(LANG(?materialLabel) = "en") }
        }
    }
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } 
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment