Reputation: 20150
I want to get the Country which contains a latitude and longitude. Currently, I have the query below which works,
SELECT DISTINCT ?lat,?long,?place WHERE {
:Taj_Mahal dbpprop:latitude ?lat .
:Taj_Mahal dbpprop:longitude ?long .
}
Now, how can I get the Country which contains this latitude and longitude using dbpedia?
Upvotes: 0
Views: 467
Reputation: 7485
if you already have the resource (Taj_Mahal) then you can use this query:
SELECT DISTINCT ?lat ?long (str(?place) as ?place) ?country1 ?country2
WHERE {
:Taj_Mahal dbpprop:latitude ?lat .
:Taj_Mahal dbpprop:longitude ?long .
:Taj_Mahal dbpedia2:location ?place .
OPTIONAL {:Taj_Mahal dbpedia2:country ?country1} .
OPTIONAL {:Taj_Mahal dbpedia2:locmapin ?country2} .
}
if you only have lat
and log
, you can use this query:
SELECT DISTINCT str(?what) as ?what str(?place) as ?place ?country1 ?country2
WHERE {
?target dbpprop:latitude 27 .
?target dbpprop:longitude 78 .
?target dbpedia2:location ?place .
?target rdfs:label ?what .
OPTIONAL {?target dbpedia2:country ?country1} .
OPTIONAL {?target dbpedia2:locmapin ?country2} .
FILTER (lang(?what) = 'en')
}
note, however, that this query works if the resource (Taj Mahal in this case) has country
, location
or logmapin
properties set. this is not the case for all places.
Upvotes: 2