Search code examples
sparqlrdfowldbpedia

How can I join climate data to cities with dbpedia?


I am trying to get a dataset that gives me all the data available in a city's climate table but I'm having some trouble.

I was able to get this to work and felt pretty good about myself. When I plug this in on dbpedia's virtuoso client this gives me all the cities that dbpedia has, and all of their countries.

PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?city_name ?country
WHERE { ?city rdf:type dbpedia-owl:City ; 
          rdfs:label ?city_name; 
          dbpedia-owl:country ?country 
   FILTER (langMatches(lang(?city_name), "EN")) .
}

Update: I have found properties that seem to give what I'm looking for (e.g. dbpedia.org/property/aprHighC) but I'm having trouble adding them to my output.

PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?city_name ?country ?aprHighC
WHERE { ?city rdf:type dbpedia-owl:City .
    ?city rdfs:label ?city_name .
    ?city dbpedia-owl:country ?country 
FILTER (langMatches(lang(?city_name), "EN")) .
}

Gives an error: Variable 'aprHighC' is used in the query result set but not assigned. How do I assign it?


Solution

  • The following query gives the January average daily high (°C). Adding other climate items is as simple as copying the line beginning "OPTIONAL" and changing the item and variable name from janHighC to whatever you are trying to get.

    PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
    SELECT * {
    { ?city rdf:type dbo:City .
     ?city rdf:type schema:City .
     ?city rdfs:label ?name
    }
    OPTIONAL {?city dbp:janHighC ?janHighC .}
    }
    

    I will note, however, that most cities don't have this information. I had to give up on getting the data this way.