Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

i'm new to OGR processing and KML format so be gentle:

i've got a series of KML files all containing multiple regions partitioning a larger area in each. i also have a series of geocoded points for which i want to ask WITHIN/CONTAINS queries with respect to the regions. two questions:

  • i don't know how to ENUMERATE all the regions/placemarks contained in the file. [UPDATE:] thanks to this hint i guess i can get what i want via a JSON encoding:

    drv = ogr.GetDriverByName('KML')
    inf = 'path/file.kml'
    ds_in = drv.Open(inf)
    featureTbl = {}
    for kml_lyr in ds_in:
        for feat in kml_lyr:
            ftbl = eval(feat.ExportToJson())
            fname = ftbl['properties']['Name']
            geom = ftbl['geometry']
            featureTbl[fname] = geom

but there must be a better/XML-parse-like way to get "child" placemark elements?

  • since i know the point will only be in one of the regions, i wonder if it is worth the effort of first computing region centroids and asking the WITHIN/CONTAINS query of the regions in order of their proximity to the point, rather than just dumbly enumerating all the regions and asking until i get a hit?
share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.