Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was looking in Fiona to get for each feature its extent but I didn't find how.

I have try to far to do something like below

import fiona

with'countries/ne_10m_admin_0_countries.shp', 'r') as source:
    for f in source:
        geom = f['geometry']
        print geom

I was expecting to get a method for this at the f variable level. After some documentation reading, I've seen that f is a pure python record. So at the end, how with Fiona can I get the extent (or bounding box) of each feature geometry?

PS: I already know the pure GDAL/OGR python solution so I expect a Fiona solution please

share|improve this question
I would be really interested in seeing the OGR python solution. I'm going through the documentation, and it looks like extents for layers and features are handled differently in OGR. – midfield99 Apr 16 '14 at 0:22
up vote 6 down vote accepted

I'd do it like this:

def explode(coords):
    """Explode a GeoJSON geometry's coordinates object and yield coordinate tuples.
    As long as the input is conforming, the type of the geometry doesn't matter."""
    for e in coords:
        if isinstance(e, (float, int, long)):
            yield coords
            for f in explode(e):
                yield f

def bbox(f):
    x, y = zip(*list(explode(f['geometry']['coordinates'])))
    return min(x), min(y), max(x), max(y)
share|improve this answer
Just in case it's not obvious: the approach above works for deserialized GeoJSON generally and isn't limited to use with Fiona. – sgillies Mar 23 '14 at 15:33
+1, this is brilliantly efficient. – crmackey Apr 1 at 18:34
I made a slight change to use ESRI's json and this solved one of my problems as well. Thanks! – CMPalmer Apr 3 at 18:40

You need to use the function shape of Shapely:

from shapely.geometry import shape
c ="ne_10m_admin_0_countries.shp")
# first record
country =
print "country name :",country['properties']['NAME']
country name : Aruba
# shape(country['geometry']) -> shapely geometry
print "bounds:", shape(country['geometry']).bounds
bounds: (-70.062408006999874, 12.417669989000046, -69.876820441999939, 12.632147528000104)
share|improve this answer
I've accepted @sgillies answer because no lib dependency but I appreciate also your answer. Thanks – ThomasG77 Mar 23 '14 at 11:07

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.