Query to Retrieve Indian States, Districts, and Cities only Returning Districts

I want to retrieve Indian districts, states, and cities. I have the following query which I think should do that (I’m omitting the prefixes).

CONSTRUCT {?state rdfs:label ?stateLabel ;
            dbo:country dbr:India ;
            geo:lat ?latitude ;
            geo:long ?longitude ;
            dbo:populationTotal ?population;
            dbo:abstract ?abs.
	   ?city rdf:type dbo:City ;
            rdfs:label ?cityLabel ;
            dbo:isPartOf ?state;
		    dbo:abstract ?abs.}
WHERE {{?state rdf:type dbo:State ;
            rdfs:label ?stateLabel ;
            dbo:country dbr:India ;
            geo:lat ?latitude ;
            geo:long ?longitude ;
            dbo:populationTotal ?population;
            dbo:abstract ?abs.
     FILTER (lang(?stateLabel) = "en" && lang(?abs) = "en")}
   UNION
   {?state rdf:type dbo:AdministrativeRegion ;
            rdfs:label ?stateLabel ;
            dbo:country dbr:India ;
            geo:lat ?latitude ;
            geo:long ?longitude ;
            dbo:populationTotal ?population;
            dbo:abstract ?abs .
     FILTER (lang(?stateLabel) = "en" && lang(?abs) = "en")}
   OPTIONAL {?city rdf:type dbo:City ;
           rdfs:label ?cityLabel ;
           dbo:isPartOf ?state;
		   dbo:abstract ?abs.
     FILTER (lang(?cityLabel) = "en" && lang(?abs) = "en")}}
     ORDER BY ?stateLabel

This returns the districts but it doesn’t return any cities or states. I’ve tried smaller parts of this query where I just query for the states or cities and it doesn’t return anything.

Not a direct reply, sorry, but did you consider using Geonames for this?

Yes, I considered Geonames. I understand the concepts of Linked Data and I’ve used SPARQL quite a bit for local OWL ontologies but this is my first attempt to actually use Linked Data so I’m not at all familiar with which sites are best or how to use them. The reason I went with DBpedia is that I want more data than just basic things like lat, long, and population. More than is in that query but I wanted to get that query working first and I thought DBpedia was a better source. Also, I want to eventually dive down to lower levels of granularity than just cities, to towns and villages even districts. If you think Geonames is better I can use that. For some reason I’m having trouble finding documentation on these different sources. Is there a tutorial (or book) on how to use Geonames you would recommend? Based on what I said do you think Geonames is as good or better than DBpedia?

Well GeoNames is simpler to understand the hyerarchy of places. For some countries it goes as granular as single street addresses :slight_smile: then up to countries, continents and finally the EARTH :slight_smile: So to navigate up and down I find it easier. Then with the toponym you can always jump to DBPedia for example to fetch a written description or the history of a place when avilable.
Also bear in mind that the same “place” (eg. Rome) can be several things such as a populated place, the seat of a town administration, the seat of a regional adm and in this specific case (I live there) the capital of Italy’s nation. This is more apparent in Geonames than in DBpedia IMHO.

https://www.geonames.org/ontology/documentation.html

https://www.geonames.org/export/codes.html

http://www.geonames.org/export/web-services.html

You need to register for a free account on Geonames and then can use their REST API

Very good references IMHO