shapely.prepare#
- prepare(geometry, **kwargs)#
Prepare a geometry, improving performance of other operations.
A prepared geometry is a normal geometry with added information such as an index on the line segments. This improves the performance of the following operations: contains, contains_properly, covered_by, covers, crosses, disjoint, intersects, overlaps, touches, and within.
Note that if a prepared geometry is modified, the newly created Geometry object is not prepared. In that case,
prepareshould be called again.This function does not recompute previously prepared geometries; it is efficient to call this function on an array that partially contains prepared geometries.
This function returns True where geometries were prepared, and False otherwise. When it returns False, this does not mean that the function failed; it merely indicates that the geometry was already prepared.
- Parameters:
- geometryGeometry or array_like
Geometries are changed in place
- **kwargs
See NumPy ufunc docs for other keyword arguments.
See also
is_preparedIdentify whether a geometry is prepared already.
destroy_preparedDestroy the prepared part of a geometry.
Examples
>>> import shapely >>> from shapely import Point >>> poly = shapely.buffer(Point(1.0, 1.0), 1) >>> shapely.prepare(poly) True >>> shapely.contains_properly(poly, [Point(0.0, 0.0), Point(0.5, 0.5)]).tolist() [False, True]