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?
The point type is implemented by a Point class; curve by the LineString and LinearRing classes; and surface by a Polygon class. Shapely implements no smooth (i.e. having continuous tangents) curves.
Returns the general minimum bounding rectangle that contains the object. Unlike envelope this rectangle is not constrained to be parallel to the coordinate axes. If the convex hull of the object is a degenerate (line or point) this degenerate is returned. New in Shapely 1.6.0
An EmptyGeometry class has been added in the master development branch and will be available in the next non-bugfix release. Shapely 1.6.0 adds new attributes to existing geometry classes and new functions ( split () and polylabel ()) to the shapely.ops module.
Shapely is a BSD-licensed Python package for manipulation and analysis of planar geometric objects. It is based on the widely deployed GEOS (the engine of PostGIS) and JTS (from which GEOS is ported) libraries. Shapely is not concerned with data formats or coordinate systems, but can be readily integrated with packages that are.
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With