Is There an Envelope Class in Shapely?

I found the envelope class in Java's JTS library very handy. An envelope holds the minimal and maximal coordinates of a geometry and is also called bounding box sometimes.

I wanted to get the common envelope of a number of shapely points. In JTS you could call expandToInclude to enlarge the envelope point by point.

As JTS was serving as a blueprint to GEOS / shapely, I was expecting something similar in shapely, but could not find it (I am new to the library though). I know it is no rocket science to do it yourself, but I doubt there is no more elegant way to do this. Do you have any idea?

3 Answers

To create simple box geometries, there is a box function that returns a rectangular polygon:

from shapely.geometry import box
# box(minx, miny, maxx, maxy, ccw=True)
b = box(2, 30, 5, 33)
b.wkt  # POLYGON ((5 30, 5 33, 2 33, 2 30, 5 30))
b.area  # 9.0

No, there's no envelope class in Shapely, which relies on (minx, miny, maxx, maxy) tuples. If you wanted to program in the same JTS style, it would be trivial to write an envelope class wrapping such a tuple.

Another option:

from shapely.geometry import MultiPoint
print MultiPoint(points).bounds
0

For anyone coming here, shapely Polygon has now bounds which I believe is equivalent to JTS envelop. Following is the documentation from official page

from shapely.geometry import Polygon
polygon = Polygon([(0, 0), (1, 1), (1, 0)])
polygon.bounds
(0.0, 0.0, 1.0, 1.0)

Its x-y bounding box is a (minx, miny, maxx, maxy) tuple.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest