Is there an envelope class in shapely?
Asked Answered
B

4

12

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?

Brazee answered 20/11, 2013 at 11:12 Comment(0)
R
8

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
Rawson answered 20/11, 2013 at 15:57 Comment(0)
M
27

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
Misplace answered 21/1, 2016 at 20:14 Comment(0)
R
8

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
Rawson answered 20/11, 2013 at 15:57 Comment(0)
M
5

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.

Mezzosoprano answered 21/4, 2022 at 0:14 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Bleat
I
0

For anyone new coming here, shapely does have an envelope function (if I understand the original correctly). This requires you to create a MultiPoint object of a minimum of 2 points.

MultiPoint([(0, 0), (1, 1)]).envelope

<POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))>

See here: https://shapely.readthedocs.io/en/latest/manual.html#object.envelope

Returns a representation of the point or smallest rectangular polygon (with sides parallel to the coordinate axes) that contains the object.

Interjacent answered 11/2 at 21:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.