Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 938
linqu Avatar asked Nov 20 '13 11:11

linqu


People also ask

How does shapely implement curve and point types?

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.

What is the difference between shapely envelope and general minimum bounding?

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

Is there an empty geometry class in shapely?

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.

What is shapely?

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.


2 Answers

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
like image 151
sgillies Avatar answered Sep 28 '22 08:09

sgillies


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
like image 32
Mike T Avatar answered Sep 28 '22 09:09

Mike T