shapely.Polygon#
A geometry type representing an area that is enclosed by a linear ring.
A polygon is a two-dimensional feature and has a non-zero area. It may have one or more negative-space “holes” which are also bounded by linear rings. If any rings cross each other, the feature is invalid and operations on it may fail.
Parameters : shell sequence
A sequence of (x, y [,z]) numeric coordinate pairs or triples, or an array-like with shape (N, 2) or (N, 3). Also can be a sequence of Point objects.
holes sequence
A sequence of objects which satisfy the same requirements as the shell parameters above
Create a square polygon with no holes
>>> coords = ((0., 0.), (0., 1.), (1., 1.), (1., 0.), (0., 0.)) >>> polygon = Polygon(coords) >>> polygon.area 1.0
The ring which bounds the positive space of the polygon.
interiors sequence
A sequence of rings which bound all existing holes.
almost_equals ( other , decimal = 6 ) #
True if geometries are equal at all coordinates to a specified decimal place.
Deprecated since version 1.8.0: The ‘almost_equals()’ method is deprecated and will be removed in Shapely 2.1 because the name is confusing. The ‘equals_exact()’ method should be used instead.
Refers to approximate coordinate equality, which requires coordinates to be approximately equal and in the same order for all components of a geometry.
Because of this it is possible for “equals()” to be True for two geometries and “almost_equals()” to be False.
>>> LineString( . [(0, 0), (2, 2)] . ).equals_exact( . LineString([(0, 0), (1, 1), (2, 2)]), . 1e-6 . ) False
Unitless area of the geometry (float)
Returns a lower dimension geometry that bounds the object
The boundary of a polygon is a line, the boundary of a line is a collection of points. The boundary of a point is an empty (null) collection.
Returns minimum bounding region (minx, miny, maxx, maxy)
buffer ( distance , quad_segs = 16 , cap_style = ’round’ , join_style = ’round’ , mitre_limit = 5.0 , single_sided = False , ** kwargs ) #
Get a geometry that represents all points within a distance of this geometry.
A positive distance produces a dilation, a negative distance an erosion. A very small or zero distance may sometimes be used to “tidy” a polygon.
Parameters : distance float
The distance to buffer around the object.
resolution int, optional
The resolution of the buffer around each vertex of the object.
quad_segs int, optional
Sets the number of line segments used to approximate an angle fillet.
cap_style shapely.BufferCapStyle or , default ‘round’
Specifies the shape of buffered line endings. BufferCapStyle.round (‘round’) results in circular line endings (see quad_segs ). Both BufferCapStyle.square (‘square’) and BufferCapStyle.flat (‘flat’) result in rectangular line endings, only BufferCapStyle.flat (‘flat’) will end at the original vertex, while BufferCapStyle.square (‘square’) involves adding the buffer width.
join_style shapely.BufferJoinStyle or , default ‘round’
Specifies the shape of buffered line midpoints. BufferJoinStyle.ROUND (‘round’) results in rounded shapes. BufferJoinStyle.bevel (‘bevel’) results in a beveled edge that touches the original vertex. BufferJoinStyle.mitre (‘mitre’) results in a single vertex that is beveled depending on the mitre_limit parameter.
mitre_limit float, optional
The mitre limit ratio is used for very sharp corners. The mitre ratio is the ratio of the distance from the corner to the end of the mitred offset corner. When two line segments meet at a sharp angle, a miter join will extend the original geometry. To prevent unreasonable geometry, the mitre limit allows controlling the maximum length of the join corner. Corners with a ratio which exceed the limit will be beveled.
single_side bool, optional
The side used is determined by the sign of the buffer distance:
a positive distance indicates the left-hand side a negative distance indicates the right-hand side
The single-sided buffer of point geometries is the same as the regular buffer. The End Cap Style for single-sided buffers is always ignored, and forced to the equivalent of CAP_FLAT.
quadsegs int, optional
Deprecated alias for quad_segs .
The return value is a strictly two-dimensional geometry. All Z coordinates of the original geometry will be ignored.
>>> from shapely.wkt import loads >>> g = loads('POINT (0.0 0.0)')
16-gon approx of a unit radius circle:
>>> g.buffer(1.0).area 3.1365484905459.
shapely.area#
For other keyword-only arguments, see the NumPy ufunc docs.
>>> from shapely import MultiPolygon, Polygon >>> polygon = Polygon([(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)]) >>> area(polygon) 100.0 >>> area(MultiPolygon([polygon, Polygon([(10, 10), (10, 20), (20, 20), (20, 10), (10, 10)])])) 200.0 >>> area(Polygon()) 0.0 >>> area(None) nan