Sign up ×
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 wrote a very simple python function that gives me the envelope/bounding box/...based on two coordinate pairs (ower left and upper right corner):

# ...
def get_bounding_box(self, ll_corner, ur_corner):
        from shapely.geometry import MultiPoint
        mp_env = MultiPoint([ll_corner, ur_corner]).envelope
        return ogr.CreateGeometryFromWkt( mp_env.to_wkt() )

print mp_env
POLYGON ((4.8439699999999997 52.3661099999999990, 4.8469199999999999 52.3661099999999990, 4.8469199999999999 52.3706000000000031, 4.8439699999999997 52.3706000000000031, 4.8439699999999997 52.3661099999999990))

As you can see I'm returning an ogr geometry which I use, for instance, in this manner:

bbox = geo.get_bounding_box(lowerleft,upper_right) 
if p.Within(bbox):

Isn't there an equivalent function to shapely's envelope in ogr? Both .ConvexHull() and GetEnvelope() return only the two corner coordinate pairs.

share|improve this question

1 Answer 1

up vote 5 down vote accepted

The Ogr function GetEnvelope() returns "a tuple (minX, maxX, minY, maxY)" (from here), but what you want (from what I can understand) is a Polygon describing the envelope/bbox?

This is actually rather simple, as the tuple (minX, maxX, minY, maxY) is all you need to create a Polygon.

Just create a Polygon based these, like so:

from osgeo import ogr

def my_envelope(geom):
   (minX, maxX, minY, maxY) = geom.GetEnvelope()

    # Create ring
    ring = ogr.Geometry(ogr.wkbLinearRing)
    ring.AddPoint(minX, minY)
    ring.AddPoint(maxX, minY)
    ring.AddPoint(maxX, maxY)
    ring.AddPoint(minX, maxY)
    ring.AddPoint(minX, minY)

    # Create polygon
    poly_envelope = ogr.Geometry(ogr.wkbPolygon)
    return poly_envelope
share|improve this answer
Thanks for your answer. So to makes things clear: there is no ogr build-in function that does this? – LarsVegas Mar 19 '14 at 14:12
I don't think so – radouxju Mar 19 '14 at 14:16

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.