shapely module#
Shapely geometry integration.
This module provides the ShapelyGeometry class for integrating with the Shapely library, allowing conversion between JITX primitive shapes and Shapely geometric objects for advanced geometric operations.
- class ShapelyGeometry(geometry)[source]#
Bases:
ShapeGeometryWrapper for Shapely geometric objects.
Provides integration between JITX shapes and the Shapely library.
- Parameters:
geometry (CoShapeGeometry)
- apply(transform)[source]#
Apply a transformation to the shapely shape of this object :param tx - Transformation to apply to the points of the shape.: If None, this is assumed to be the IDENTITY transformation.
- Returns:
A new
ShapelyGeometryobject with the points of the internal shapely geometrygtransformed viashapely.affinity()functions.- Parameters:
transform (Transform)
- classmethod from_shape(shape, tolerance=0.01)[source]#
Create ShapelyGeometry from a JITX Shape.
- Parameters:
shape (
Shape) – JITX Shape to convert.tolerance – Tolerance for arc approximation.
- Returns:
ShapelyGeometry with transform applied.
- classmethod from_shapegeometry(geometry, tolerance=0.01)[source]#
Create ShapelyGeometry from any ShapeGeometry.
- Parameters:
geometry (
ShapeGeometry) – ShapeGeometry to convert.tolerance – Tolerance for arc approximation.
- Returns:
ShapelyGeometry representation.
- classmethod from_primitive(prim, tolerance=0.01)[source]#
Create ShapelyGeometry from a primitive shape.
- Parameters:
prim (
Primitive) – Primitive shape to convert.tolerance – Tolerance for arc approximation.
- Returns:
ShapelyGeometry representation of the primitive.
- property coords#
Access to geometry’s coordinates (CoordinateSequence).
- property xy#
Separate arrays of X and Y coordinate values.
- property wkt#
WKT representation of the geometry.
- property wkb#
WKB representation of the geometry.
- property wkb_hex#
WKB hex representation of the geometry.
- property geom_type#
Name of the geometry’s type, such as ‘Point’.
- property area#
Unitless area of the geometry (float).
- distance(other)[source]#
Unitless distance to other geometry (float).
- Parameters:
other (ShapelyGeometry)
- hausdorff_distance(other)[source]#
Unitless Hausdorff distance to other geometry (float).
- Parameters:
other (ShapelyGeometry)
- property length#
Unitless length of the geometry (float).
- property minimum_clearance#
Unitless distance a node can be moved to produce an invalid geometry (float).
- property boundary#
Return 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.
- property bounds#
Return minimum bounding region (minx, miny, maxx, maxy).
- property centroid#
Return the geometric center of the object.
- point_on_surface()[source]#
Return a point guaranteed to be within the object, cheaply.
Alias of
representative_point().
- representative_point()[source]#
Return a point guaranteed to be within the object, cheaply.
Alias of
point_on_surface().
- property convex_hull#
Return the convex hull of the geometry.
Imagine an elastic band stretched around the geometry: that’s a convex hull, more or less.
The convex hull of a three member multipoint, for example, is a triangular polygon.
- property envelope#
A figure that envelopes the geometry.
- property oriented_envelope#
Return the oriented envelope (minimum rotated rectangle) of a geometry.
The oriented envelope encloses an input geometry, such that the resulting rectangle has minimum area.
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.
The starting point of the rectangle is not fixed. You can use
normalize()to reorganize the rectangle to strict canonical form so the starting point is always the lower left point.Alias of
minimum_rotated_rectangle().
- property minimum_rotated_rectangle#
Return the oriented envelope (minimum rotated rectangle) of the geometry.
The oriented envelope encloses an input geometry, such that the resulting rectangle has minimum area.
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.The starting point of the rectangle is not fixed. You can use
normalize()to reorganize the rectangle to strict canonical form so the starting point is always the lower left point.Alias of
oriented_envelope().
- buffer(distance, quad_segs=16, *, cap_style='round', join_style='round', mitre_limit=5.0, single_sided=False, **kwargs)[source]#
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 – Buffer distance. Positive for dilation, negative for erosion.
quad_segs – Number of segments for quarter circles.
cap_style (
'round'|'square'|'flat') – Style for line endings.join_style (
'round'|'mitre'|'bevel') – Style for line joins.mitre_limit – Limit for mitre joins.
single_sided – Whether to buffer only one side.
**kwargs – Additional arguments passed to Shapely.
- Returns:
Buffered ShapelyGeometry.
- simplify(tolerance, *, preserve_topology=True)[source]#
Return a simplified geometry produced by the Douglas-Peucker algorithm.
Coordinates of the simplified geometry will be no more than the tolerance distance from the original. Unless the topology preserving option is used, the algorithm may produce self-intersecting or otherwise invalid geometries.
- Parameters:
tolerance – Maximum distance for simplification.
preserve_topology – Whether to preserve topology.
- Returns:
Simplified ShapelyGeometry.
- normalize()[source]#
Convert geometry to normal form (or canonical form).
This method orders the coordinates, rings of a polygon and parts of multi geometries consistently. Typically useful for testing purposes (for example in combination with
equals_exact()).
- difference(other, *, grid_size=None)[source]#
Return the difference of the geometries.
Refer to shapely.difference for full documentation.
- Parameters:
other (ShapelyGeometry)
- intersection(other, *, grid_size=None)[source]#
Return the intersection of the geometries.
Refer to shapely.intersection for full documentation.
- Parameters:
other (ShapelyGeometry)
- symmetric_difference(other, *, grid_size=None)[source]#
Return the symmetric difference of the geometries.
Refer to shapely.symmetric_difference for full documentation.
- Parameters:
other (ShapelyGeometry)
- union(other, *, grid_size=None)[source]#
Return the union of the geometries.
Refer to shapely.union for full documentation.
- Parameters:
other (ShapelyGeometry)
- property has_z#
True if the geometry’s coordinate sequence(s) have z values.
- property is_empty#
True if the set of points in this geometry is empty, else False.
- property is_ring#
True if the geometry is a closed ring, else False.
- property is_closed#
True if the geometry is closed, else False.
Applicable only to linear geometries.
- property is_simple#
True if the geometry is simple.
Simple means that any self-intersections are only at boundary points.
- property is_valid#
True if the geometry is valid.
The definition depends on sub-class.
- relate(other)[source]#
Return the DE-9IM intersection matrix for the two geometries (string).
- Parameters:
other (ShapelyGeometry)
- covers(other)[source]#
Return True if the geometry covers the other, else False.
- Parameters:
other (ShapelyGeometry)
- covered_by(other)[source]#
Return True if the geometry is covered by the other, else False.
- Parameters:
other (ShapelyGeometry)
- contains(other)[source]#
Return True if the geometry contains the other, else False.
- Parameters:
other (ShapelyGeometry)
- contains_properly(other)[source]#
Return True if the geometry completely contains the other.
There should be no common boundary points.
Refer to
shapely.contains_properly()for full documentation.- Parameters:
other (ShapelyGeometry)
- crosses(other)[source]#
Return True if the geometries cross, else False.
- Parameters:
other (ShapelyGeometry)
- disjoint(other)[source]#
Return True if geometries are disjoint, else False.
- Parameters:
other (ShapelyGeometry)
- equals(other)[source]#
Return True if geometries are equal, else False.
This method considers point-set equality (or topological equality), and is equivalent to (self.within(other) & self.contains(other)).
- Parameters:
other (ShapelyGeometry)
- intersects(other)[source]#
Return True if geometries intersect, else False.
- Parameters:
other (ShapelyGeometry)
- overlaps(other)[source]#
Return True if geometries overlap, else False.
- Parameters:
other (ShapelyGeometry)
- touches(other)[source]#
Return True if geometries touch, else False.
- Parameters:
other (ShapelyGeometry)
- within(other)[source]#
Return True if geometry is within the other, else False.
- Parameters:
other (ShapelyGeometry)
- dwithin(other, distance)[source]#
Return True if geometry is within a given distance from the other.
Refer to
shapely.dwithin()for full documentation.- Parameters:
other (ShapelyGeometry)
- relate_pattern(other, pattern)[source]#
Return True if the DE-9IM relationship code satisfies the pattern.
- Parameters:
other (ShapelyGeometry)
pattern (str)
- line_locate_point(other, *, normalized=False)[source]#
Return the distance of this geometry to a point nearest the specified point.
If the normalized arg is True, return the distance normalized to the length of the linear geometry.
Alias of
project().- Parameters:
other (shapely.Point)
- project(other, *, normalized=False)[source]#
Return the distance of geometry to a point nearest the specified point.
If the normalized arg is True, return the distance normalized to the length of the linear geometry.
Alias of
line_locate_point().- Parameters:
other (shapely.Point)
- line_interpolate_point(distance, *, normalized=False)[source]#
Return a point at the specified distance along a linear geometry.
Negative length values are taken as measured in the reverse direction from the end of the geometry. Out-of-range index values are handled by clamping them to the valid range of values. If the normalized arg is True, the distance will be interpreted as a fraction of the geometry’s length.
Alias of
interpolate().
- interpolate(distance, *, normalized=False)[source]#
Return a point at the specified distance along a linear geometry.
Negative length values are taken as measured in the reverse direction from the end of the geometry. Out-of-range index values are handled by clamping them to the valid range of values. If the normalized arg is True, the distance will be interpreted as a fraction of the geometry’s length.
Alias of
line_interpolate_point().
- segmentize(max_segment_length)[source]#
Add vertices to line segments based on maximum segment length.
Additional vertices will be added to every line segment in an input geometry so that segments are no longer than the provided maximum segment length. New vertices will evenly subdivide each segment.
Only linear components of input geometries are densified; other geometries are returned unmodified.