'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?



Solution 1:[1]

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

Solution 2:[2]

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

Solution 3:[3]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sgillies
Solution 2 Mike T
Solution 3