shapely API Reference
Full documentation for shapely (2.1.2)
shapely.BufferCapStyle
Python Library Documentation: class BufferCapStyle in module shapely.constructive class BufferCapStyle(shapely._enum.ParamEnum) | BufferCapStyle(*values) | | Enumeration of buffer cap styles. | | Attributes | ---------- | round : int | Represents a round cap style. | flat : int | Represents a flat cap style. | square : int | Represents a square cap style. | | Method resolution order: | BufferCapStyle | shapely._enum.ParamEnum | enum.IntEnum | builtins.int | enum.ReprEnum | enum.Enum | builtins.object | | Methods defined here: | | __format__(self, format_spec, /) from builtins.int | Convert to a string according to format_spec. | | __new__(cls, value) from enum.Enum | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | flat = <BufferCapStyle.flat: 2> | | round = <BufferCapStyle.round: 1> | | square = <BufferCapStyle.square: 3> | | ---------------------------------------------------------------------- | Methods inherited from enum.IntEnum: | | __repr__(self) from enum.Enum | Return repr(self). | | __str__ = __repr__(self, /) from builtins.int | Return repr(self). | | ---------------------------------------------------------------------- | Methods inherited from builtins.int: | | __abs__(self, /) | abs(self) | | __add__(self, value, /) | Return self+value. | | __and__(self, value, /) | Return self&value. | | __bool__(self, /) | True if self else False | | __ceil__(...) | Ceiling of an Integral returns itself. | | __divmod__(self, value, /) | Return divmod(self, value). | | __eq__(self, value, /) | Return self==value. | | __float__(self, /) | float(self) | | __floor__(...) | Flooring an Integral returns itself. | | __floordiv__(self, value, /) | Return self//value. | | __ge__(self, value, /) | Return self>=value. | | __getattribute__(self, name, /) | Return getattr(self, name). | | __getnewargs__(self, /) | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __index__(self, /) | Return self converted to an integer, if self is suitable for use as an index into a list. | | __int__(self, /) | int(self) | | __invert__(self, /) | ~self | | __le__(self, value, /) | Return self<=value. | | __lshift__(self, value, /) | Return self<<value. | | __lt__(self, value, /) | Return self<value. | | __mod__(self, value, /) | Return self%value. | | __mul__(self, value, /) | Return self*value. | | __ne__(self, value, /) | Return self!=value. | | __neg__(self, /) | -self | | __or__(self, value, /) | Return self|value. | | __pos__(self, /) | +self | | __pow__(self, value, mod=None, /) | Return pow(self, value, mod). | | __radd__(self, value, /) | Return value+self. | | __rand__(self, value, /) | Return value&self. | | __rdivmod__(self, value, /) | Return divmod(value, self). | | __rfloordiv__(self, value, /) | Return value//self. | | __rlshift__(self, value, /) | Return value<<self. | | __rmod__(self, value, /) | Return value%self. | | __rmul__(self, value, /) | Return value*self. | | __ror__(self, value, /) | Return value|self. | | __round__(...) | Rounding an Integral returns itself. | | Rounding with an ndigits argument also returns an integer. | | __rpow__(self, value, mod=None, /) | Return pow(value, self, mod). | | __rrshift__(self, value, /) | Return value>>self. | | __rshift__(self, value, /) | Return self>>value. | | __rsub__(self, value, /) | Return value-self. | | __rtruediv__(self, value, /) | Return value/self. | | __rxor__(self, value, /) | Return value^self. | | __sizeof__(self, /) | Returns size in memory, in bytes. | | __sub__(self, value, /) | Return self-value. | | __truediv__(self, value, /) | Return self/value. | | __trunc__(...) | Truncating an Integral returns itself. | | __xor__(self, value, /) | Return self^value. | | as_integer_ratio(self, /) | Return a pair of integers, whose ratio is equal to the original int. | | The ratio is in lowest terms and has a positive denominator. | | >>> (10).as_integer_ratio() | (10, 1) | >>> (-10).as_integer_ratio() | (-10, 1) | >>> (0).as_integer_ratio() | (0, 1) | | bit_count(self, /) | Number of ones in the binary representation of the absolute value of self. | | Also known as the population count. | | >>> bin(13) | '0b1101' | >>> (13).bit_count() | 3 | | bit_length(self, /) | Number of bits necessary to represent self in binary. | | >>> bin(37) | '0b100101' | >>> (37).bit_length() | 6 | | conjugate(...) | Returns self, the complex conjugate of any int. | | is_integer(self, /) | Returns True. Exists for duck type compatibility with float.is_integer. | | to_bytes(self, /, length=1, byteorder='big', *, signed=False) | Return an array of bytes representing an integer. | | length | Length of bytes object to use. An OverflowError is raised if the | integer is not representable with the given number of bytes. Default | is length 1. | byteorder | The byte order used to represent the integer. If byteorder is 'big', | the most significant byte is at the beginning of the byte array. If | byteorder is 'little', the most significant byte is at the end of the | byte array. To request the native byte order of the host system, use | `sys.byteorder' as the byte order value. Default is to use 'big'. | signed | Determines whether two's complement is used to represent the integer. | If signed is False and a negative integer is given, an OverflowError | is raised. | | ---------------------------------------------------------------------- | Class methods inherited from builtins.int: | | from_bytes(bytes, byteorder='big', *, signed=False) | Return the integer represented by the given array of bytes. | | bytes | Holds the array of bytes to convert. The argument must either | support the buffer protocol or be an iterable object producing bytes. | Bytes and bytearray are examples of built-in objects that support the | buffer protocol. | byteorder | The byte order used to represent the integer. If byteorder is 'big', | the most significant byte is at the beginning of the byte array. If | byteorder is 'little', the most significant byte is at the end of the | byte array. To request the native byte order of the host system, use | `sys.byteorder' as the byte order value. Default is to use 'big'. | signed | Indicates whether two's complement is used to represent the integer. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.int: | | denominator | the denominator of a rational number in lowest terms | | imag | the imaginary part of a complex number | | numerator | the numerator of a rational number in lowest terms | | real | the real part of a complex number | | ---------------------------------------------------------------------- | Methods inherited from enum.Enum: | | __dir__(self) | Returns public methods and other interesting attributes. | | __init__(self, *args, **kwds) | Initialize self. See help(type(self)) for accurate signature. | | __reduce_ex__(self, proto) | Helper for pickle. | | ---------------------------------------------------------------------- | Data descriptors inherited from enum.Enum: | | name | The name of the Enum member. | | value | The value of the Enum member. | | ---------------------------------------------------------------------- | Static methods inherited from enum.EnumType: | | __contains__(value) | Return True if `value` is in `cls`. | | `value` is in `cls` if: | 1) `value` is a member of `cls`, or | 2) `value` is the value of one of the `cls`'s members. | | __getitem__(name) | Return the member matching `name`. | | __iter__() | Return members in definition order. | | __len__() | Return the number of members (no aliases) | | ---------------------------------------------------------------------- | Readonly properties inherited from enum.EnumType: | | __members__ | Returns a mapping of member name->value. | | This mapping lists all enum members, including aliases. Note that this | is a read-only view of the internal mapping.
shapely.BufferJoinStyle
Python Library Documentation: class BufferJoinStyle in module shapely.constructive class BufferJoinStyle(shapely._enum.ParamEnum) | BufferJoinStyle(*values) | | Enumeration of buffer join styles. | | Attributes | ---------- | round : int | Specifies a round join style. | mitre : int | Specifies a mitre join style. | bevel : int | Specifies a bevel join style. | | Method resolution order: | BufferJoinStyle | shapely._enum.ParamEnum | enum.IntEnum | builtins.int | enum.ReprEnum | enum.Enum | builtins.object | | Methods defined here: | | __format__(self, format_spec, /) from builtins.int | Convert to a string according to format_spec. | | __new__(cls, value) from enum.Enum | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | bevel = <BufferJoinStyle.bevel: 3> | | mitre = <BufferJoinStyle.mitre: 2> | | round = <BufferJoinStyle.round: 1> | | ---------------------------------------------------------------------- | Methods inherited from enum.IntEnum: | | __repr__(self) from enum.Enum | Return repr(self). | | __str__ = __repr__(self, /) from builtins.int | Return repr(self). | | ---------------------------------------------------------------------- | Methods inherited from builtins.int: | | __abs__(self, /) | abs(self) | | __add__(self, value, /) | Return self+value. | | __and__(self, value, /) | Return self&value. | | __bool__(self, /) | True if self else False | | __ceil__(...) | Ceiling of an Integral returns itself. | | __divmod__(self, value, /) | Return divmod(self, value). | | __eq__(self, value, /) | Return self==value. | | __float__(self, /) | float(self) | | __floor__(...) | Flooring an Integral returns itself. | | __floordiv__(self, value, /) | Return self//value. | | __ge__(self, value, /) | Return self>=value. | | __getattribute__(self, name, /) | Return getattr(self, name). | | __getnewargs__(self, /) | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __index__(self, /) | Return self converted to an integer, if self is suitable for use as an index into a list. | | __int__(self, /) | int(self) | | __invert__(self, /) | ~self | | __le__(self, value, /) | Return self<=value. | | __lshift__(self, value, /) | Return self<<value. | | __lt__(self, value, /) | Return self<value. | | __mod__(self, value, /) | Return self%value. | | __mul__(self, value, /) | Return self*value. | | __ne__(self, value, /) | Return self!=value. | | __neg__(self, /) | -self | | __or__(self, value, /) | Return self|value. | | __pos__(self, /) | +self | | __pow__(self, value, mod=None, /) | Return pow(self, value, mod). | | __radd__(self, value, /) | Return value+self. | | __rand__(self, value, /) | Return value&self. | | __rdivmod__(self, value, /) | Return divmod(value, self). | | __rfloordiv__(self, value, /) | Return value//self. | | __rlshift__(self, value, /) | Return value<<self. | | __rmod__(self, value, /) | Return value%self. | | __rmul__(self, value, /) | Return value*self. | | __ror__(self, value, /) | Return value|self. | | __round__(...) | Rounding an Integral returns itself. | | Rounding with an ndigits argument also returns an integer. | | __rpow__(self, value, mod=None, /) | Return pow(value, self, mod). | | __rrshift__(self, value, /) | Return value>>self. | | __rshift__(self, value, /) | Return self>>value. | | __rsub__(self, value, /) | Return value-self. | | __rtruediv__(self, value, /) | Return value/self. | | __rxor__(self, value, /) | Return value^self. | | __sizeof__(self, /) | Returns size in memory, in bytes. | | __sub__(self, value, /) | Return self-value. | | __truediv__(self, value, /) | Return self/value. | | __trunc__(...) | Truncating an Integral returns itself. | | __xor__(self, value, /) | Return self^value. | | as_integer_ratio(self, /) | Return a pair of integers, whose ratio is equal to the original int. | | The ratio is in lowest terms and has a positive denominator. | | >>> (10).as_integer_ratio() | (10, 1) | >>> (-10).as_integer_ratio() | (-10, 1) | >>> (0).as_integer_ratio() | (0, 1) | | bit_count(self, /) | Number of ones in the binary representation of the absolute value of self. | | Also known as the population count. | | >>> bin(13) | '0b1101' | >>> (13).bit_count() | 3 | | bit_length(self, /) | Number of bits necessary to represent self in binary. | | >>> bin(37) | '0b100101' | >>> (37).bit_length() | 6 | | conjugate(...) | Returns self, the complex conjugate of any int. | | is_integer(self, /) | Returns True. Exists for duck type compatibility with float.is_integer. | | to_bytes(self, /, length=1, byteorder='big', *, signed=False) | Return an array of bytes representing an integer. | | length | Length of bytes object to use. An OverflowError is raised if the | integer is not representable with the given number of bytes. Default | is length 1. | byteorder | The byte order used to represent the integer. If byteorder is 'big', | the most significant byte is at the beginning of the byte array. If | byteorder is 'little', the most significant byte is at the end of the | byte array. To request the native byte order of the host system, use | `sys.byteorder' as the byte order value. Default is to use 'big'. | signed | Determines whether two's complement is used to represent the integer. | If signed is False and a negative integer is given, an OverflowError | is raised. | | ---------------------------------------------------------------------- | Class methods inherited from builtins.int: | | from_bytes(bytes, byteorder='big', *, signed=False) | Return the integer represented by the given array of bytes. | | bytes | Holds the array of bytes to convert. The argument must either | support the buffer protocol or be an iterable object producing bytes. | Bytes and bytearray are examples of built-in objects that support the | buffer protocol. | byteorder | The byte order used to represent the integer. If byteorder is 'big', | the most significant byte is at the beginning of the byte array. If | byteorder is 'little', the most significant byte is at the end of the | byte array. To request the native byte order of the host system, use | `sys.byteorder' as the byte order value. Default is to use 'big'. | signed | Indicates whether two's complement is used to represent the integer. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.int: | | denominator | the denominator of a rational number in lowest terms | | imag | the imaginary part of a complex number | | numerator | the numerator of a rational number in lowest terms | | real | the real part of a complex number | | ---------------------------------------------------------------------- | Methods inherited from enum.Enum: | | __dir__(self) | Returns public methods and other interesting attributes. | | __init__(self, *args, **kwds) | Initialize self. See help(type(self)) for accurate signature. | | __reduce_ex__(self, proto) | Helper for pickle. | | ---------------------------------------------------------------------- | Data descriptors inherited from enum.Enum: | | name | The name of the Enum member. | | value | The value of the Enum member. | | ---------------------------------------------------------------------- | Static methods inherited from enum.EnumType: | | __contains__(value) | Return True if `value` is in `cls`. | | `value` is in `cls` if: | 1) `value` is a member of `cls`, or | 2) `value` is the value of one of the `cls`'s members. | | __getitem__(name) | Return the member matching `name`. | | __iter__() | Return members in definition order. | | __len__() | Return the number of members (no aliases) | | ---------------------------------------------------------------------- | Readonly properties inherited from enum.EnumType: | | __members__ | Returns a mapping of member name->value. | | This mapping lists all enum members, including aliases. Note that this | is a read-only view of the internal mapping.
shapely.GEOSException
Python Library Documentation: class GEOSException in module shapely.errors class GEOSException(ShapelyError) | Method resolution order: | GEOSException | ShapelyError | builtins.Exception | builtins.BaseException | builtins.object | | Data descriptors inherited from ShapelyError: | | __weakref__ | list of weak references to the object | | ---------------------------------------------------------------------- | Methods inherited from builtins.Exception: | | __init__(self, /, *args, **kwargs) | Initialize self. See help(type(self)) for accurate signature. | | ---------------------------------------------------------------------- | Static methods inherited from builtins.Exception: | | __new__(*args, **kwargs) class method of builtins.Exception | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Methods inherited from builtins.BaseException: | | __getattribute__(self, name, /) | Return getattr(self, name). | | __reduce__(...) | Helper for pickle. | | __repr__(self, /) | Return repr(self). | | __setstate__(...) | | __str__(self, /) | Return str(self). | | add_note(...) | Exception.add_note(note) -- | add a note to the exception | | with_traceback(...) | Exception.with_traceback(tb) -- | set self.__traceback__ to tb and return self. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.BaseException: | | __cause__ | exception cause | | __context__ | exception context | | __dict__ | | __suppress_context__ | | __traceback__ | | args
shapely.Geometry
Python Library Documentation: class Geometry in module shapely.lib class Geometry(builtins.object) | Geometry type | | Methods defined here: | | __eq__(self, value, /) | Return self==value. | | __ge__(self, value, /) | Return self>=value. | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __le__(self, value, /) | Return self<=value. | | __lt__(self, value, /) | Return self<value. | | __ne__(self, value, /) | Return self!=value. | | __repr__(self, /) | Return repr(self). | | __setstate__(...) | For unpickling pre-shapely 2.0 pickles | | __str__(self, /) | Return str(self).
shapely.GeometryCollection
Python Library Documentation: class GeometryCollection in module shapely.geometry.collection
class GeometryCollection(shapely.geometry.base.BaseMultipartGeometry)
| GeometryCollection(geoms=None)
|
| Collection of one or more geometries that can be of different types.
|
| Parameters
| ----------
| geoms : list
| A list of shapely geometry instances, which may be of varying geometry
| types.
|
| Attributes
| ----------
| geoms : sequence
| A sequence of Shapely geometry instances
|
| Examples
| --------
| Create a GeometryCollection with a Point and a LineString
|
| >>> from shapely import GeometryCollection, LineString, Point
| >>> p = Point(51, -1)
| >>> l = LineString([(52, -1), (49, 2)])
| >>> gc = GeometryCollection([p, l])
|
| Method resolution order:
| GeometryCollection
| shapely.geometry.base.BaseMultipartGeometry
| shapely.geometry.base.BaseGeometry
| shapely.lib.Geometry
| builtins.object
|
| Static methods defined here:
|
| __new__(self, geoms=None)
| Create a new GeometryCollection.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __geo_interface__
| Return a GeoJSON-like mapping of the geometry collection.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.geometry.base.BaseMultipartGeometry:
|
| __bool__(self)
| Return True if the geometry is not empty, else False.
|
| __eq__(self, other)
| Return True if geometries are equal, else False.
|
| __hash__(self)
| Return the hash value of the geometry.
|
| svg(self, scale_factor=1.0, color=None)
| Return a group of SVG elements for the multipart geometry.
|
| Parameters
| ----------
| scale_factor : float
| Multiplication factor for the SVG stroke-width. Default is 1.
| color : str, optional
| Hex string for stroke or fill color. Default is to use "#66cc99"
| if geometry is valid, and "#ff3333" if invalid.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from shapely.geometry.base.BaseMultipartGeometry:
|
| coords
| Not implemented.
|
| Sub-geometries may have coordinate sequences, but multi-part geometries
| do not.
|
| geoms
| Access to the contained geometries.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.geometry.base.BaseGeometry:
|
| __and__(self, other)
| Return the intersection of the geometries.
|
| __format__(self, format_spec)
| Format a geometry using a format specification.
|
| __nonzero__(self)
| Return True if the geometry is not empty, else False.
|
| __or__(self, other)
| Return the union of the geometries.
|
| __reduce__(self)
| Pickle support.
|
| __repr__(self)
| Return a string representation of the geometry.
|
| __str__(self)
| Return a string representation of the geometry.
|
| __sub__(self, other)
| Return the difference of the geometries.
|
| __xor__(self, other)
| Return the symmetric difference of the geometries.
|
| buffer(self, 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.
| quad_segs : int, optional
| Sets the number of line segments used to approximate an
| angle fillet.
| cap_style : shapely.BufferCapStyle or {'round', 'square', 'flat'}, 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 {'round', 'mitre', 'bevel'}, 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_sided : 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, resolution : int, optional
| Deprecated aliases for `quad_segs`.
| **kwargs : dict, optional
| For backwards compatibility of renamed parameters. If an unsupported
| kwarg is passed, a `ValueError` will be raised.
|
| Returns
| -------
| Geometry
|
| Notes
| -----
| The return value is a strictly two-dimensional geometry. All
| Z coordinates of the original geometry will be ignored.
|
| .. deprecated:: 2.1.0
| A deprecation warning is shown if ``quad_segs``, ``cap_style``,
| ``join_style``, ``mitre_limit`` or ``single_sided`` are
| specified as positional arguments. In a future release, these will
| need to be specified as keyword arguments.
|
| Examples
| --------
| >>> from shapely import BufferCapStyle
| >>> 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.1365484905459398
|
| 128-gon approximation:
|
| >>> g.buffer(1.0, 128).area
| 3.1415138011443013
|
| triangle approximation:
|
| >>> g.buffer(1.0, 3).area
| 3.0
| >>> list(g.buffer(1.0, cap_style=BufferCapStyle.square).exterior.coords)
| [(1.0, 1.0), (1.0, -1.0), (-1.0, -1.0), (-1.0, 1.0), (1.0, 1.0)]
| >>> g.buffer(1.0, cap_style=BufferCapStyle.square).area
| 4.0
|
| contains(self, other)
| Return True if the geometry contains the other, else False.
|
| contains_properly(self, other)
| Return True if the geometry completely contains the other.
|
| There should be no common boundary points.
|
| Refer to `shapely.contains_properly` for full documentation.
|
| covered_by(self, other)
| Return True if the geometry is covered by the other, else False.
|
| covers(self, other)
| Return True if the geometry covers the other, else False.
|
| crosses(self, other)
| Return True if the geometries cross, else False.
|
| difference(self, other, grid_size=None)
| Return the difference of the geometries.
|
| Refer to `shapely.difference` for full documentation.
|
| disjoint(self, other)
| Return True if geometries are disjoint, else False.
|
| distance(self, other)
| Unitless distance to other geometry (float).
|
| dwithin(self, other, distance)
| Return True if geometry is within a given distance from the other.
|
| Refer to `shapely.dwithin` for full documentation.
|
| equals(self, other)
| 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)).
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals(
| ... LineString([(0, 0), (1, 1), (2, 2)])
| ... )
| True
|
| Returns
| -------
| bool
|
| equals_exact(self, other, tolerance=0.0, *, normalize=False)
| Return True if the geometries are equivalent within the tolerance.
|
| Refer to :func:`~shapely.equals_exact` for full documentation.
|
| Parameters
| ----------
| other : BaseGeometry
| The other geometry object in this comparison.
| tolerance : float, optional (default: 0.)
| Absolute tolerance in the same units as coordinates.
| normalize : bool, optional (default: False)
| If True, normalize the two geometries so that the coordinates are
| in the same order.
|
| .. versionadded:: 2.1.0
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals_exact(
| ... LineString([(0, 0), (1, 1), (2, 2)]),
| ... 1e-6
| ... )
| False
|
| Returns
| -------
| bool
|
| geometryType(self)
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| hausdorff_distance(self, other)
| Unitless hausdorff distance to other geometry (float).
|
| interpolate(self, distance, normalized=False)
| 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`.
|
| intersection(self, other, grid_size=None)
| Return the intersection of the geometries.
|
| Refer to `shapely.intersection` for full documentation.
|
| intersects(self, other)
| Return True if geometries intersect, else False.
|
| line_interpolate_point(self, distance, normalized=False)
| 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`.
|
| line_locate_point(self, other, normalized=False)
| 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`.
|
| normalize(self)
| 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`).
|
| Examples
| --------
| >>> from shapely import MultiLineString
| >>> line = MultiLineString([[(0, 0), (1, 1)], [(3, 3), (2, 2)]])
| >>> line.normalize()
| <MULTILINESTRING ((2 2, 3 3), (0 0, 1 1))>
|
| overlaps(self, other)
| Return True if geometries overlap, else False.
|
| point_on_surface(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `representative_point`.
|
| project(self, other, normalized=False)
| 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`.
|
| relate(self, other)
| Return the DE-9IM intersection matrix for the two geometries (string).
|
| relate_pattern(self, other, pattern)
| Return True if the DE-9IM relationship code satisfies the pattern.
|
| representative_point(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `point_on_surface`.
|
| reverse(self)
| Return a copy of this geometry with the order of coordinates reversed.
|
| If the geometry is a polygon with interior rings, the interior rings are also
| reversed.
|
| Points are unchanged.
|
| See Also
| --------
| is_ccw : Checks if a geometry is clockwise.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (1, 2)]).reverse()
| <LINESTRING (1 2, 0 0)>
| >>> Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]).reverse()
| <POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
|
| segmentize(self, max_segment_length)
| 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.
|
| Parameters
| ----------
| max_segment_length : float or array_like
| Additional vertices will be added so that all line segments are no
| longer this value. Must be greater than 0.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (0, 10)]).segmentize(max_segment_length=5)
| <LINESTRING (0 0, 0 5, 0 10)>
| >>> Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]).segmentize(max_segment_length=5)
| <POLYGON ((0 0, 5 0, 10 0, 10 5, 10 10, 5 10, 0 10, 0 5, 0 0))>
|
| simplify(self, tolerance, preserve_topology=True)
| 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.
|
| symmetric_difference(self, other, grid_size=None)
| Return the symmetric difference of the geometries.
|
| Refer to `shapely.symmetric_difference` for full documentation.
|
| touches(self, other)
| Return True if geometries touch, else False.
|
| union(self, other, grid_size=None)
| Return the union of the geometries.
|
| Refer to `shapely.union` for full documentation.
|
| within(self, other)
| Return True if geometry is within the other, else False.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from shapely.geometry.base.BaseGeometry:
|
| area
| Unitless area of the geometry (float).
|
| 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.
|
| bounds
| Return minimum bounding region (minx, miny, maxx, maxy).
|
| centroid
| Return the geometric center of the object.
|
| 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.
|
| envelope
| A figure that envelopes the geometry.
|
| geom_type
| Name of the geometry's type, such as 'Point'.
|
| has_m
| True if the geometry's coordinate sequence(s) have m values.
|
| has_z
| True if the geometry's coordinate sequence(s) have z values.
|
| is_closed
| True if the geometry is closed, else False.
|
| Applicable only to linear geometries.
|
| is_empty
| True if the set of points in this geometry is empty, else False.
|
| is_ring
| True if the geometry is a closed ring, else False.
|
| is_simple
| True if the geometry is simple.
|
| Simple means that any self-intersections are only at boundary points.
|
| is_valid
| True if the geometry is valid.
|
| The definition depends on sub-class.
|
| length
| Unitless length of the geometry (float).
|
| minimum_clearance
| Unitless distance a node can be moved to produce an invalid geometry (float).
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `oriented_envelope`.
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `minimum_rotated_rectangle`.
|
| type
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| wkb
| WKB representation of the geometry.
|
| wkb_hex
| WKB hex representation of the geometry.
|
| wkt
| WKT representation of the geometry.
|
| xy
| Separate arrays of X and Y coordinate values.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.lib.Geometry:
|
| __ge__(self, value, /)
| Return self>=value.
|
| __gt__(self, value, /)
| Return self>value.
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __setstate__(...)
| For unpickling pre-shapely 2.0 pickles
shapely.GeometryType
Python Library Documentation: class GeometryType in module shapely._geometry class GeometryType(enum.IntEnum) | GeometryType(*values) | | The enumeration of GEOS geometry types. | | Method resolution order: | GeometryType | enum.IntEnum | builtins.int | enum.ReprEnum | enum.Enum | builtins.object | | Methods defined here: | | __format__(self, format_spec, /) from builtins.int | Convert to a string according to format_spec. | | __new__(cls, value) from enum.Enum | Create and return a new object. See help(type) for accurate signature. | | ---------------------------------------------------------------------- | Data and other attributes defined here: | | GEOMETRYCOLLECTION = <GeometryType.GEOMETRYCOLLECTION: 7> | | LINEARRING = <GeometryType.LINEARRING: 2> | | LINESTRING = <GeometryType.LINESTRING: 1> | | MISSING = <GeometryType.MISSING: -1> | | MULTILINESTRING = <GeometryType.MULTILINESTRING: 5> | | MULTIPOINT = <GeometryType.MULTIPOINT: 4> | | MULTIPOLYGON = <GeometryType.MULTIPOLYGON: 6> | | POINT = <GeometryType.POINT: 0> | | POLYGON = <GeometryType.POLYGON: 3> | | ---------------------------------------------------------------------- | Methods inherited from enum.IntEnum: | | __repr__(self) from enum.Enum | Return repr(self). | | __str__ = __repr__(self, /) from builtins.int | Return repr(self). | | ---------------------------------------------------------------------- | Methods inherited from builtins.int: | | __abs__(self, /) | abs(self) | | __add__(self, value, /) | Return self+value. | | __and__(self, value, /) | Return self&value. | | __bool__(self, /) | True if self else False | | __ceil__(...) | Ceiling of an Integral returns itself. | | __divmod__(self, value, /) | Return divmod(self, value). | | __eq__(self, value, /) | Return self==value. | | __float__(self, /) | float(self) | | __floor__(...) | Flooring an Integral returns itself. | | __floordiv__(self, value, /) | Return self//value. | | __ge__(self, value, /) | Return self>=value. | | __getattribute__(self, name, /) | Return getattr(self, name). | | __getnewargs__(self, /) | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __index__(self, /) | Return self converted to an integer, if self is suitable for use as an index into a list. | | __int__(self, /) | int(self) | | __invert__(self, /) | ~self | | __le__(self, value, /) | Return self<=value. | | __lshift__(self, value, /) | Return self<<value. | | __lt__(self, value, /) | Return self<value. | | __mod__(self, value, /) | Return self%value. | | __mul__(self, value, /) | Return self*value. | | __ne__(self, value, /) | Return self!=value. | | __neg__(self, /) | -self | | __or__(self, value, /) | Return self|value. | | __pos__(self, /) | +self | | __pow__(self, value, mod=None, /) | Return pow(self, value, mod). | | __radd__(self, value, /) | Return value+self. | | __rand__(self, value, /) | Return value&self. | | __rdivmod__(self, value, /) | Return divmod(value, self). | | __rfloordiv__(self, value, /) | Return value//self. | | __rlshift__(self, value, /) | Return value<<self. | | __rmod__(self, value, /) | Return value%self. | | __rmul__(self, value, /) | Return value*self. | | __ror__(self, value, /) | Return value|self. | | __round__(...) | Rounding an Integral returns itself. | | Rounding with an ndigits argument also returns an integer. | | __rpow__(self, value, mod=None, /) | Return pow(value, self, mod). | | __rrshift__(self, value, /) | Return value>>self. | | __rshift__(self, value, /) | Return self>>value. | | __rsub__(self, value, /) | Return value-self. | | __rtruediv__(self, value, /) | Return value/self. | | __rxor__(self, value, /) | Return value^self. | | __sizeof__(self, /) | Returns size in memory, in bytes. | | __sub__(self, value, /) | Return self-value. | | __truediv__(self, value, /) | Return self/value. | | __trunc__(...) | Truncating an Integral returns itself. | | __xor__(self, value, /) | Return self^value. | | as_integer_ratio(self, /) | Return a pair of integers, whose ratio is equal to the original int. | | The ratio is in lowest terms and has a positive denominator. | | >>> (10).as_integer_ratio() | (10, 1) | >>> (-10).as_integer_ratio() | (-10, 1) | >>> (0).as_integer_ratio() | (0, 1) | | bit_count(self, /) | Number of ones in the binary representation of the absolute value of self. | | Also known as the population count. | | >>> bin(13) | '0b1101' | >>> (13).bit_count() | 3 | | bit_length(self, /) | Number of bits necessary to represent self in binary. | | >>> bin(37) | '0b100101' | >>> (37).bit_length() | 6 | | conjugate(...) | Returns self, the complex conjugate of any int. | | is_integer(self, /) | Returns True. Exists for duck type compatibility with float.is_integer. | | to_bytes(self, /, length=1, byteorder='big', *, signed=False) | Return an array of bytes representing an integer. | | length | Length of bytes object to use. An OverflowError is raised if the | integer is not representable with the given number of bytes. Default | is length 1. | byteorder | The byte order used to represent the integer. If byteorder is 'big', | the most significant byte is at the beginning of the byte array. If | byteorder is 'little', the most significant byte is at the end of the | byte array. To request the native byte order of the host system, use | `sys.byteorder' as the byte order value. Default is to use 'big'. | signed | Determines whether two's complement is used to represent the integer. | If signed is False and a negative integer is given, an OverflowError | is raised. | | ---------------------------------------------------------------------- | Class methods inherited from builtins.int: | | from_bytes(bytes, byteorder='big', *, signed=False) | Return the integer represented by the given array of bytes. | | bytes | Holds the array of bytes to convert. The argument must either | support the buffer protocol or be an iterable object producing bytes. | Bytes and bytearray are examples of built-in objects that support the | buffer protocol. | byteorder | The byte order used to represent the integer. If byteorder is 'big', | the most significant byte is at the beginning of the byte array. If | byteorder is 'little', the most significant byte is at the end of the | byte array. To request the native byte order of the host system, use | `sys.byteorder' as the byte order value. Default is to use 'big'. | signed | Indicates whether two's complement is used to represent the integer. | | ---------------------------------------------------------------------- | Data descriptors inherited from builtins.int: | | denominator | the denominator of a rational number in lowest terms | | imag | the imaginary part of a complex number | | numerator | the numerator of a rational number in lowest terms | | real | the real part of a complex number | | ---------------------------------------------------------------------- | Methods inherited from enum.Enum: | | __dir__(self) | Returns public methods and other interesting attributes. | | __init__(self, *args, **kwds) | Initialize self. See help(type(self)) for accurate signature. | | __reduce_ex__(self, proto) | Helper for pickle. | | ---------------------------------------------------------------------- | Data descriptors inherited from enum.Enum: | | name | The name of the Enum member. | | value | The value of the Enum member. | | ---------------------------------------------------------------------- | Static methods inherited from enum.EnumType: | | __contains__(value) | Return True if `value` is in `cls`. | | `value` is in `cls` if: | 1) `value` is a member of `cls`, or | 2) `value` is the value of one of the `cls`'s members. | | __getitem__(name) | Return the member matching `name`. | | __iter__() | Return members in definition order. | | __len__() | Return the number of members (no aliases) | | ---------------------------------------------------------------------- | Readonly properties inherited from enum.EnumType: | | __members__ | Returns a mapping of member name->value. | | This mapping lists all enum members, including aliases. Note that this | is a read-only view of the internal mapping.
shapely.LineString
Python Library Documentation: class LineString in module shapely.geometry.linestring
class LineString(shapely.geometry.base.BaseGeometry)
| LineString(coordinates=None)
|
| A geometry type composed of one or more line segments.
|
| A LineString is a one-dimensional feature and has a non-zero length but
| zero area. It may approximate a curve and need not be straight. A LineString may
| be closed.
|
| Parameters
| ----------
| coordinates : 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, or combination of both.
|
| Examples
| --------
| Create a LineString with two segments
|
| >>> from shapely import LineString
| >>> a = LineString([[0, 0], [1, 0], [1, 1]])
| >>> a.length
| 2.0
|
| Method resolution order:
| LineString
| shapely.geometry.base.BaseGeometry
| shapely.lib.Geometry
| builtins.object
|
| Methods defined here:
|
| offset_curve(self, distance, quad_segs=16, join_style=<BufferJoinStyle.round: 1>, mitre_limit=5.0)
| Return a (Multi)LineString at a distance from the object.
|
| The side, left or right, is determined by the sign of the `distance`
| parameter (negative for right side offset, positive for left side
| offset). The resolution of the buffer around each vertex of the object
| increases by increasing the `quad_segs` keyword parameter.
|
| The join style is for outside corners between line segments. Accepted
| values are JOIN_STYLE.round (1), JOIN_STYLE.mitre (2), and
| JOIN_STYLE.bevel (3).
|
| The mitre ratio limit is used for very sharp corners. It 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
| far beyond 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.
|
| Note: the behaviour regarding orientation of the resulting line
| depends on the GEOS version. With GEOS < 3.11, the line retains the
| same direction for a left offset (positive distance) or has reverse
| direction for a right offset (negative distance), and this behaviour
| was documented as such in previous Shapely versions. Starting with
| GEOS 3.11, the function tries to preserve the orientation of the
| original line.
|
| parallel_offset(self, distance, side='right', resolution=16, join_style=<BufferJoinStyle.round: 1>, mitre_limit=5.0)
| Alternative method to :meth:`offset_curve` method.
|
| Older alternative method to the :meth:`offset_curve` method, but uses
| ``resolution`` instead of ``quad_segs`` and a ``side`` keyword
| ('left' or 'right') instead of sign of the distance. This method is
| kept for backwards compatibility for now, but is is recommended to
| use :meth:`offset_curve` instead.
|
| svg(self, scale_factor=1.0, stroke_color=None, opacity=None)
| Return SVG polyline element for the LineString geometry.
|
| Parameters
| ----------
| scale_factor : float
| Multiplication factor for the SVG stroke-width. Default is 1.
| stroke_color : str, optional
| Hex string for stroke color. Default is to use "#66cc99" if
| geometry is valid, and "#ff3333" if invalid.
| opacity : float
| Float number between 0 and 1 for color opacity. Default value is 0.8
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(self, coordinates=None)
| Create a new LineString geometry.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __geo_interface__
| Return a GeoJSON-like mapping of the LineString geometry.
|
| xy
| Separate arrays of X and Y coordinate values.
|
| Examples
| --------
| >>> from shapely import LineString
| >>> x, y = LineString([(0, 0), (1, 1)]).xy
| >>> list(x)
| [0.0, 1.0]
| >>> list(y)
| [0.0, 1.0]
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.geometry.base.BaseGeometry:
|
| __and__(self, other)
| Return the intersection of the geometries.
|
| __bool__(self)
| Return True if the geometry is not empty, else False.
|
| __format__(self, format_spec)
| Format a geometry using a format specification.
|
| __nonzero__(self)
| Return True if the geometry is not empty, else False.
|
| __or__(self, other)
| Return the union of the geometries.
|
| __reduce__(self)
| Pickle support.
|
| __repr__(self)
| Return a string representation of the geometry.
|
| __str__(self)
| Return a string representation of the geometry.
|
| __sub__(self, other)
| Return the difference of the geometries.
|
| __xor__(self, other)
| Return the symmetric difference of the geometries.
|
| buffer(self, 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.
| quad_segs : int, optional
| Sets the number of line segments used to approximate an
| angle fillet.
| cap_style : shapely.BufferCapStyle or {'round', 'square', 'flat'}, 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 {'round', 'mitre', 'bevel'}, 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_sided : 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, resolution : int, optional
| Deprecated aliases for `quad_segs`.
| **kwargs : dict, optional
| For backwards compatibility of renamed parameters. If an unsupported
| kwarg is passed, a `ValueError` will be raised.
|
| Returns
| -------
| Geometry
|
| Notes
| -----
| The return value is a strictly two-dimensional geometry. All
| Z coordinates of the original geometry will be ignored.
|
| .. deprecated:: 2.1.0
| A deprecation warning is shown if ``quad_segs``, ``cap_style``,
| ``join_style``, ``mitre_limit`` or ``single_sided`` are
| specified as positional arguments. In a future release, these will
| need to be specified as keyword arguments.
|
| Examples
| --------
| >>> from shapely import BufferCapStyle
| >>> 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.1365484905459398
|
| 128-gon approximation:
|
| >>> g.buffer(1.0, 128).area
| 3.1415138011443013
|
| triangle approximation:
|
| >>> g.buffer(1.0, 3).area
| 3.0
| >>> list(g.buffer(1.0, cap_style=BufferCapStyle.square).exterior.coords)
| [(1.0, 1.0), (1.0, -1.0), (-1.0, -1.0), (-1.0, 1.0), (1.0, 1.0)]
| >>> g.buffer(1.0, cap_style=BufferCapStyle.square).area
| 4.0
|
| contains(self, other)
| Return True if the geometry contains the other, else False.
|
| contains_properly(self, other)
| Return True if the geometry completely contains the other.
|
| There should be no common boundary points.
|
| Refer to `shapely.contains_properly` for full documentation.
|
| covered_by(self, other)
| Return True if the geometry is covered by the other, else False.
|
| covers(self, other)
| Return True if the geometry covers the other, else False.
|
| crosses(self, other)
| Return True if the geometries cross, else False.
|
| difference(self, other, grid_size=None)
| Return the difference of the geometries.
|
| Refer to `shapely.difference` for full documentation.
|
| disjoint(self, other)
| Return True if geometries are disjoint, else False.
|
| distance(self, other)
| Unitless distance to other geometry (float).
|
| dwithin(self, other, distance)
| Return True if geometry is within a given distance from the other.
|
| Refer to `shapely.dwithin` for full documentation.
|
| equals(self, other)
| 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)).
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals(
| ... LineString([(0, 0), (1, 1), (2, 2)])
| ... )
| True
|
| Returns
| -------
| bool
|
| equals_exact(self, other, tolerance=0.0, *, normalize=False)
| Return True if the geometries are equivalent within the tolerance.
|
| Refer to :func:`~shapely.equals_exact` for full documentation.
|
| Parameters
| ----------
| other : BaseGeometry
| The other geometry object in this comparison.
| tolerance : float, optional (default: 0.)
| Absolute tolerance in the same units as coordinates.
| normalize : bool, optional (default: False)
| If True, normalize the two geometries so that the coordinates are
| in the same order.
|
| .. versionadded:: 2.1.0
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals_exact(
| ... LineString([(0, 0), (1, 1), (2, 2)]),
| ... 1e-6
| ... )
| False
|
| Returns
| -------
| bool
|
| geometryType(self)
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| hausdorff_distance(self, other)
| Unitless hausdorff distance to other geometry (float).
|
| interpolate(self, distance, normalized=False)
| 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`.
|
| intersection(self, other, grid_size=None)
| Return the intersection of the geometries.
|
| Refer to `shapely.intersection` for full documentation.
|
| intersects(self, other)
| Return True if geometries intersect, else False.
|
| line_interpolate_point(self, distance, normalized=False)
| 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`.
|
| line_locate_point(self, other, normalized=False)
| 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`.
|
| normalize(self)
| 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`).
|
| Examples
| --------
| >>> from shapely import MultiLineString
| >>> line = MultiLineString([[(0, 0), (1, 1)], [(3, 3), (2, 2)]])
| >>> line.normalize()
| <MULTILINESTRING ((2 2, 3 3), (0 0, 1 1))>
|
| overlaps(self, other)
| Return True if geometries overlap, else False.
|
| point_on_surface(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `representative_point`.
|
| project(self, other, normalized=False)
| 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`.
|
| relate(self, other)
| Return the DE-9IM intersection matrix for the two geometries (string).
|
| relate_pattern(self, other, pattern)
| Return True if the DE-9IM relationship code satisfies the pattern.
|
| representative_point(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `point_on_surface`.
|
| reverse(self)
| Return a copy of this geometry with the order of coordinates reversed.
|
| If the geometry is a polygon with interior rings, the interior rings are also
| reversed.
|
| Points are unchanged.
|
| See Also
| --------
| is_ccw : Checks if a geometry is clockwise.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (1, 2)]).reverse()
| <LINESTRING (1 2, 0 0)>
| >>> Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]).reverse()
| <POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
|
| segmentize(self, max_segment_length)
| 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.
|
| Parameters
| ----------
| max_segment_length : float or array_like
| Additional vertices will be added so that all line segments are no
| longer this value. Must be greater than 0.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (0, 10)]).segmentize(max_segment_length=5)
| <LINESTRING (0 0, 0 5, 0 10)>
| >>> Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]).segmentize(max_segment_length=5)
| <POLYGON ((0 0, 5 0, 10 0, 10 5, 10 10, 5 10, 0 10, 0 5, 0 0))>
|
| simplify(self, tolerance, preserve_topology=True)
| 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.
|
| symmetric_difference(self, other, grid_size=None)
| Return the symmetric difference of the geometries.
|
| Refer to `shapely.symmetric_difference` for full documentation.
|
| touches(self, other)
| Return True if geometries touch, else False.
|
| union(self, other, grid_size=None)
| Return the union of the geometries.
|
| Refer to `shapely.union` for full documentation.
|
| within(self, other)
| Return True if geometry is within the other, else False.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from shapely.geometry.base.BaseGeometry:
|
| area
| Unitless area of the geometry (float).
|
| 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.
|
| bounds
| Return minimum bounding region (minx, miny, maxx, maxy).
|
| centroid
| Return the geometric center of the object.
|
| 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.
|
| coords
| Access to geometry's coordinates (CoordinateSequence).
|
| envelope
| A figure that envelopes the geometry.
|
| geom_type
| Name of the geometry's type, such as 'Point'.
|
| has_m
| True if the geometry's coordinate sequence(s) have m values.
|
| has_z
| True if the geometry's coordinate sequence(s) have z values.
|
| is_closed
| True if the geometry is closed, else False.
|
| Applicable only to linear geometries.
|
| is_empty
| True if the set of points in this geometry is empty, else False.
|
| is_ring
| True if the geometry is a closed ring, else False.
|
| is_simple
| True if the geometry is simple.
|
| Simple means that any self-intersections are only at boundary points.
|
| is_valid
| True if the geometry is valid.
|
| The definition depends on sub-class.
|
| length
| Unitless length of the geometry (float).
|
| minimum_clearance
| Unitless distance a node can be moved to produce an invalid geometry (float).
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `oriented_envelope`.
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `minimum_rotated_rectangle`.
|
| type
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| wkb
| WKB representation of the geometry.
|
| wkb_hex
| WKB hex representation of the geometry.
|
| wkt
| WKT representation of the geometry.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.lib.Geometry:
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __setstate__(...)
| For unpickling pre-shapely 2.0 pickles
shapely.LinearRing
Python Library Documentation: class LinearRing in module shapely.geometry.polygon
class LinearRing(shapely.geometry.linestring.LineString)
| LinearRing(coordinates=None)
|
| Geometry type composed of one or more line segments that forms a closed loop.
|
| A LinearRing is a closed, one-dimensional feature.
| A LinearRing that crosses itself or touches itself at a single point is
| invalid and operations on it may fail.
|
| Parameters
| ----------
| coordinates : 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.
|
| Notes
| -----
| Rings are automatically closed. There is no need to specify a final
| coordinate pair identical to the first.
|
| Examples
| --------
| Construct a square ring.
|
| >>> from shapely import LinearRing
| >>> ring = LinearRing( ((0, 0), (0, 1), (1 ,1 ), (1 , 0)) )
| >>> ring.is_closed
| True
| >>> list(ring.coords)
| [(0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0), (0.0, 0.0)]
| >>> ring.length
| 4.0
|
| Method resolution order:
| LinearRing
| shapely.geometry.linestring.LineString
| shapely.geometry.base.BaseGeometry
| shapely.lib.Geometry
| builtins.object
|
| Methods defined here:
|
| __reduce__(self)
| Pickle support.
|
| WKB doesn't differentiate between LineString and LinearRing so we
| need to move the coordinate sequence into the correct geometry type
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(self, coordinates=None)
| Create a new LinearRing geometry.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __geo_interface__
| Return a GeoJSON-like mapping of the LinearRing geometry.
|
| is_ccw
| True if the ring is oriented counter clock-wise.
|
| is_simple
| True if the geometry is simple.
|
| Simple means that any self-intersections are only at boundary points.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.geometry.linestring.LineString:
|
| offset_curve(self, distance, quad_segs=16, join_style=<BufferJoinStyle.round: 1>, mitre_limit=5.0)
| Return a (Multi)LineString at a distance from the object.
|
| The side, left or right, is determined by the sign of the `distance`
| parameter (negative for right side offset, positive for left side
| offset). The resolution of the buffer around each vertex of the object
| increases by increasing the `quad_segs` keyword parameter.
|
| The join style is for outside corners between line segments. Accepted
| values are JOIN_STYLE.round (1), JOIN_STYLE.mitre (2), and
| JOIN_STYLE.bevel (3).
|
| The mitre ratio limit is used for very sharp corners. It 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
| far beyond 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.
|
| Note: the behaviour regarding orientation of the resulting line
| depends on the GEOS version. With GEOS < 3.11, the line retains the
| same direction for a left offset (positive distance) or has reverse
| direction for a right offset (negative distance), and this behaviour
| was documented as such in previous Shapely versions. Starting with
| GEOS 3.11, the function tries to preserve the orientation of the
| original line.
|
| parallel_offset(self, distance, side='right', resolution=16, join_style=<BufferJoinStyle.round: 1>, mitre_limit=5.0)
| Alternative method to :meth:`offset_curve` method.
|
| Older alternative method to the :meth:`offset_curve` method, but uses
| ``resolution`` instead of ``quad_segs`` and a ``side`` keyword
| ('left' or 'right') instead of sign of the distance. This method is
| kept for backwards compatibility for now, but is is recommended to
| use :meth:`offset_curve` instead.
|
| svg(self, scale_factor=1.0, stroke_color=None, opacity=None)
| Return SVG polyline element for the LineString geometry.
|
| Parameters
| ----------
| scale_factor : float
| Multiplication factor for the SVG stroke-width. Default is 1.
| stroke_color : str, optional
| Hex string for stroke color. Default is to use "#66cc99" if
| geometry is valid, and "#ff3333" if invalid.
| opacity : float
| Float number between 0 and 1 for color opacity. Default value is 0.8
|
| ----------------------------------------------------------------------
| Readonly properties inherited from shapely.geometry.linestring.LineString:
|
| xy
| Separate arrays of X and Y coordinate values.
|
| Examples
| --------
| >>> from shapely import LineString
| >>> x, y = LineString([(0, 0), (1, 1)]).xy
| >>> list(x)
| [0.0, 1.0]
| >>> list(y)
| [0.0, 1.0]
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.geometry.base.BaseGeometry:
|
| __and__(self, other)
| Return the intersection of the geometries.
|
| __bool__(self)
| Return True if the geometry is not empty, else False.
|
| __format__(self, format_spec)
| Format a geometry using a format specification.
|
| __nonzero__(self)
| Return True if the geometry is not empty, else False.
|
| __or__(self, other)
| Return the union of the geometries.
|
| __repr__(self)
| Return a string representation of the geometry.
|
| __str__(self)
| Return a string representation of the geometry.
|
| __sub__(self, other)
| Return the difference of the geometries.
|
| __xor__(self, other)
| Return the symmetric difference of the geometries.
|
| buffer(self, 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.
| quad_segs : int, optional
| Sets the number of line segments used to approximate an
| angle fillet.
| cap_style : shapely.BufferCapStyle or {'round', 'square', 'flat'}, 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 {'round', 'mitre', 'bevel'}, 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_sided : 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, resolution : int, optional
| Deprecated aliases for `quad_segs`.
| **kwargs : dict, optional
| For backwards compatibility of renamed parameters. If an unsupported
| kwarg is passed, a `ValueError` will be raised.
|
| Returns
| -------
| Geometry
|
| Notes
| -----
| The return value is a strictly two-dimensional geometry. All
| Z coordinates of the original geometry will be ignored.
|
| .. deprecated:: 2.1.0
| A deprecation warning is shown if ``quad_segs``, ``cap_style``,
| ``join_style``, ``mitre_limit`` or ``single_sided`` are
| specified as positional arguments. In a future release, these will
| need to be specified as keyword arguments.
|
| Examples
| --------
| >>> from shapely import BufferCapStyle
| >>> 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.1365484905459398
|
| 128-gon approximation:
|
| >>> g.buffer(1.0, 128).area
| 3.1415138011443013
|
| triangle approximation:
|
| >>> g.buffer(1.0, 3).area
| 3.0
| >>> list(g.buffer(1.0, cap_style=BufferCapStyle.square).exterior.coords)
| [(1.0, 1.0), (1.0, -1.0), (-1.0, -1.0), (-1.0, 1.0), (1.0, 1.0)]
| >>> g.buffer(1.0, cap_style=BufferCapStyle.square).area
| 4.0
|
| contains(self, other)
| Return True if the geometry contains the other, else False.
|
| contains_properly(self, other)
| Return True if the geometry completely contains the other.
|
| There should be no common boundary points.
|
| Refer to `shapely.contains_properly` for full documentation.
|
| covered_by(self, other)
| Return True if the geometry is covered by the other, else False.
|
| covers(self, other)
| Return True if the geometry covers the other, else False.
|
| crosses(self, other)
| Return True if the geometries cross, else False.
|
| difference(self, other, grid_size=None)
| Return the difference of the geometries.
|
| Refer to `shapely.difference` for full documentation.
|
| disjoint(self, other)
| Return True if geometries are disjoint, else False.
|
| distance(self, other)
| Unitless distance to other geometry (float).
|
| dwithin(self, other, distance)
| Return True if geometry is within a given distance from the other.
|
| Refer to `shapely.dwithin` for full documentation.
|
| equals(self, other)
| 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)).
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals(
| ... LineString([(0, 0), (1, 1), (2, 2)])
| ... )
| True
|
| Returns
| -------
| bool
|
| equals_exact(self, other, tolerance=0.0, *, normalize=False)
| Return True if the geometries are equivalent within the tolerance.
|
| Refer to :func:`~shapely.equals_exact` for full documentation.
|
| Parameters
| ----------
| other : BaseGeometry
| The other geometry object in this comparison.
| tolerance : float, optional (default: 0.)
| Absolute tolerance in the same units as coordinates.
| normalize : bool, optional (default: False)
| If True, normalize the two geometries so that the coordinates are
| in the same order.
|
| .. versionadded:: 2.1.0
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals_exact(
| ... LineString([(0, 0), (1, 1), (2, 2)]),
| ... 1e-6
| ... )
| False
|
| Returns
| -------
| bool
|
| geometryType(self)
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| hausdorff_distance(self, other)
| Unitless hausdorff distance to other geometry (float).
|
| interpolate(self, distance, normalized=False)
| 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`.
|
| intersection(self, other, grid_size=None)
| Return the intersection of the geometries.
|
| Refer to `shapely.intersection` for full documentation.
|
| intersects(self, other)
| Return True if geometries intersect, else False.
|
| line_interpolate_point(self, distance, normalized=False)
| 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`.
|
| line_locate_point(self, other, normalized=False)
| 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`.
|
| normalize(self)
| 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`).
|
| Examples
| --------
| >>> from shapely import MultiLineString
| >>> line = MultiLineString([[(0, 0), (1, 1)], [(3, 3), (2, 2)]])
| >>> line.normalize()
| <MULTILINESTRING ((2 2, 3 3), (0 0, 1 1))>
|
| overlaps(self, other)
| Return True if geometries overlap, else False.
|
| point_on_surface(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `representative_point`.
|
| project(self, other, normalized=False)
| 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`.
|
| relate(self, other)
| Return the DE-9IM intersection matrix for the two geometries (string).
|
| relate_pattern(self, other, pattern)
| Return True if the DE-9IM relationship code satisfies the pattern.
|
| representative_point(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `point_on_surface`.
|
| reverse(self)
| Return a copy of this geometry with the order of coordinates reversed.
|
| If the geometry is a polygon with interior rings, the interior rings are also
| reversed.
|
| Points are unchanged.
|
| See Also
| --------
| is_ccw : Checks if a geometry is clockwise.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (1, 2)]).reverse()
| <LINESTRING (1 2, 0 0)>
| >>> Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]).reverse()
| <POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
|
| segmentize(self, max_segment_length)
| 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.
|
| Parameters
| ----------
| max_segment_length : float or array_like
| Additional vertices will be added so that all line segments are no
| longer this value. Must be greater than 0.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (0, 10)]).segmentize(max_segment_length=5)
| <LINESTRING (0 0, 0 5, 0 10)>
| >>> Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]).segmentize(max_segment_length=5)
| <POLYGON ((0 0, 5 0, 10 0, 10 5, 10 10, 5 10, 0 10, 0 5, 0 0))>
|
| simplify(self, tolerance, preserve_topology=True)
| 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.
|
| symmetric_difference(self, other, grid_size=None)
| Return the symmetric difference of the geometries.
|
| Refer to `shapely.symmetric_difference` for full documentation.
|
| touches(self, other)
| Return True if geometries touch, else False.
|
| union(self, other, grid_size=None)
| Return the union of the geometries.
|
| Refer to `shapely.union` for full documentation.
|
| within(self, other)
| Return True if geometry is within the other, else False.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from shapely.geometry.base.BaseGeometry:
|
| area
| Unitless area of the geometry (float).
|
| 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.
|
| bounds
| Return minimum bounding region (minx, miny, maxx, maxy).
|
| centroid
| Return the geometric center of the object.
|
| 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.
|
| coords
| Access to geometry's coordinates (CoordinateSequence).
|
| envelope
| A figure that envelopes the geometry.
|
| geom_type
| Name of the geometry's type, such as 'Point'.
|
| has_m
| True if the geometry's coordinate sequence(s) have m values.
|
| has_z
| True if the geometry's coordinate sequence(s) have z values.
|
| is_closed
| True if the geometry is closed, else False.
|
| Applicable only to linear geometries.
|
| is_empty
| True if the set of points in this geometry is empty, else False.
|
| is_ring
| True if the geometry is a closed ring, else False.
|
| is_valid
| True if the geometry is valid.
|
| The definition depends on sub-class.
|
| length
| Unitless length of the geometry (float).
|
| minimum_clearance
| Unitless distance a node can be moved to produce an invalid geometry (float).
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `oriented_envelope`.
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `minimum_rotated_rectangle`.
|
| type
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| wkb
| WKB representation of the geometry.
|
| wkb_hex
| WKB hex representation of the geometry.
|
| wkt
| WKT representation of the geometry.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.lib.Geometry:
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __setstate__(...)
| For unpickling pre-shapely 2.0 pickles
shapely.MultiLineString
Python Library Documentation: class MultiLineString in module shapely.geometry.multilinestring
class MultiLineString(shapely.geometry.base.BaseMultipartGeometry)
| MultiLineString(lines=None)
|
| A collection of one or more LineStrings.
|
| A MultiLineString has non-zero length and zero area.
|
| Parameters
| ----------
| lines : sequence
| A sequence LineStrings, or a sequence of line-like coordinate
| sequences or array-likes (see accepted input for LineString).
|
| Attributes
| ----------
| geoms : sequence
| A sequence of LineStrings
|
| Examples
| --------
| Construct a MultiLineString containing two LineStrings.
|
| >>> from shapely import MultiLineString
| >>> lines = MultiLineString([[[0, 0], [1, 2]], [[4, 4], [5, 6]]])
|
| Method resolution order:
| MultiLineString
| shapely.geometry.base.BaseMultipartGeometry
| shapely.geometry.base.BaseGeometry
| shapely.lib.Geometry
| builtins.object
|
| Methods defined here:
|
| svg(self, scale_factor=1.0, stroke_color=None, opacity=None)
| Return a group of SVG polyline elements for the LineString geometry.
|
| Parameters
| ----------
| scale_factor : float
| Multiplication factor for the SVG stroke-width. Default is 1.
| stroke_color : str, optional
| Hex string for stroke color. Default is to use "#66cc99" if
| geometry is valid, and "#ff3333" if invalid.
| opacity : float
| Float number between 0 and 1 for color opacity. Default value is 0.8
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(self, lines=None)
| Create a new MultiLineString geometry.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __geo_interface__
| Return a GeoJSON-like mapping interface for this MultiLineString.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.geometry.base.BaseMultipartGeometry:
|
| __bool__(self)
| Return True if the geometry is not empty, else False.
|
| __eq__(self, other)
| Return True if geometries are equal, else False.
|
| __hash__(self)
| Return the hash value of the geometry.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from shapely.geometry.base.BaseMultipartGeometry:
|
| coords
| Not implemented.
|
| Sub-geometries may have coordinate sequences, but multi-part geometries
| do not.
|
| geoms
| Access to the contained geometries.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.geometry.base.BaseGeometry:
|
| __and__(self, other)
| Return the intersection of the geometries.
|
| __format__(self, format_spec)
| Format a geometry using a format specification.
|
| __nonzero__(self)
| Return True if the geometry is not empty, else False.
|
| __or__(self, other)
| Return the union of the geometries.
|
| __reduce__(self)
| Pickle support.
|
| __repr__(self)
| Return a string representation of the geometry.
|
| __str__(self)
| Return a string representation of the geometry.
|
| __sub__(self, other)
| Return the difference of the geometries.
|
| __xor__(self, other)
| Return the symmetric difference of the geometries.
|
| buffer(self, 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.
| quad_segs : int, optional
| Sets the number of line segments used to approximate an
| angle fillet.
| cap_style : shapely.BufferCapStyle or {'round', 'square', 'flat'}, 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 {'round', 'mitre', 'bevel'}, 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_sided : 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, resolution : int, optional
| Deprecated aliases for `quad_segs`.
| **kwargs : dict, optional
| For backwards compatibility of renamed parameters. If an unsupported
| kwarg is passed, a `ValueError` will be raised.
|
| Returns
| -------
| Geometry
|
| Notes
| -----
| The return value is a strictly two-dimensional geometry. All
| Z coordinates of the original geometry will be ignored.
|
| .. deprecated:: 2.1.0
| A deprecation warning is shown if ``quad_segs``, ``cap_style``,
| ``join_style``, ``mitre_limit`` or ``single_sided`` are
| specified as positional arguments. In a future release, these will
| need to be specified as keyword arguments.
|
| Examples
| --------
| >>> from shapely import BufferCapStyle
| >>> 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.1365484905459398
|
| 128-gon approximation:
|
| >>> g.buffer(1.0, 128).area
| 3.1415138011443013
|
| triangle approximation:
|
| >>> g.buffer(1.0, 3).area
| 3.0
| >>> list(g.buffer(1.0, cap_style=BufferCapStyle.square).exterior.coords)
| [(1.0, 1.0), (1.0, -1.0), (-1.0, -1.0), (-1.0, 1.0), (1.0, 1.0)]
| >>> g.buffer(1.0, cap_style=BufferCapStyle.square).area
| 4.0
|
| contains(self, other)
| Return True if the geometry contains the other, else False.
|
| contains_properly(self, other)
| Return True if the geometry completely contains the other.
|
| There should be no common boundary points.
|
| Refer to `shapely.contains_properly` for full documentation.
|
| covered_by(self, other)
| Return True if the geometry is covered by the other, else False.
|
| covers(self, other)
| Return True if the geometry covers the other, else False.
|
| crosses(self, other)
| Return True if the geometries cross, else False.
|
| difference(self, other, grid_size=None)
| Return the difference of the geometries.
|
| Refer to `shapely.difference` for full documentation.
|
| disjoint(self, other)
| Return True if geometries are disjoint, else False.
|
| distance(self, other)
| Unitless distance to other geometry (float).
|
| dwithin(self, other, distance)
| Return True if geometry is within a given distance from the other.
|
| Refer to `shapely.dwithin` for full documentation.
|
| equals(self, other)
| 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)).
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals(
| ... LineString([(0, 0), (1, 1), (2, 2)])
| ... )
| True
|
| Returns
| -------
| bool
|
| equals_exact(self, other, tolerance=0.0, *, normalize=False)
| Return True if the geometries are equivalent within the tolerance.
|
| Refer to :func:`~shapely.equals_exact` for full documentation.
|
| Parameters
| ----------
| other : BaseGeometry
| The other geometry object in this comparison.
| tolerance : float, optional (default: 0.)
| Absolute tolerance in the same units as coordinates.
| normalize : bool, optional (default: False)
| If True, normalize the two geometries so that the coordinates are
| in the same order.
|
| .. versionadded:: 2.1.0
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals_exact(
| ... LineString([(0, 0), (1, 1), (2, 2)]),
| ... 1e-6
| ... )
| False
|
| Returns
| -------
| bool
|
| geometryType(self)
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| hausdorff_distance(self, other)
| Unitless hausdorff distance to other geometry (float).
|
| interpolate(self, distance, normalized=False)
| 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`.
|
| intersection(self, other, grid_size=None)
| Return the intersection of the geometries.
|
| Refer to `shapely.intersection` for full documentation.
|
| intersects(self, other)
| Return True if geometries intersect, else False.
|
| line_interpolate_point(self, distance, normalized=False)
| 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`.
|
| line_locate_point(self, other, normalized=False)
| 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`.
|
| normalize(self)
| 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`).
|
| Examples
| --------
| >>> from shapely import MultiLineString
| >>> line = MultiLineString([[(0, 0), (1, 1)], [(3, 3), (2, 2)]])
| >>> line.normalize()
| <MULTILINESTRING ((2 2, 3 3), (0 0, 1 1))>
|
| overlaps(self, other)
| Return True if geometries overlap, else False.
|
| point_on_surface(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `representative_point`.
|
| project(self, other, normalized=False)
| 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`.
|
| relate(self, other)
| Return the DE-9IM intersection matrix for the two geometries (string).
|
| relate_pattern(self, other, pattern)
| Return True if the DE-9IM relationship code satisfies the pattern.
|
| representative_point(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `point_on_surface`.
|
| reverse(self)
| Return a copy of this geometry with the order of coordinates reversed.
|
| If the geometry is a polygon with interior rings, the interior rings are also
| reversed.
|
| Points are unchanged.
|
| See Also
| --------
| is_ccw : Checks if a geometry is clockwise.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (1, 2)]).reverse()
| <LINESTRING (1 2, 0 0)>
| >>> Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]).reverse()
| <POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
|
| segmentize(self, max_segment_length)
| 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.
|
| Parameters
| ----------
| max_segment_length : float or array_like
| Additional vertices will be added so that all line segments are no
| longer this value. Must be greater than 0.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (0, 10)]).segmentize(max_segment_length=5)
| <LINESTRING (0 0, 0 5, 0 10)>
| >>> Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]).segmentize(max_segment_length=5)
| <POLYGON ((0 0, 5 0, 10 0, 10 5, 10 10, 5 10, 0 10, 0 5, 0 0))>
|
| simplify(self, tolerance, preserve_topology=True)
| 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.
|
| symmetric_difference(self, other, grid_size=None)
| Return the symmetric difference of the geometries.
|
| Refer to `shapely.symmetric_difference` for full documentation.
|
| touches(self, other)
| Return True if geometries touch, else False.
|
| union(self, other, grid_size=None)
| Return the union of the geometries.
|
| Refer to `shapely.union` for full documentation.
|
| within(self, other)
| Return True if geometry is within the other, else False.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from shapely.geometry.base.BaseGeometry:
|
| area
| Unitless area of the geometry (float).
|
| 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.
|
| bounds
| Return minimum bounding region (minx, miny, maxx, maxy).
|
| centroid
| Return the geometric center of the object.
|
| 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.
|
| envelope
| A figure that envelopes the geometry.
|
| geom_type
| Name of the geometry's type, such as 'Point'.
|
| has_m
| True if the geometry's coordinate sequence(s) have m values.
|
| has_z
| True if the geometry's coordinate sequence(s) have z values.
|
| is_closed
| True if the geometry is closed, else False.
|
| Applicable only to linear geometries.
|
| is_empty
| True if the set of points in this geometry is empty, else False.
|
| is_ring
| True if the geometry is a closed ring, else False.
|
| is_simple
| True if the geometry is simple.
|
| Simple means that any self-intersections are only at boundary points.
|
| is_valid
| True if the geometry is valid.
|
| The definition depends on sub-class.
|
| length
| Unitless length of the geometry (float).
|
| minimum_clearance
| Unitless distance a node can be moved to produce an invalid geometry (float).
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `oriented_envelope`.
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `minimum_rotated_rectangle`.
|
| type
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| wkb
| WKB representation of the geometry.
|
| wkb_hex
| WKB hex representation of the geometry.
|
| wkt
| WKT representation of the geometry.
|
| xy
| Separate arrays of X and Y coordinate values.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.lib.Geometry:
|
| __ge__(self, value, /)
| Return self>=value.
|
| __gt__(self, value, /)
| Return self>value.
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __setstate__(...)
| For unpickling pre-shapely 2.0 pickles
shapely.MultiPoint
Python Library Documentation: class MultiPoint in module shapely.geometry.multipoint
class MultiPoint(shapely.geometry.base.BaseMultipartGeometry)
| MultiPoint(points=None)
|
| A collection of one or more Points.
|
| A MultiPoint has zero area and zero length.
|
| Parameters
| ----------
| points : sequence
| A sequence of Points, or a sequence of (x, y [,z]) numeric coordinate
| pairs or triples, or an array-like of shape (N, 2) or (N, 3).
|
| Attributes
| ----------
| geoms : sequence
| A sequence of Points
|
| Examples
| --------
| Construct a MultiPoint containing two Points
|
| >>> from shapely import MultiPoint, Point
| >>> ob = MultiPoint([[0.0, 0.0], [1.0, 2.0]])
| >>> len(ob.geoms)
| 2
| >>> type(ob.geoms[0]) == Point
| True
|
| Method resolution order:
| MultiPoint
| shapely.geometry.base.BaseMultipartGeometry
| shapely.geometry.base.BaseGeometry
| shapely.lib.Geometry
| builtins.object
|
| Methods defined here:
|
| svg(self, scale_factor=1.0, fill_color=None, opacity=None)
| Return a group of SVG circle elements for the MultiPoint geometry.
|
| Parameters
| ----------
| scale_factor : float
| Multiplication factor for the SVG circle diameters. Default is 1.
| fill_color : str, optional
| Hex string for fill color. Default is to use "#66cc99" if
| geometry is valid, and "#ff3333" if invalid.
| opacity : float
| Float number between 0 and 1 for color opacity. Default value is 0.6
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(self, points=None)
| Create a new MultiPoint geometry.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __geo_interface__
| Return a GeoJSON-like mapping interface for this MultiPoint.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.geometry.base.BaseMultipartGeometry:
|
| __bool__(self)
| Return True if the geometry is not empty, else False.
|
| __eq__(self, other)
| Return True if geometries are equal, else False.
|
| __hash__(self)
| Return the hash value of the geometry.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from shapely.geometry.base.BaseMultipartGeometry:
|
| coords
| Not implemented.
|
| Sub-geometries may have coordinate sequences, but multi-part geometries
| do not.
|
| geoms
| Access to the contained geometries.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.geometry.base.BaseGeometry:
|
| __and__(self, other)
| Return the intersection of the geometries.
|
| __format__(self, format_spec)
| Format a geometry using a format specification.
|
| __nonzero__(self)
| Return True if the geometry is not empty, else False.
|
| __or__(self, other)
| Return the union of the geometries.
|
| __reduce__(self)
| Pickle support.
|
| __repr__(self)
| Return a string representation of the geometry.
|
| __str__(self)
| Return a string representation of the geometry.
|
| __sub__(self, other)
| Return the difference of the geometries.
|
| __xor__(self, other)
| Return the symmetric difference of the geometries.
|
| buffer(self, 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.
| quad_segs : int, optional
| Sets the number of line segments used to approximate an
| angle fillet.
| cap_style : shapely.BufferCapStyle or {'round', 'square', 'flat'}, 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 {'round', 'mitre', 'bevel'}, 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_sided : 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, resolution : int, optional
| Deprecated aliases for `quad_segs`.
| **kwargs : dict, optional
| For backwards compatibility of renamed parameters. If an unsupported
| kwarg is passed, a `ValueError` will be raised.
|
| Returns
| -------
| Geometry
|
| Notes
| -----
| The return value is a strictly two-dimensional geometry. All
| Z coordinates of the original geometry will be ignored.
|
| .. deprecated:: 2.1.0
| A deprecation warning is shown if ``quad_segs``, ``cap_style``,
| ``join_style``, ``mitre_limit`` or ``single_sided`` are
| specified as positional arguments. In a future release, these will
| need to be specified as keyword arguments.
|
| Examples
| --------
| >>> from shapely import BufferCapStyle
| >>> 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.1365484905459398
|
| 128-gon approximation:
|
| >>> g.buffer(1.0, 128).area
| 3.1415138011443013
|
| triangle approximation:
|
| >>> g.buffer(1.0, 3).area
| 3.0
| >>> list(g.buffer(1.0, cap_style=BufferCapStyle.square).exterior.coords)
| [(1.0, 1.0), (1.0, -1.0), (-1.0, -1.0), (-1.0, 1.0), (1.0, 1.0)]
| >>> g.buffer(1.0, cap_style=BufferCapStyle.square).area
| 4.0
|
| contains(self, other)
| Return True if the geometry contains the other, else False.
|
| contains_properly(self, other)
| Return True if the geometry completely contains the other.
|
| There should be no common boundary points.
|
| Refer to `shapely.contains_properly` for full documentation.
|
| covered_by(self, other)
| Return True if the geometry is covered by the other, else False.
|
| covers(self, other)
| Return True if the geometry covers the other, else False.
|
| crosses(self, other)
| Return True if the geometries cross, else False.
|
| difference(self, other, grid_size=None)
| Return the difference of the geometries.
|
| Refer to `shapely.difference` for full documentation.
|
| disjoint(self, other)
| Return True if geometries are disjoint, else False.
|
| distance(self, other)
| Unitless distance to other geometry (float).
|
| dwithin(self, other, distance)
| Return True if geometry is within a given distance from the other.
|
| Refer to `shapely.dwithin` for full documentation.
|
| equals(self, other)
| 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)).
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals(
| ... LineString([(0, 0), (1, 1), (2, 2)])
| ... )
| True
|
| Returns
| -------
| bool
|
| equals_exact(self, other, tolerance=0.0, *, normalize=False)
| Return True if the geometries are equivalent within the tolerance.
|
| Refer to :func:`~shapely.equals_exact` for full documentation.
|
| Parameters
| ----------
| other : BaseGeometry
| The other geometry object in this comparison.
| tolerance : float, optional (default: 0.)
| Absolute tolerance in the same units as coordinates.
| normalize : bool, optional (default: False)
| If True, normalize the two geometries so that the coordinates are
| in the same order.
|
| .. versionadded:: 2.1.0
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals_exact(
| ... LineString([(0, 0), (1, 1), (2, 2)]),
| ... 1e-6
| ... )
| False
|
| Returns
| -------
| bool
|
| geometryType(self)
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| hausdorff_distance(self, other)
| Unitless hausdorff distance to other geometry (float).
|
| interpolate(self, distance, normalized=False)
| 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`.
|
| intersection(self, other, grid_size=None)
| Return the intersection of the geometries.
|
| Refer to `shapely.intersection` for full documentation.
|
| intersects(self, other)
| Return True if geometries intersect, else False.
|
| line_interpolate_point(self, distance, normalized=False)
| 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`.
|
| line_locate_point(self, other, normalized=False)
| 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`.
|
| normalize(self)
| 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`).
|
| Examples
| --------
| >>> from shapely import MultiLineString
| >>> line = MultiLineString([[(0, 0), (1, 1)], [(3, 3), (2, 2)]])
| >>> line.normalize()
| <MULTILINESTRING ((2 2, 3 3), (0 0, 1 1))>
|
| overlaps(self, other)
| Return True if geometries overlap, else False.
|
| point_on_surface(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `representative_point`.
|
| project(self, other, normalized=False)
| 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`.
|
| relate(self, other)
| Return the DE-9IM intersection matrix for the two geometries (string).
|
| relate_pattern(self, other, pattern)
| Return True if the DE-9IM relationship code satisfies the pattern.
|
| representative_point(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `point_on_surface`.
|
| reverse(self)
| Return a copy of this geometry with the order of coordinates reversed.
|
| If the geometry is a polygon with interior rings, the interior rings are also
| reversed.
|
| Points are unchanged.
|
| See Also
| --------
| is_ccw : Checks if a geometry is clockwise.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (1, 2)]).reverse()
| <LINESTRING (1 2, 0 0)>
| >>> Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]).reverse()
| <POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
|
| segmentize(self, max_segment_length)
| 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.
|
| Parameters
| ----------
| max_segment_length : float or array_like
| Additional vertices will be added so that all line segments are no
| longer this value. Must be greater than 0.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (0, 10)]).segmentize(max_segment_length=5)
| <LINESTRING (0 0, 0 5, 0 10)>
| >>> Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]).segmentize(max_segment_length=5)
| <POLYGON ((0 0, 5 0, 10 0, 10 5, 10 10, 5 10, 0 10, 0 5, 0 0))>
|
| simplify(self, tolerance, preserve_topology=True)
| 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.
|
| symmetric_difference(self, other, grid_size=None)
| Return the symmetric difference of the geometries.
|
| Refer to `shapely.symmetric_difference` for full documentation.
|
| touches(self, other)
| Return True if geometries touch, else False.
|
| union(self, other, grid_size=None)
| Return the union of the geometries.
|
| Refer to `shapely.union` for full documentation.
|
| within(self, other)
| Return True if geometry is within the other, else False.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from shapely.geometry.base.BaseGeometry:
|
| area
| Unitless area of the geometry (float).
|
| 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.
|
| bounds
| Return minimum bounding region (minx, miny, maxx, maxy).
|
| centroid
| Return the geometric center of the object.
|
| 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.
|
| envelope
| A figure that envelopes the geometry.
|
| geom_type
| Name of the geometry's type, such as 'Point'.
|
| has_m
| True if the geometry's coordinate sequence(s) have m values.
|
| has_z
| True if the geometry's coordinate sequence(s) have z values.
|
| is_closed
| True if the geometry is closed, else False.
|
| Applicable only to linear geometries.
|
| is_empty
| True if the set of points in this geometry is empty, else False.
|
| is_ring
| True if the geometry is a closed ring, else False.
|
| is_simple
| True if the geometry is simple.
|
| Simple means that any self-intersections are only at boundary points.
|
| is_valid
| True if the geometry is valid.
|
| The definition depends on sub-class.
|
| length
| Unitless length of the geometry (float).
|
| minimum_clearance
| Unitless distance a node can be moved to produce an invalid geometry (float).
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `oriented_envelope`.
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `minimum_rotated_rectangle`.
|
| type
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| wkb
| WKB representation of the geometry.
|
| wkb_hex
| WKB hex representation of the geometry.
|
| wkt
| WKT representation of the geometry.
|
| xy
| Separate arrays of X and Y coordinate values.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.lib.Geometry:
|
| __ge__(self, value, /)
| Return self>=value.
|
| __gt__(self, value, /)
| Return self>value.
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __setstate__(...)
| For unpickling pre-shapely 2.0 pickles
shapely.MultiPolygon
Python Library Documentation: class MultiPolygon in module shapely.geometry.multipolygon
class MultiPolygon(shapely.geometry.base.BaseMultipartGeometry)
| MultiPolygon(polygons=None)
|
| A collection of one or more Polygons.
|
| If component polygons overlap the collection is invalid and some
| operations on it may fail.
|
| Parameters
| ----------
| polygons : sequence
| A sequence of Polygons, or a sequence of (shell, holes) tuples
| where shell is the sequence representation of a linear ring
| (see LinearRing) and holes is a sequence of such linear rings.
|
| Attributes
| ----------
| geoms : sequence
| A sequence of `Polygon` instances
|
| Examples
| --------
| Construct a MultiPolygon from a sequence of coordinate tuples
|
| >>> from shapely import MultiPolygon, Polygon
| >>> ob = MultiPolygon([
| ... (
| ... ((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)),
| ... [((0.1,0.1), (0.1,0.2), (0.2,0.2), (0.2,0.1))]
| ... )
| ... ])
| >>> len(ob.geoms)
| 1
| >>> type(ob.geoms[0]) == Polygon
| True
|
| Method resolution order:
| MultiPolygon
| shapely.geometry.base.BaseMultipartGeometry
| shapely.geometry.base.BaseGeometry
| shapely.lib.Geometry
| builtins.object
|
| Methods defined here:
|
| svg(self, scale_factor=1.0, fill_color=None, opacity=None)
| Return group of SVG path elements for the MultiPolygon geometry.
|
| Parameters
| ----------
| scale_factor : float
| Multiplication factor for the SVG stroke-width. Default is 1.
| fill_color : str, optional
| Hex string for fill color. Default is to use "#66cc99" if
| geometry is valid, and "#ff3333" if invalid.
| opacity : float
| Float number between 0 and 1 for color opacity. Default value is 0.6
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(self, polygons=None)
| Create a new MultiPolygon geometry.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __geo_interface__
| Return a GeoJSON-like mapping of the MultiPolygon geometry.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.geometry.base.BaseMultipartGeometry:
|
| __bool__(self)
| Return True if the geometry is not empty, else False.
|
| __eq__(self, other)
| Return True if geometries are equal, else False.
|
| __hash__(self)
| Return the hash value of the geometry.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from shapely.geometry.base.BaseMultipartGeometry:
|
| coords
| Not implemented.
|
| Sub-geometries may have coordinate sequences, but multi-part geometries
| do not.
|
| geoms
| Access to the contained geometries.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.geometry.base.BaseGeometry:
|
| __and__(self, other)
| Return the intersection of the geometries.
|
| __format__(self, format_spec)
| Format a geometry using a format specification.
|
| __nonzero__(self)
| Return True if the geometry is not empty, else False.
|
| __or__(self, other)
| Return the union of the geometries.
|
| __reduce__(self)
| Pickle support.
|
| __repr__(self)
| Return a string representation of the geometry.
|
| __str__(self)
| Return a string representation of the geometry.
|
| __sub__(self, other)
| Return the difference of the geometries.
|
| __xor__(self, other)
| Return the symmetric difference of the geometries.
|
| buffer(self, 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.
| quad_segs : int, optional
| Sets the number of line segments used to approximate an
| angle fillet.
| cap_style : shapely.BufferCapStyle or {'round', 'square', 'flat'}, 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 {'round', 'mitre', 'bevel'}, 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_sided : 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, resolution : int, optional
| Deprecated aliases for `quad_segs`.
| **kwargs : dict, optional
| For backwards compatibility of renamed parameters. If an unsupported
| kwarg is passed, a `ValueError` will be raised.
|
| Returns
| -------
| Geometry
|
| Notes
| -----
| The return value is a strictly two-dimensional geometry. All
| Z coordinates of the original geometry will be ignored.
|
| .. deprecated:: 2.1.0
| A deprecation warning is shown if ``quad_segs``, ``cap_style``,
| ``join_style``, ``mitre_limit`` or ``single_sided`` are
| specified as positional arguments. In a future release, these will
| need to be specified as keyword arguments.
|
| Examples
| --------
| >>> from shapely import BufferCapStyle
| >>> 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.1365484905459398
|
| 128-gon approximation:
|
| >>> g.buffer(1.0, 128).area
| 3.1415138011443013
|
| triangle approximation:
|
| >>> g.buffer(1.0, 3).area
| 3.0
| >>> list(g.buffer(1.0, cap_style=BufferCapStyle.square).exterior.coords)
| [(1.0, 1.0), (1.0, -1.0), (-1.0, -1.0), (-1.0, 1.0), (1.0, 1.0)]
| >>> g.buffer(1.0, cap_style=BufferCapStyle.square).area
| 4.0
|
| contains(self, other)
| Return True if the geometry contains the other, else False.
|
| contains_properly(self, other)
| Return True if the geometry completely contains the other.
|
| There should be no common boundary points.
|
| Refer to `shapely.contains_properly` for full documentation.
|
| covered_by(self, other)
| Return True if the geometry is covered by the other, else False.
|
| covers(self, other)
| Return True if the geometry covers the other, else False.
|
| crosses(self, other)
| Return True if the geometries cross, else False.
|
| difference(self, other, grid_size=None)
| Return the difference of the geometries.
|
| Refer to `shapely.difference` for full documentation.
|
| disjoint(self, other)
| Return True if geometries are disjoint, else False.
|
| distance(self, other)
| Unitless distance to other geometry (float).
|
| dwithin(self, other, distance)
| Return True if geometry is within a given distance from the other.
|
| Refer to `shapely.dwithin` for full documentation.
|
| equals(self, other)
| 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)).
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals(
| ... LineString([(0, 0), (1, 1), (2, 2)])
| ... )
| True
|
| Returns
| -------
| bool
|
| equals_exact(self, other, tolerance=0.0, *, normalize=False)
| Return True if the geometries are equivalent within the tolerance.
|
| Refer to :func:`~shapely.equals_exact` for full documentation.
|
| Parameters
| ----------
| other : BaseGeometry
| The other geometry object in this comparison.
| tolerance : float, optional (default: 0.)
| Absolute tolerance in the same units as coordinates.
| normalize : bool, optional (default: False)
| If True, normalize the two geometries so that the coordinates are
| in the same order.
|
| .. versionadded:: 2.1.0
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals_exact(
| ... LineString([(0, 0), (1, 1), (2, 2)]),
| ... 1e-6
| ... )
| False
|
| Returns
| -------
| bool
|
| geometryType(self)
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| hausdorff_distance(self, other)
| Unitless hausdorff distance to other geometry (float).
|
| interpolate(self, distance, normalized=False)
| 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`.
|
| intersection(self, other, grid_size=None)
| Return the intersection of the geometries.
|
| Refer to `shapely.intersection` for full documentation.
|
| intersects(self, other)
| Return True if geometries intersect, else False.
|
| line_interpolate_point(self, distance, normalized=False)
| 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`.
|
| line_locate_point(self, other, normalized=False)
| 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`.
|
| normalize(self)
| 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`).
|
| Examples
| --------
| >>> from shapely import MultiLineString
| >>> line = MultiLineString([[(0, 0), (1, 1)], [(3, 3), (2, 2)]])
| >>> line.normalize()
| <MULTILINESTRING ((2 2, 3 3), (0 0, 1 1))>
|
| overlaps(self, other)
| Return True if geometries overlap, else False.
|
| point_on_surface(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `representative_point`.
|
| project(self, other, normalized=False)
| 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`.
|
| relate(self, other)
| Return the DE-9IM intersection matrix for the two geometries (string).
|
| relate_pattern(self, other, pattern)
| Return True if the DE-9IM relationship code satisfies the pattern.
|
| representative_point(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `point_on_surface`.
|
| reverse(self)
| Return a copy of this geometry with the order of coordinates reversed.
|
| If the geometry is a polygon with interior rings, the interior rings are also
| reversed.
|
| Points are unchanged.
|
| See Also
| --------
| is_ccw : Checks if a geometry is clockwise.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (1, 2)]).reverse()
| <LINESTRING (1 2, 0 0)>
| >>> Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]).reverse()
| <POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
|
| segmentize(self, max_segment_length)
| 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.
|
| Parameters
| ----------
| max_segment_length : float or array_like
| Additional vertices will be added so that all line segments are no
| longer this value. Must be greater than 0.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (0, 10)]).segmentize(max_segment_length=5)
| <LINESTRING (0 0, 0 5, 0 10)>
| >>> Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]).segmentize(max_segment_length=5)
| <POLYGON ((0 0, 5 0, 10 0, 10 5, 10 10, 5 10, 0 10, 0 5, 0 0))>
|
| simplify(self, tolerance, preserve_topology=True)
| 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.
|
| symmetric_difference(self, other, grid_size=None)
| Return the symmetric difference of the geometries.
|
| Refer to `shapely.symmetric_difference` for full documentation.
|
| touches(self, other)
| Return True if geometries touch, else False.
|
| union(self, other, grid_size=None)
| Return the union of the geometries.
|
| Refer to `shapely.union` for full documentation.
|
| within(self, other)
| Return True if geometry is within the other, else False.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from shapely.geometry.base.BaseGeometry:
|
| area
| Unitless area of the geometry (float).
|
| 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.
|
| bounds
| Return minimum bounding region (minx, miny, maxx, maxy).
|
| centroid
| Return the geometric center of the object.
|
| 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.
|
| envelope
| A figure that envelopes the geometry.
|
| geom_type
| Name of the geometry's type, such as 'Point'.
|
| has_m
| True if the geometry's coordinate sequence(s) have m values.
|
| has_z
| True if the geometry's coordinate sequence(s) have z values.
|
| is_closed
| True if the geometry is closed, else False.
|
| Applicable only to linear geometries.
|
| is_empty
| True if the set of points in this geometry is empty, else False.
|
| is_ring
| True if the geometry is a closed ring, else False.
|
| is_simple
| True if the geometry is simple.
|
| Simple means that any self-intersections are only at boundary points.
|
| is_valid
| True if the geometry is valid.
|
| The definition depends on sub-class.
|
| length
| Unitless length of the geometry (float).
|
| minimum_clearance
| Unitless distance a node can be moved to produce an invalid geometry (float).
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `oriented_envelope`.
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `minimum_rotated_rectangle`.
|
| type
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| wkb
| WKB representation of the geometry.
|
| wkb_hex
| WKB hex representation of the geometry.
|
| wkt
| WKT representation of the geometry.
|
| xy
| Separate arrays of X and Y coordinate values.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.lib.Geometry:
|
| __ge__(self, value, /)
| Return self>=value.
|
| __gt__(self, value, /)
| Return self>value.
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __setstate__(...)
| For unpickling pre-shapely 2.0 pickles
shapely.Point
Python Library Documentation: class Point in module shapely.geometry.point
class Point(shapely.geometry.base.BaseGeometry)
| Point(*args)
|
| A geometry type that represents a single coordinate.
|
| Each coordinate has x, y and possibly z and/or m values.
|
| A point is a zero-dimensional feature and has zero length and zero area.
|
| Parameters
| ----------
| args : float, or sequence of floats
| The coordinates can either be passed as a single parameter, or as
| individual float values using multiple parameters:
|
| 1) 1 parameter: a sequence or array-like of with 2 or 3 values.
| 2) 2 or 3 parameters (float): x, y, and possibly z.
|
| Attributes
| ----------
| x, y, z, m : float
| Coordinate values
|
| Examples
| --------
| Constructing the Point using separate parameters for x and y:
|
| >>> from shapely import Point
| >>> p = Point(1.0, -1.0)
|
| Constructing the Point using a list of x, y coordinates:
|
| >>> p = Point([1.0, -1.0])
| >>> print(p)
| POINT (1 -1)
| >>> p.y
| -1.0
| >>> p.x
| 1.0
|
| Method resolution order:
| Point
| shapely.geometry.base.BaseGeometry
| shapely.lib.Geometry
| builtins.object
|
| Methods defined here:
|
| svg(self, scale_factor=1.0, fill_color=None, opacity=None)
| Return SVG circle element for the Point geometry.
|
| Parameters
| ----------
| scale_factor : float
| Multiplication factor for the SVG circle diameter. Default is 1.
| fill_color : str, optional
| Hex string for fill color. Default is to use "#66cc99" if
| geometry is valid, and "#ff3333" if invalid.
| opacity : float
| Float number between 0 and 1 for color opacity. Default value is 0.6
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(self, *args)
| Create a new Point geometry.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __geo_interface__
| Return a GeoJSON-like mapping of the Point geometry.
|
| m
| Return m coordinate.
|
| .. versionadded:: 2.1.0
| Also requires GEOS 3.12.0 or later.
|
| x
| Return x coordinate.
|
| xy
| Separate arrays of X and Y coordinate values.
|
| Examples
| --------
| >>> from shapely import Point
| >>> x, y = Point(0, 0).xy
| >>> list(x)
| [0.0]
| >>> list(y)
| [0.0]
|
| y
| Return y coordinate.
|
| z
| Return z coordinate.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.geometry.base.BaseGeometry:
|
| __and__(self, other)
| Return the intersection of the geometries.
|
| __bool__(self)
| Return True if the geometry is not empty, else False.
|
| __format__(self, format_spec)
| Format a geometry using a format specification.
|
| __nonzero__(self)
| Return True if the geometry is not empty, else False.
|
| __or__(self, other)
| Return the union of the geometries.
|
| __reduce__(self)
| Pickle support.
|
| __repr__(self)
| Return a string representation of the geometry.
|
| __str__(self)
| Return a string representation of the geometry.
|
| __sub__(self, other)
| Return the difference of the geometries.
|
| __xor__(self, other)
| Return the symmetric difference of the geometries.
|
| buffer(self, 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.
| quad_segs : int, optional
| Sets the number of line segments used to approximate an
| angle fillet.
| cap_style : shapely.BufferCapStyle or {'round', 'square', 'flat'}, 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 {'round', 'mitre', 'bevel'}, 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_sided : 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, resolution : int, optional
| Deprecated aliases for `quad_segs`.
| **kwargs : dict, optional
| For backwards compatibility of renamed parameters. If an unsupported
| kwarg is passed, a `ValueError` will be raised.
|
| Returns
| -------
| Geometry
|
| Notes
| -----
| The return value is a strictly two-dimensional geometry. All
| Z coordinates of the original geometry will be ignored.
|
| .. deprecated:: 2.1.0
| A deprecation warning is shown if ``quad_segs``, ``cap_style``,
| ``join_style``, ``mitre_limit`` or ``single_sided`` are
| specified as positional arguments. In a future release, these will
| need to be specified as keyword arguments.
|
| Examples
| --------
| >>> from shapely import BufferCapStyle
| >>> 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.1365484905459398
|
| 128-gon approximation:
|
| >>> g.buffer(1.0, 128).area
| 3.1415138011443013
|
| triangle approximation:
|
| >>> g.buffer(1.0, 3).area
| 3.0
| >>> list(g.buffer(1.0, cap_style=BufferCapStyle.square).exterior.coords)
| [(1.0, 1.0), (1.0, -1.0), (-1.0, -1.0), (-1.0, 1.0), (1.0, 1.0)]
| >>> g.buffer(1.0, cap_style=BufferCapStyle.square).area
| 4.0
|
| contains(self, other)
| Return True if the geometry contains the other, else False.
|
| contains_properly(self, other)
| Return True if the geometry completely contains the other.
|
| There should be no common boundary points.
|
| Refer to `shapely.contains_properly` for full documentation.
|
| covered_by(self, other)
| Return True if the geometry is covered by the other, else False.
|
| covers(self, other)
| Return True if the geometry covers the other, else False.
|
| crosses(self, other)
| Return True if the geometries cross, else False.
|
| difference(self, other, grid_size=None)
| Return the difference of the geometries.
|
| Refer to `shapely.difference` for full documentation.
|
| disjoint(self, other)
| Return True if geometries are disjoint, else False.
|
| distance(self, other)
| Unitless distance to other geometry (float).
|
| dwithin(self, other, distance)
| Return True if geometry is within a given distance from the other.
|
| Refer to `shapely.dwithin` for full documentation.
|
| equals(self, other)
| 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)).
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals(
| ... LineString([(0, 0), (1, 1), (2, 2)])
| ... )
| True
|
| Returns
| -------
| bool
|
| equals_exact(self, other, tolerance=0.0, *, normalize=False)
| Return True if the geometries are equivalent within the tolerance.
|
| Refer to :func:`~shapely.equals_exact` for full documentation.
|
| Parameters
| ----------
| other : BaseGeometry
| The other geometry object in this comparison.
| tolerance : float, optional (default: 0.)
| Absolute tolerance in the same units as coordinates.
| normalize : bool, optional (default: False)
| If True, normalize the two geometries so that the coordinates are
| in the same order.
|
| .. versionadded:: 2.1.0
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals_exact(
| ... LineString([(0, 0), (1, 1), (2, 2)]),
| ... 1e-6
| ... )
| False
|
| Returns
| -------
| bool
|
| geometryType(self)
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| hausdorff_distance(self, other)
| Unitless hausdorff distance to other geometry (float).
|
| interpolate(self, distance, normalized=False)
| 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`.
|
| intersection(self, other, grid_size=None)
| Return the intersection of the geometries.
|
| Refer to `shapely.intersection` for full documentation.
|
| intersects(self, other)
| Return True if geometries intersect, else False.
|
| line_interpolate_point(self, distance, normalized=False)
| 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`.
|
| line_locate_point(self, other, normalized=False)
| 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`.
|
| normalize(self)
| 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`).
|
| Examples
| --------
| >>> from shapely import MultiLineString
| >>> line = MultiLineString([[(0, 0), (1, 1)], [(3, 3), (2, 2)]])
| >>> line.normalize()
| <MULTILINESTRING ((2 2, 3 3), (0 0, 1 1))>
|
| overlaps(self, other)
| Return True if geometries overlap, else False.
|
| point_on_surface(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `representative_point`.
|
| project(self, other, normalized=False)
| 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`.
|
| relate(self, other)
| Return the DE-9IM intersection matrix for the two geometries (string).
|
| relate_pattern(self, other, pattern)
| Return True if the DE-9IM relationship code satisfies the pattern.
|
| representative_point(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `point_on_surface`.
|
| reverse(self)
| Return a copy of this geometry with the order of coordinates reversed.
|
| If the geometry is a polygon with interior rings, the interior rings are also
| reversed.
|
| Points are unchanged.
|
| See Also
| --------
| is_ccw : Checks if a geometry is clockwise.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (1, 2)]).reverse()
| <LINESTRING (1 2, 0 0)>
| >>> Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]).reverse()
| <POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
|
| segmentize(self, max_segment_length)
| 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.
|
| Parameters
| ----------
| max_segment_length : float or array_like
| Additional vertices will be added so that all line segments are no
| longer this value. Must be greater than 0.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (0, 10)]).segmentize(max_segment_length=5)
| <LINESTRING (0 0, 0 5, 0 10)>
| >>> Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]).segmentize(max_segment_length=5)
| <POLYGON ((0 0, 5 0, 10 0, 10 5, 10 10, 5 10, 0 10, 0 5, 0 0))>
|
| simplify(self, tolerance, preserve_topology=True)
| 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.
|
| symmetric_difference(self, other, grid_size=None)
| Return the symmetric difference of the geometries.
|
| Refer to `shapely.symmetric_difference` for full documentation.
|
| touches(self, other)
| Return True if geometries touch, else False.
|
| union(self, other, grid_size=None)
| Return the union of the geometries.
|
| Refer to `shapely.union` for full documentation.
|
| within(self, other)
| Return True if geometry is within the other, else False.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from shapely.geometry.base.BaseGeometry:
|
| area
| Unitless area of the geometry (float).
|
| 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.
|
| bounds
| Return minimum bounding region (minx, miny, maxx, maxy).
|
| centroid
| Return the geometric center of the object.
|
| 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.
|
| coords
| Access to geometry's coordinates (CoordinateSequence).
|
| envelope
| A figure that envelopes the geometry.
|
| geom_type
| Name of the geometry's type, such as 'Point'.
|
| has_m
| True if the geometry's coordinate sequence(s) have m values.
|
| has_z
| True if the geometry's coordinate sequence(s) have z values.
|
| is_closed
| True if the geometry is closed, else False.
|
| Applicable only to linear geometries.
|
| is_empty
| True if the set of points in this geometry is empty, else False.
|
| is_ring
| True if the geometry is a closed ring, else False.
|
| is_simple
| True if the geometry is simple.
|
| Simple means that any self-intersections are only at boundary points.
|
| is_valid
| True if the geometry is valid.
|
| The definition depends on sub-class.
|
| length
| Unitless length of the geometry (float).
|
| minimum_clearance
| Unitless distance a node can be moved to produce an invalid geometry (float).
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `oriented_envelope`.
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `minimum_rotated_rectangle`.
|
| type
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| wkb
| WKB representation of the geometry.
|
| wkb_hex
| WKB hex representation of the geometry.
|
| wkt
| WKT representation of the geometry.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.lib.Geometry:
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __setstate__(...)
| For unpickling pre-shapely 2.0 pickles
shapely.Polygon
Python Library Documentation: class Polygon in module shapely.geometry.polygon
class Polygon(shapely.geometry.base.BaseGeometry)
| Polygon(shell=None, holes=None)
|
| 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
|
| Attributes
| ----------
| exterior : LinearRing
| The ring which bounds the positive space of the polygon.
| interiors : sequence
| A sequence of rings which bound all existing holes.
|
| Examples
| --------
| Create a square polygon with no holes
|
| >>> from shapely import Polygon
| >>> coords = ((0., 0.), (0., 1.), (1., 1.), (1., 0.), (0., 0.))
| >>> polygon = Polygon(coords)
| >>> polygon.area
| 1.0
|
| Method resolution order:
| Polygon
| shapely.geometry.base.BaseGeometry
| shapely.lib.Geometry
| builtins.object
|
| Methods defined here:
|
| svg(self, scale_factor=1.0, fill_color=None, opacity=None)
| Return SVG path element for the Polygon geometry.
|
| Parameters
| ----------
| scale_factor : float
| Multiplication factor for the SVG stroke-width. Default is 1.
| fill_color : str, optional
| Hex string for fill color. Default is to use "#66cc99" if
| geometry is valid, and "#ff3333" if invalid.
| opacity : float
| Float number between 0 and 1 for color opacity. Default value is 0.6
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_bounds(xmin, ymin, xmax, ymax)
| Construct a `Polygon()` from spatial bounds.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(self, shell=None, holes=None)
| Create a new Polygon geometry.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __geo_interface__
| Return a GeoJSON-like mapping of the Polygon geometry.
|
| coords
| Not implemented for polygons.
|
| exterior
| Return the exterior ring of the polygon.
|
| interiors
| Return the sequence of interior rings of the polygon.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.geometry.base.BaseGeometry:
|
| __and__(self, other)
| Return the intersection of the geometries.
|
| __bool__(self)
| Return True if the geometry is not empty, else False.
|
| __format__(self, format_spec)
| Format a geometry using a format specification.
|
| __nonzero__(self)
| Return True if the geometry is not empty, else False.
|
| __or__(self, other)
| Return the union of the geometries.
|
| __reduce__(self)
| Pickle support.
|
| __repr__(self)
| Return a string representation of the geometry.
|
| __str__(self)
| Return a string representation of the geometry.
|
| __sub__(self, other)
| Return the difference of the geometries.
|
| __xor__(self, other)
| Return the symmetric difference of the geometries.
|
| buffer(self, 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.
| quad_segs : int, optional
| Sets the number of line segments used to approximate an
| angle fillet.
| cap_style : shapely.BufferCapStyle or {'round', 'square', 'flat'}, 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 {'round', 'mitre', 'bevel'}, 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_sided : 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, resolution : int, optional
| Deprecated aliases for `quad_segs`.
| **kwargs : dict, optional
| For backwards compatibility of renamed parameters. If an unsupported
| kwarg is passed, a `ValueError` will be raised.
|
| Returns
| -------
| Geometry
|
| Notes
| -----
| The return value is a strictly two-dimensional geometry. All
| Z coordinates of the original geometry will be ignored.
|
| .. deprecated:: 2.1.0
| A deprecation warning is shown if ``quad_segs``, ``cap_style``,
| ``join_style``, ``mitre_limit`` or ``single_sided`` are
| specified as positional arguments. In a future release, these will
| need to be specified as keyword arguments.
|
| Examples
| --------
| >>> from shapely import BufferCapStyle
| >>> 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.1365484905459398
|
| 128-gon approximation:
|
| >>> g.buffer(1.0, 128).area
| 3.1415138011443013
|
| triangle approximation:
|
| >>> g.buffer(1.0, 3).area
| 3.0
| >>> list(g.buffer(1.0, cap_style=BufferCapStyle.square).exterior.coords)
| [(1.0, 1.0), (1.0, -1.0), (-1.0, -1.0), (-1.0, 1.0), (1.0, 1.0)]
| >>> g.buffer(1.0, cap_style=BufferCapStyle.square).area
| 4.0
|
| contains(self, other)
| Return True if the geometry contains the other, else False.
|
| contains_properly(self, other)
| Return True if the geometry completely contains the other.
|
| There should be no common boundary points.
|
| Refer to `shapely.contains_properly` for full documentation.
|
| covered_by(self, other)
| Return True if the geometry is covered by the other, else False.
|
| covers(self, other)
| Return True if the geometry covers the other, else False.
|
| crosses(self, other)
| Return True if the geometries cross, else False.
|
| difference(self, other, grid_size=None)
| Return the difference of the geometries.
|
| Refer to `shapely.difference` for full documentation.
|
| disjoint(self, other)
| Return True if geometries are disjoint, else False.
|
| distance(self, other)
| Unitless distance to other geometry (float).
|
| dwithin(self, other, distance)
| Return True if geometry is within a given distance from the other.
|
| Refer to `shapely.dwithin` for full documentation.
|
| equals(self, other)
| 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)).
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals(
| ... LineString([(0, 0), (1, 1), (2, 2)])
| ... )
| True
|
| Returns
| -------
| bool
|
| equals_exact(self, other, tolerance=0.0, *, normalize=False)
| Return True if the geometries are equivalent within the tolerance.
|
| Refer to :func:`~shapely.equals_exact` for full documentation.
|
| Parameters
| ----------
| other : BaseGeometry
| The other geometry object in this comparison.
| tolerance : float, optional (default: 0.)
| Absolute tolerance in the same units as coordinates.
| normalize : bool, optional (default: False)
| If True, normalize the two geometries so that the coordinates are
| in the same order.
|
| .. versionadded:: 2.1.0
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals_exact(
| ... LineString([(0, 0), (1, 1), (2, 2)]),
| ... 1e-6
| ... )
| False
|
| Returns
| -------
| bool
|
| geometryType(self)
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| hausdorff_distance(self, other)
| Unitless hausdorff distance to other geometry (float).
|
| interpolate(self, distance, normalized=False)
| 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`.
|
| intersection(self, other, grid_size=None)
| Return the intersection of the geometries.
|
| Refer to `shapely.intersection` for full documentation.
|
| intersects(self, other)
| Return True if geometries intersect, else False.
|
| line_interpolate_point(self, distance, normalized=False)
| 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`.
|
| line_locate_point(self, other, normalized=False)
| 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`.
|
| normalize(self)
| 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`).
|
| Examples
| --------
| >>> from shapely import MultiLineString
| >>> line = MultiLineString([[(0, 0), (1, 1)], [(3, 3), (2, 2)]])
| >>> line.normalize()
| <MULTILINESTRING ((2 2, 3 3), (0 0, 1 1))>
|
| overlaps(self, other)
| Return True if geometries overlap, else False.
|
| point_on_surface(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `representative_point`.
|
| project(self, other, normalized=False)
| 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`.
|
| relate(self, other)
| Return the DE-9IM intersection matrix for the two geometries (string).
|
| relate_pattern(self, other, pattern)
| Return True if the DE-9IM relationship code satisfies the pattern.
|
| representative_point(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `point_on_surface`.
|
| reverse(self)
| Return a copy of this geometry with the order of coordinates reversed.
|
| If the geometry is a polygon with interior rings, the interior rings are also
| reversed.
|
| Points are unchanged.
|
| See Also
| --------
| is_ccw : Checks if a geometry is clockwise.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (1, 2)]).reverse()
| <LINESTRING (1 2, 0 0)>
| >>> Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]).reverse()
| <POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
|
| segmentize(self, max_segment_length)
| 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.
|
| Parameters
| ----------
| max_segment_length : float or array_like
| Additional vertices will be added so that all line segments are no
| longer this value. Must be greater than 0.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (0, 10)]).segmentize(max_segment_length=5)
| <LINESTRING (0 0, 0 5, 0 10)>
| >>> Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]).segmentize(max_segment_length=5)
| <POLYGON ((0 0, 5 0, 10 0, 10 5, 10 10, 5 10, 0 10, 0 5, 0 0))>
|
| simplify(self, tolerance, preserve_topology=True)
| 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.
|
| symmetric_difference(self, other, grid_size=None)
| Return the symmetric difference of the geometries.
|
| Refer to `shapely.symmetric_difference` for full documentation.
|
| touches(self, other)
| Return True if geometries touch, else False.
|
| union(self, other, grid_size=None)
| Return the union of the geometries.
|
| Refer to `shapely.union` for full documentation.
|
| within(self, other)
| Return True if geometry is within the other, else False.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from shapely.geometry.base.BaseGeometry:
|
| area
| Unitless area of the geometry (float).
|
| 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.
|
| bounds
| Return minimum bounding region (minx, miny, maxx, maxy).
|
| centroid
| Return the geometric center of the object.
|
| 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.
|
| envelope
| A figure that envelopes the geometry.
|
| geom_type
| Name of the geometry's type, such as 'Point'.
|
| has_m
| True if the geometry's coordinate sequence(s) have m values.
|
| has_z
| True if the geometry's coordinate sequence(s) have z values.
|
| is_closed
| True if the geometry is closed, else False.
|
| Applicable only to linear geometries.
|
| is_empty
| True if the set of points in this geometry is empty, else False.
|
| is_ring
| True if the geometry is a closed ring, else False.
|
| is_simple
| True if the geometry is simple.
|
| Simple means that any self-intersections are only at boundary points.
|
| is_valid
| True if the geometry is valid.
|
| The definition depends on sub-class.
|
| length
| Unitless length of the geometry (float).
|
| minimum_clearance
| Unitless distance a node can be moved to produce an invalid geometry (float).
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `oriented_envelope`.
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `minimum_rotated_rectangle`.
|
| type
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| wkb
| WKB representation of the geometry.
|
| wkb_hex
| WKB hex representation of the geometry.
|
| wkt
| WKT representation of the geometry.
|
| xy
| Separate arrays of X and Y coordinate values.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.lib.Geometry:
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __setstate__(...)
| For unpickling pre-shapely 2.0 pickles
shapely.STRtree
Python Library Documentation: class STRtree in module shapely.strtree
class STRtree(builtins.object)
| STRtree(geoms: collections.abc.Iterable[shapely.geometry.base.BaseGeometry], node_capacity: int = 10)
|
| A query-only R-tree spatial index.
|
| It is created using the Sort-Tile-Recursive (STR) [1]_ algorithm.
|
| The tree indexes the bounding boxes of each geometry. The tree is
| constructed directly at initialization and nodes cannot be added or
| removed after it has been created.
|
| All operations return indices of the input geometries. These indices
| can be used to index into anything associated with the input geometries,
| including the input geometries themselves, or custom items stored in
| another object of the same length as the geometries.
|
| Bounding boxes limited to two dimensions and are axis-aligned (equivalent to
| the ``bounds`` property of a geometry); any Z values present in geometries
| are ignored for purposes of indexing within the tree.
|
| Any mixture of geometry types may be stored in the tree.
|
| Note: the tree is more efficient for querying when there are fewer
| geometries that have overlapping bounding boxes and where there is greater
| similarity between the outer boundary of a geometry and its bounding box.
| For example, a MultiPolygon composed of widely-spaced individual Polygons
| will have a large overall bounding box compared to the boundaries of its
| individual Polygons, and the bounding box may also potentially overlap many
| other geometries within the tree. This means that the resulting tree may be
| less efficient to query than a tree constructed from individual Polygons.
|
| Parameters
| ----------
| geoms : sequence
| A sequence of geometry objects.
| node_capacity : int, default 10
| The maximum number of child nodes per parent node in the tree.
|
| References
| ----------
| .. [1] Leutenegger, Scott T.; Edgington, Jeffrey M.; Lopez, Mario A.
| (February 1997). "STR: A Simple and Efficient Algorithm for
| R-Tree Packing".
| https://ia600900.us.archive.org/27/items/nasa_techdoc_19970016975/19970016975.pdf
|
| Methods defined here:
|
| __init__(self, geoms: collections.abc.Iterable[shapely.geometry.base.BaseGeometry], node_capacity: int = 10)
| Create a new STRtree spatial index.
|
| __len__(self)
| Return the number of geometries in the tree.
|
| __reduce__(self)
| Pickle support.
|
| nearest(self, geometry) -> typing.Any | None
| Return the index of the nearest geometry in the tree.
|
| This is determined for each input geometry based on distance within
| two-dimensional Cartesian space.
|
| This distance will be 0 when input geometries intersect tree geometries.
|
| If there are multiple equidistant or intersected geometries in the tree,
| only a single result is returned for each input geometry, based on the
| order that tree geometries are visited; this order may be
| nondeterministic.
|
| If any input geometry is None or empty, an error is raised. Any Z
| values present in input geometries are ignored when finding nearest
| tree geometries.
|
| Parameters
| ----------
| geometry : Geometry or array_like
| Input geometries to query the tree.
|
| Returns
| -------
| scalar or ndarray
| Indices of geometries in tree. Return value will have the same shape
| as the input.
|
| None is returned if this index is empty. This may change in
| version 2.0.
|
| See Also
| --------
| query_nearest: returns all equidistant geometries, exclusive geometries, and optional distances
|
| Examples
| --------
| >>> from shapely import Point, STRtree
| >>> tree = STRtree([Point(i, i) for i in range(10)])
|
| Query the tree for nearest using a scalar geometry:
|
| >>> index = tree.nearest(Point(2.2, 2.2))
| >>> index
| 2
| >>> tree.geometries.take(index)
| <POINT (2 2)>
|
| Query the tree for nearest using an array of geometries:
|
| >>> indices = tree.nearest([Point(2.2, 2.2), Point(4.4, 4.4)])
| >>> indices.tolist()
| [2, 4]
| >>> tree.geometries.take(indices).tolist()
| [<POINT (2 2)>, <POINT (4 4)>]
|
| Nearest only return one object if there are multiple equidistant results:
|
| >>> tree = STRtree ([Point(0, 0), Point(0, 0)])
| >>> tree.nearest(Point(0, 0))
| 0
|
| query(self, geometry, predicate=None, distance=None)
| Get the index combinations of all possibly intersecting geometries.
|
| Returns the integer indices of all combinations of each input geometry
| and tree geometries where the bounding box of each input geometry
| intersects the bounding box of a tree geometry.
|
| If the input geometry is a scalar, this returns an array of shape (n, ) with
| the indices of the matching tree geometries. If the input geometry is an
| array_like, this returns an array with shape (2,n) where the subarrays
| correspond to the indices of the input geometries and indices of the
| tree geometries associated with each. To generate an array of pairs of
| input geometry index and tree geometry index, simply transpose the
| result.
|
| If a predicate is provided, the tree geometries are first queried based
| on the bounding box of the input geometry and then are further filtered
| to those that meet the predicate when comparing the input geometry to
| the tree geometry:
| predicate(geometry, tree_geometry)
|
| The 'dwithin' predicate requires GEOS >= 3.10.
|
| Bounding boxes are limited to two dimensions and are axis-aligned
| (equivalent to the ``bounds`` property of a geometry); any Z values
| present in input geometries are ignored when querying the tree.
|
| Any input geometry that is None or empty will never match geometries in
| the tree.
|
| Parameters
| ----------
| geometry : Geometry or array_like
| Input geometries to query the tree and filter results using the
| optional predicate.
| predicate : {None, 'intersects', 'within', 'contains', 'overlaps', 'crosses','touches', 'covers', 'covered_by', 'contains_properly', 'dwithin'}, optional
| The predicate to use for testing geometries from the tree
| that are within the input geometry's bounding box.
| distance : number or array_like, optional
| Distances around each input geometry within which to query the tree
| for the 'dwithin' predicate. If array_like, shape must be
| broadcastable to shape of geometry. Required if predicate='dwithin'.
|
| Returns
| -------
| ndarray with shape (n,) if geometry is a scalar
| Contains tree geometry indices.
|
| OR
|
| ndarray with shape (2, n) if geometry is an array_like
| The first subarray contains input geometry indices.
| The second subarray contains tree geometry indices.
|
| Examples
| --------
| >>> from shapely import box, Point, STRtree
| >>> import numpy as np
| >>> points = [Point(0, 0), Point(1, 1), Point(2,2), Point(3, 3)]
| >>> tree = STRtree(points)
|
| Query the tree using a scalar geometry:
|
| >>> indices = tree.query(box(0, 0, 1, 1))
| >>> indices.tolist()
| [0, 1]
|
| Query using an array of geometries:
|
| >>> boxes = np.array([box(0, 0, 1, 1), box(2, 2, 3, 3)])
| >>> arr_indices = tree.query(boxes)
| >>> arr_indices.tolist()
| [[0, 0, 1, 1], [0, 1, 2, 3]]
|
| Or transpose to get all pairs of input and tree indices:
|
| >>> arr_indices.T.tolist()
| [[0, 0], [0, 1], [1, 2], [1, 3]]
|
| Retrieve the tree geometries by results of query:
|
| >>> tree.geometries.take(indices).tolist()
| [<POINT (0 0)>, <POINT (1 1)>]
|
| Retrieve all pairs of input and tree geometries:
|
| >>> np.array([boxes.take(arr_indices[0]),tree.geometries.take(arr_indices[1])]).T.tolist()
| [[<POLYGON ((1 0, 1 1, 0 1, 0 0, 1 0))>, <POINT (0 0)>],
| [<POLYGON ((1 0, 1 1, 0 1, 0 0, 1 0))>, <POINT (1 1)>],
| [<POLYGON ((3 2, 3 3, 2 3, 2 2, 3 2))>, <POINT (2 2)>],
| [<POLYGON ((3 2, 3 3, 2 3, 2 2, 3 2))>, <POINT (3 3)>]]
|
| Query using a predicate:
|
| >>> tree = STRtree([box(0, 0, 0.5, 0.5), box(0.5, 0.5, 1, 1), box(1, 1, 2, 2)])
| >>> tree.query(box(0, 0, 1, 1), predicate="contains").tolist()
| [0, 1]
| >>> tree.query(Point(0.75, 0.75), predicate="dwithin", distance=0.5).tolist()
| [0, 1, 2]
|
| >>> tree.query(boxes, predicate="contains").tolist()
| [[0, 0], [0, 1]]
| >>> tree.query(boxes, predicate="dwithin", distance=0.5).tolist()
| [[0, 0, 0, 1], [0, 1, 2, 2]]
|
| Retrieve custom items associated with tree geometries (records can
| be in whatever data structure so long as geometries and custom data
| can be extracted into arrays of the same length and order):
|
| >>> records = [
| ... {"geometry": Point(0, 0), "value": "A"},
| ... {"geometry": Point(2, 2), "value": "B"}
| ... ]
| >>> tree = STRtree([record["geometry"] for record in records])
| >>> items = np.array([record["value"] for record in records])
| >>> items.take(tree.query(box(0, 0, 1, 1))).tolist()
| ['A']
|
|
| Notes
| -----
| In the context of a spatial join, input geometries are the "left"
| geometries that determine the order of the results, and tree geometries
| are "right" geometries that are joined against the left geometries. This
| effectively performs an inner join, where only those combinations of
| geometries that can be joined based on overlapping bounding boxes or
| optional predicate are returned.
|
| query_nearest(self, geometry, max_distance=None, return_distance=False, exclusive=False, all_matches=True)
| Return the index of the nearest geometries in the tree.
|
| This is determined for each input geometry based on distance within
| two-dimensional Cartesian space.
|
| This distance will be 0 when input geometries intersect tree geometries.
|
| If there are multiple equidistant or intersected geometries in tree and
| `all_matches` is True (the default), all matching tree geometries are
| returned; otherwise only the first matching tree geometry is returned.
| Tree indices are returned in the order they are visited for each input
| geometry and may not be in ascending index order; no meaningful order is
| implied.
|
| The max_distance used to search for nearest items in the tree may have a
| significant impact on performance by reducing the number of input
| geometries that are evaluated for nearest items in the tree. Only those
| input geometries with at least one tree geometry within +/- max_distance
| beyond their envelope will be evaluated. However, using a large
| max_distance may have a negative performance impact because many tree
| geometries will be queried for each input geometry.
|
| The distance, if returned, will be 0 for any intersected geometries in
| the tree.
|
| Any geometry that is None or empty in the input geometries is omitted
| from the output. Any Z values present in input geometries are ignored
| when finding nearest tree geometries.
|
| Parameters
| ----------
| geometry : Geometry or array_like
| Input geometries to query the tree.
| max_distance : float, optional
| Maximum distance within which to query for nearest items in tree.
| Must be greater than 0.
| return_distance : bool, default False
| If True, will return distances in addition to indices.
| exclusive : bool, default False
| If True, the nearest tree geometries that are equal to the input
| geometry will not be returned.
| all_matches : bool, default True
| If True, all equidistant and intersected geometries will be returned
| for each input geometry.
| If False, only the first nearest geometry will be returned.
|
| Returns
| -------
| tree indices or tuple of (tree indices, distances) if geometry is a scalar
| indices is an ndarray of shape (n, ) and distances (if present) an
| ndarray of shape (n, )
|
| OR
|
| indices or tuple of (indices, distances)
| indices is an ndarray of shape (2,n) and distances (if present) an
| ndarray of shape (n).
| The first subarray of indices contains input geometry indices.
| The second subarray of indices contains tree geometry indices.
|
| See Also
| --------
| nearest: returns singular nearest geometry for each input
|
| Examples
| --------
| >>> import numpy as np
| >>> from shapely import box, Point, STRtree
| >>> points = [Point(0, 0), Point(1, 1), Point(2,2), Point(3, 3)]
| >>> tree = STRtree(points)
|
| Find the nearest tree geometries to a scalar geometry:
|
| >>> indices = tree.query_nearest(Point(0.25, 0.25))
| >>> indices.tolist()
| [0]
|
| Retrieve the tree geometries by results of query:
|
| >>> tree.geometries.take(indices).tolist()
| [<POINT (0 0)>]
|
| Find the nearest tree geometries to an array of geometries:
|
| >>> query_points = np.array([Point(2.25, 2.25), Point(1, 1)])
| >>> arr_indices = tree.query_nearest(query_points)
| >>> arr_indices.tolist()
| [[0, 1], [2, 1]]
|
| Or transpose to get all pairs of input and tree indices:
|
| >>> arr_indices.T.tolist()
| [[0, 2], [1, 1]]
|
| Retrieve all pairs of input and tree geometries:
|
| >>> list(zip(query_points.take(arr_indices[0]), tree.geometries.take(arr_indices[1])))
| [(<POINT (2.25 2.25)>, <POINT (2 2)>), (<POINT (1 1)>, <POINT (1 1)>)]
|
| All intersecting geometries in the tree are returned by default:
|
| >>> tree.query_nearest(box(1,1,3,3)).tolist()
| [1, 2, 3]
|
| Set all_matches to False to to return a single match per input geometry:
|
| >>> tree.query_nearest(box(1,1,3,3), all_matches=False).tolist()
| [1]
|
| Return the distance to each nearest tree geometry:
|
| >>> index, distance = tree.query_nearest(Point(0.5, 0.5), return_distance=True)
| >>> index.tolist()
| [0, 1]
| >>> distance.round(4).tolist()
| [0.7071, 0.7071]
|
| Return the distance for each input and nearest tree geometry for an array
| of geometries:
|
| >>> indices, distance = tree.query_nearest([Point(0.5, 0.5), Point(1, 1)], return_distance=True)
| >>> indices.tolist()
| [[0, 0, 1], [0, 1, 1]]
| >>> distance.round(4).tolist()
| [0.7071, 0.7071, 0.0]
|
| Retrieve custom items associated with tree geometries (records can
| be in whatever data structure so long as geometries and custom data
| can be extracted into arrays of the same length and order):
|
| >>> records = [
| ... {"geometry": Point(0, 0), "value": "A"},
| ... {"geometry": Point(2, 2), "value": "B"}
| ... ]
| >>> tree = STRtree([record["geometry"] for record in records])
| >>> items = np.array([record["value"] for record in records])
| >>> items.take(tree.query_nearest(Point(0.5, 0.5))).tolist()
| ['A']
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| geometries
| Geometries stored in the tree in the order used to construct the tree.
|
| The order of this array corresponds to the tree indices returned by
| other STRtree methods.
|
| Do not attempt to modify items in the returned array.
|
| Returns
| -------
| ndarray of Geometry objects
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
shapely.affinity
Python Library Documentation: module shapely.affinity in shapely
NAME
shapely.affinity - Affine transforms, both in general and specific, named transforms.
FUNCTIONS
affine_transform(geom, matrix)
Return a transformed geometry using an affine transformation matrix.
The coefficient matrix is provided as a list or tuple with 6 or 12 items
for 2D or 3D transformations, respectively.
For 2D affine transformations, the 6 parameter matrix is::
[a, b, d, e, xoff, yoff]
which represents the augmented matrix::
[x'] / a b xoff \ [x]
[y'] = | d e yoff | [y]
[1 ] \ 0 0 1 / [1]
or the equations for the transformed coordinates::
x' = a * x + b * y + xoff
y' = d * x + e * y + yoff
For 3D affine transformations, the 12 parameter matrix is::
[a, b, c, d, e, f, g, h, i, xoff, yoff, zoff]
which represents the augmented matrix::
[x'] / a b c xoff \ [x]
[y'] = | d e f yoff | [y]
[z'] | g h i zoff | [z]
[1 ] \ 0 0 0 1 / [1]
or the equations for the transformed coordinates::
x' = a * x + b * y + c * z + xoff
y' = d * x + e * y + f * z + yoff
z' = g * x + h * y + i * z + zoff
rotate(geom, angle, origin='center', use_radians=False)
Return a rotated geometry on a 2D plane.
The angle of rotation can be specified in either degrees (default) or
radians by setting ``use_radians=True``. Positive angles are
counter-clockwise and negative are clockwise rotations.
The point of origin can be a keyword 'center' for the bounding box
center (default), 'centroid' for the geometry's centroid, a Point object
or a coordinate tuple (x0, y0).
The affine transformation matrix for 2D rotation is:
/ cos(r) -sin(r) xoff \
| sin(r) cos(r) yoff |
\ 0 0 1 /
where the offsets are calculated from the origin Point(x0, y0):
xoff = x0 - x0 * cos(r) + y0 * sin(r)
yoff = y0 - x0 * sin(r) - y0 * cos(r)
scale(geom, xfact=1.0, yfact=1.0, zfact=1.0, origin='center')
Return a scaled geometry, scaled by factors along each dimension.
The point of origin can be a keyword 'center' for the 2D bounding box
center (default), 'centroid' for the geometry's 2D centroid, a Point
object or a coordinate tuple (x0, y0, z0).
Negative scale factors will mirror or reflect coordinates.
The general 3D affine transformation matrix for scaling is:
/ xfact 0 0 xoff \
| 0 yfact 0 yoff |
| 0 0 zfact zoff |
\ 0 0 0 1 /
where the offsets are calculated from the origin Point(x0, y0, z0):
xoff = x0 - x0 * xfact
yoff = y0 - y0 * yfact
zoff = z0 - z0 * zfact
skew(geom, xs=0.0, ys=0.0, origin='center', use_radians=False)
Return a skewed geometry, sheared by angles along x and y dimensions.
The shear angle can be specified in either degrees (default) or radians
by setting ``use_radians=True``.
The point of origin can be a keyword 'center' for the bounding box
center (default), 'centroid' for the geometry's centroid, a Point object
or a coordinate tuple (x0, y0).
The general 2D affine transformation matrix for skewing is:
/ 1 tan(xs) xoff \
| tan(ys) 1 yoff |
\ 0 0 1 /
where the offsets are calculated from the origin Point(x0, y0):
xoff = -y0 * tan(xs)
yoff = -x0 * tan(ys)
translate(geom, xoff=0.0, yoff=0.0, zoff=0.0)
Return a translated geometry shifted by offsets along each dimension.
The general 3D affine transformation matrix for translation is:
/ 1 0 0 xoff \
| 0 1 0 yoff |
| 0 0 1 zoff |
\ 0 0 0 1 /
DATA
__all__ = ['affine_transform', 'rotate', 'scale', 'skew', 'translate']
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\shapely\affinity.py
shapely.algorithms
Python Library Documentation: package shapely.algorithms in shapely
NAME
shapely.algorithms - Algorithms implemented in Shapely.
PACKAGE CONTENTS
_oriented_envelope
cga
polylabel
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\shapely\algorithms\__init__.py
shapely.area
Python Library Documentation: function area in module shapely.measurement
area(geometry, **kwargs)
Compute the area of a (multi)polygon.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the area.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import MultiPolygon, Polygon
>>> polygon = Polygon([(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)])
>>> shapely.area(polygon)
100.0
>>> polygon2 = Polygon([(10, 10), (10, 20), (20, 20), (20, 10), (10, 10)])
>>> shapely.area(MultiPolygon([polygon, polygon2]))
200.0
>>> shapely.area(Polygon())
0.0
>>> shapely.area(None)
nan
shapely.boundary
Python Library Documentation: function boundary in module shapely.constructive
boundary(geometry, **kwargs)
Return the topological boundary of a geometry.
This function will return None for geometrycollections.
Parameters
----------
geometry : Geometry or array_like
Geometry for which to return the boundary.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, LinearRing, LineString, MultiLineString, MultiPoint, Point, Polygon
>>> shapely.boundary(Point(0, 0))
<GEOMETRYCOLLECTION EMPTY>
>>> shapely.boundary(LineString([(0, 0), (1, 1), (1, 2)]))
<MULTIPOINT ((0 0), (1 2))>
>>> shapely.boundary(LinearRing([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]))
<MULTIPOINT EMPTY>
>>> shapely.boundary(Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]))
<LINESTRING (0 0, 1 0, 1 1, 0 1, 0 0)>
>>> shapely.boundary(MultiPoint([(0, 0), (1, 2)]))
<GEOMETRYCOLLECTION EMPTY>
>>> shapely.boundary(MultiLineString([[(0, 0), (1, 1)], [(0, 1), (1, 0)]]))
<MULTIPOINT ((0 0), (0 1), (1 0), (1 1))>
>>> shapely.boundary(GeometryCollection([Point(0, 0)])) is None
True
shapely.bounds
Python Library Documentation: function bounds in module shapely.measurement
bounds(geometry, **kwargs)
Compute the bounds (extent) of a geometry.
For each geometry these 4 numbers are returned: min x, min y, max x, max y.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the bounds.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point, Polygon
>>> shapely.bounds(Point(2, 3)).tolist()
[2.0, 3.0, 2.0, 3.0]
>>> shapely.bounds(LineString([(0, 0), (0, 2), (3, 2)])).tolist()
[0.0, 0.0, 3.0, 2.0]
>>> shapely.bounds(Polygon()).tolist()
[nan, nan, nan, nan]
>>> shapely.bounds(None).tolist()
[nan, nan, nan, nan]
shapely.box
Python Library Documentation: function box in module shapely.creation
box(xmin, ymin, xmax, ymax, ccw=True, **kwargs)
Create box polygons.
Parameters
----------
xmin : float or array_like
Float or array of minimum x coordinates.
ymin : float or array_like
Float or array of minimum y coordinates.
xmax : float or array_like
Float or array of maximum x coordinates.
ymax : float or array_like
Float or array of maximum y coordinates.
ccw : bool, default True
If True, box will be created in counterclockwise direction starting
from bottom right coordinate (xmax, ymin).
If False, box will be created in clockwise direction starting from
bottom left coordinate (xmin, ymin).
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``ccw`` is specified as a
positional argument. This will need to be specified as a keyword
argument in a future release.
Examples
--------
>>> import shapely
>>> shapely.box(0, 0, 1, 1)
<POLYGON ((1 0, 1 1, 0 1, 0 0, 1 0))>
>>> shapely.box(0, 0, 1, 1, ccw=False)
<POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
shapely.buffer
Python Library Documentation: function buffer in module shapely.constructive
buffer(geometry, distance, quad_segs=8, cap_style='round', join_style='round', mitre_limit=5.0, single_sided=False, **kwargs)
Compute the buffer of a geometry for positive and negative buffer distance.
The buffer of a geometry is defined as the Minkowski sum (or difference,
for negative distance) of the geometry with a circle with radius equal
to the absolute value of the buffer distance.
The buffer operation always returns a polygonal result. The negative
or zero-distance buffer of lines and points is always empty.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the buffer.
distance : float or array_like
Specifies the circle radius in the Minkowski sum (or difference).
quad_segs : int, default 8
Specifies the number of linear segments in a quarter circle in the
approximation of circular arcs.
cap_style : shapely.BufferCapStyle or {'round', 'square', 'flat'}, 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 {'round', 'mitre', 'bevel'}, 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, default 5.0
Crops of 'mitre'-style joins if the point is displaced from the
buffered vertex by more than this limit.
single_sided : bool, default False
Only buffer at one side of the geometry.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``quad_segs``, ``cap_style``,
``join_style``, ``mitre_limit`` or ``single_sided`` are
specified as positional arguments. In a future release, these will
need to be specified as keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point, Polygon, BufferCapStyle, BufferJoinStyle
>>> shapely.buffer(Point(10, 10), 2, quad_segs=1)
<POLYGON ((12 10, 10 8, 8 10, 10 12, 12 10))>
>>> shapely.buffer(Point(10, 10), 2, quad_segs=2)
<POLYGON ((12 10, 11.414 8.586, 10 8, 8.586 8.586, 8 10, 8.5...>
>>> shapely.buffer(Point(10, 10), -2, quad_segs=1)
<POLYGON EMPTY>
>>> line = LineString([(10, 10), (20, 10)])
>>> shapely.buffer(line, 2, cap_style="square")
<POLYGON ((20 12, 22 12, 22 8, 10 8, 8 8, 8 12, 20 12))>
>>> shapely.buffer(line, 2, cap_style="flat")
<POLYGON ((20 12, 20 8, 10 8, 10 12, 20 12))>
>>> shapely.buffer(line, 2, single_sided=True, cap_style="flat")
<POLYGON ((20 10, 10 10, 10 12, 20 12, 20 10))>
>>> line2 = LineString([(10, 10), (20, 10), (20, 20)])
>>> shapely.buffer(line2, 2, cap_style="flat", join_style="bevel")
<POLYGON ((18 12, 18 20, 22 20, 22 10, 20 8, 10 8, 10 12, 18 12))>
>>> shapely.buffer(line2, 2, cap_style="flat", join_style="mitre")
<POLYGON ((18 12, 18 20, 22 20, 22 8, 10 8, 10 12, 18 12))>
>>> shapely.buffer(line2, 2, cap_style="flat", join_style="mitre", mitre_limit=1)
<POLYGON ((18 12, 18 20, 22 20, 22 9.172, 20.828 8, 10 8, 10 12, 18 12))>
>>> square = Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)])
>>> shapely.buffer(square, 2, join_style="mitre")
<POLYGON ((-2 -2, -2 12, 12 12, 12 -2, -2 -2))>
>>> shapely.buffer(square, -2, join_style="mitre")
<POLYGON ((2 2, 2 8, 8 8, 8 2, 2 2))>
>>> shapely.buffer(square, -5, join_style="mitre")
<POLYGON EMPTY>
>>> shapely.buffer(line, float("nan")) is None
True
shapely.build_area
Python Library Documentation: function build_area in module shapely.constructive
build_area(geometry, **kwargs)
Create an areal geometry formed by the constituent linework of given geometry.
Equivalent of the PostGIS ST_BuildArea() function.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to build an area.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, Polygon
>>> polygon1 = Polygon([(0, 0), (3, 0), (3, 3), (0, 3), (0, 0)])
>>> polygon2 = Polygon([(1, 1), (1, 2), (2, 2), (1, 1)])
>>> shapely.build_area(GeometryCollection([polygon1, polygon2]))
<POLYGON ((0 0, 0 3, 3 3, 3 0, 0 0), (1 1, 2 2, 1 2, 1 1))>
shapely.centroid
Python Library Documentation: function centroid in module shapely.constructive
centroid(geometry, **kwargs)
Compute the geometric center (center-of-mass) of a geometry.
For multipoints this is computed as the mean of the input coordinates.
For multilinestrings the centroid is weighted by the length of each
line segment. For multipolygons the centroid is weighted by the area of
each polygon.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the centroid.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, MultiPoint, Polygon
>>> shapely.centroid(Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]))
<POINT (5 5)>
>>> shapely.centroid(LineString([(0, 0), (2, 2), (10, 10)]))
<POINT (5 5)>
>>> shapely.centroid(MultiPoint([(0, 0), (10, 10)]))
<POINT (5 5)>
>>> shapely.centroid(Polygon())
<POINT EMPTY>
shapely.clip_by_rect
Python Library Documentation: function clip_by_rect in module shapely.constructive
clip_by_rect(geometry, xmin, ymin, xmax, ymax, **kwargs)
Return the portion of a geometry within a rectangle.
The geometry is clipped in a fast but possibly dirty way. The output is
not guaranteed to be valid. No exceptions will be raised for topological
errors.
Note: empty geometries or geometries that do not overlap with the
specified bounds will result in GEOMETRYCOLLECTION EMPTY.
Parameters
----------
geometry : Geometry or array_like
The geometry to be clipped.
xmin : float
Minimum x value of the rectangle.
ymin : float
Minimum y value of the rectangle.
xmax : float
Maximum x value of the rectangle.
ymax : float
Maximum y value of the rectangle.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Polygon
>>> line = LineString([(0, 0), (10, 10)])
>>> shapely.clip_by_rect(line, 0., 0., 1., 1.)
<LINESTRING (0 0, 1 1)>
>>> polygon = Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)])
>>> shapely.clip_by_rect(polygon, 0., 0., 1., 1.)
<POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
shapely.concave_hull
Python Library Documentation: function concave_hull in module shapely.constructive
concave_hull(geometry, ratio=0.0, allow_holes=False, **kwargs)
Compute a concave geometry that encloses an input geometry.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the concave hull.
ratio : float, default 0.0
Number in the range [0, 1]. Higher numbers will include fewer vertices
in the hull.
allow_holes : bool, default False
If set to True, the concave hull may have holes.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import MultiPoint, Polygon
>>> multi_point = MultiPoint([(0, 0), (0, 3), (1, 1), (3, 0), (3, 3)])
>>> shapely.concave_hull(multi_point, ratio=0.1)
<POLYGON ((0 0, 0 3, 1 1, 3 3, 3 0, 0 0))>
>>> shapely.concave_hull(multi_point, ratio=1.0)
<POLYGON ((0 0, 0 3, 3 3, 3 0, 0 0))>
>>> shapely.concave_hull(Polygon())
<POLYGON EMPTY>
shapely.constrained_delaunay_triangles
Python Library Documentation: function constrained_delaunay_triangles in module shapely.constructive
constrained_delaunay_triangles(geometry, **kwargs)
Compute the constrained Delaunay triangulation of polygons.
A constrained Delaunay triangulation requires the edges of the input
polygon(s) to be in the set of resulting triangle edges. An unconstrained
delaunay triangulation only triangulates based on the vertices, hence
triangle edges could cross polygon boundaries.
.. versionadded:: 2.1.0
Parameters
----------
geometry : Geometry or array_like
**kwargs
For other keyword-only arguments, see the
`NumPy ufunc docs <https://numpy.org/doc/stable/reference/ufuncs.html#ufuncs-kwargs>`_.
Returns
-------
GeometryCollection or array of GeometryCollections
* GeometryCollection of polygons, given polygonal input
* Empty GeometryCollection, given non-polygonal input
See Also
--------
delaunay_triangles
Examples
--------
>>> import shapely
>>> from shapely import MultiPoint, MultiPolygon, Polygon
>>> shapely.constrained_delaunay_triangles(Polygon([(10, 10), (20, 40), (90, 90), (90, 10), (10, 10)]))
<GEOMETRYCOLLECTION (POLYGON ((90 10, 20 40, 90 90, 90 10)), POLYGON ((20 40...>
>>> shapely.constrained_delaunay_triangles(Polygon())
<GEOMETRYCOLLECTION EMPTY>
>>> shapely.constrained_delaunay_triangles(MultiPolygon([Polygon(((50, 30), (60, 30), (100, 100), (50, 30))), Polygon(((10, 10), (20, 40), (90, 90), (90, 10), (10, 10)))]))
<GEOMETRYCOLLECTION (POLYGON ((50 30, 100 100, 60 30, 50 30)), POLYGON ((90 ...>
>>> shapely.constrained_delaunay_triangles(MultiPolygon())
<GEOMETRYCOLLECTION EMPTY>
>>> shapely.constrained_delaunay_triangles(MultiPoint([(50, 30), (51, 30), (60, 30), (100, 100)]))
<GEOMETRYCOLLECTION EMPTY>
shapely.constructive
Python Library Documentation: module shapely.constructive in shapely
NAME
shapely.constructive - Methods that yield new objects not derived from set-theoretic analysis.
CLASSES
shapely._enum.ParamEnum(enum.IntEnum)
BufferCapStyle
BufferJoinStyle
class BufferCapStyle(shapely._enum.ParamEnum)
| BufferCapStyle(*values)
|
| Enumeration of buffer cap styles.
|
| Attributes
| ----------
| round : int
| Represents a round cap style.
| flat : int
| Represents a flat cap style.
| square : int
| Represents a square cap style.
|
| Method resolution order:
| BufferCapStyle
| shapely._enum.ParamEnum
| enum.IntEnum
| builtins.int
| enum.ReprEnum
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec, /) from builtins.int
| Convert to a string according to format_spec.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| flat = <BufferCapStyle.flat: 2>
|
| round = <BufferCapStyle.round: 1>
|
| square = <BufferCapStyle.square: 3>
|
| ----------------------------------------------------------------------
| Methods inherited from enum.IntEnum:
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__ = __repr__(self, /) from builtins.int
| Return repr(self).
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.int:
|
| __abs__(self, /)
| abs(self)
|
| __add__(self, value, /)
| Return self+value.
|
| __and__(self, value, /)
| Return self&value.
|
| __bool__(self, /)
| True if self else False
|
| __ceil__(...)
| Ceiling of an Integral returns itself.
|
| __divmod__(self, value, /)
| Return divmod(self, value).
|
| __eq__(self, value, /)
| Return self==value.
|
| __float__(self, /)
| float(self)
|
| __floor__(...)
| Flooring an Integral returns itself.
|
| __floordiv__(self, value, /)
| Return self//value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __index__(self, /)
| Return self converted to an integer, if self is suitable for use as an index into a list.
|
| __int__(self, /)
| int(self)
|
| __invert__(self, /)
| ~self
|
| __le__(self, value, /)
| Return self<=value.
|
| __lshift__(self, value, /)
| Return self<<value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __neg__(self, /)
| -self
|
| __or__(self, value, /)
| Return self|value.
|
| __pos__(self, /)
| +self
|
| __pow__(self, value, mod=None, /)
| Return pow(self, value, mod).
|
| __radd__(self, value, /)
| Return value+self.
|
| __rand__(self, value, /)
| Return value&self.
|
| __rdivmod__(self, value, /)
| Return divmod(value, self).
|
| __rfloordiv__(self, value, /)
| Return value//self.
|
| __rlshift__(self, value, /)
| Return value<<self.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __ror__(self, value, /)
| Return value|self.
|
| __round__(...)
| Rounding an Integral returns itself.
|
| Rounding with an ndigits argument also returns an integer.
|
| __rpow__(self, value, mod=None, /)
| Return pow(value, self, mod).
|
| __rrshift__(self, value, /)
| Return value>>self.
|
| __rshift__(self, value, /)
| Return self>>value.
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rtruediv__(self, value, /)
| Return value/self.
|
| __rxor__(self, value, /)
| Return value^self.
|
| __sizeof__(self, /)
| Returns size in memory, in bytes.
|
| __sub__(self, value, /)
| Return self-value.
|
| __truediv__(self, value, /)
| Return self/value.
|
| __trunc__(...)
| Truncating an Integral returns itself.
|
| __xor__(self, value, /)
| Return self^value.
|
| as_integer_ratio(self, /)
| Return a pair of integers, whose ratio is equal to the original int.
|
| The ratio is in lowest terms and has a positive denominator.
|
| >>> (10).as_integer_ratio()
| (10, 1)
| >>> (-10).as_integer_ratio()
| (-10, 1)
| >>> (0).as_integer_ratio()
| (0, 1)
|
| bit_count(self, /)
| Number of ones in the binary representation of the absolute value of self.
|
| Also known as the population count.
|
| >>> bin(13)
| '0b1101'
| >>> (13).bit_count()
| 3
|
| bit_length(self, /)
| Number of bits necessary to represent self in binary.
|
| >>> bin(37)
| '0b100101'
| >>> (37).bit_length()
| 6
|
| conjugate(...)
| Returns self, the complex conjugate of any int.
|
| is_integer(self, /)
| Returns True. Exists for duck type compatibility with float.is_integer.
|
| to_bytes(self, /, length=1, byteorder='big', *, signed=False)
| Return an array of bytes representing an integer.
|
| length
| Length of bytes object to use. An OverflowError is raised if the
| integer is not representable with the given number of bytes. Default
| is length 1.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Determines whether two's complement is used to represent the integer.
| If signed is False and a negative integer is given, an OverflowError
| is raised.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.int:
|
| from_bytes(bytes, byteorder='big', *, signed=False)
| Return the integer represented by the given array of bytes.
|
| bytes
| Holds the array of bytes to convert. The argument must either
| support the buffer protocol or be an iterable object producing bytes.
| Bytes and bytearray are examples of built-in objects that support the
| buffer protocol.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Indicates whether two's complement is used to represent the integer.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.int:
|
| denominator
| the denominator of a rational number in lowest terms
|
| imag
| the imaginary part of a complex number
|
| numerator
| the numerator of a rational number in lowest terms
|
| real
| the real part of a complex number
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Static methods inherited from enum.EnumType:
|
| __contains__(value)
| Return True if `value` is in `cls`.
|
| `value` is in `cls` if:
| 1) `value` is a member of `cls`, or
| 2) `value` is the value of one of the `cls`'s members.
|
| __getitem__(name)
| Return the member matching `name`.
|
| __iter__()
| Return members in definition order.
|
| __len__()
| Return the number of members (no aliases)
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
class BufferJoinStyle(shapely._enum.ParamEnum)
| BufferJoinStyle(*values)
|
| Enumeration of buffer join styles.
|
| Attributes
| ----------
| round : int
| Specifies a round join style.
| mitre : int
| Specifies a mitre join style.
| bevel : int
| Specifies a bevel join style.
|
| Method resolution order:
| BufferJoinStyle
| shapely._enum.ParamEnum
| enum.IntEnum
| builtins.int
| enum.ReprEnum
| enum.Enum
| builtins.object
|
| Methods defined here:
|
| __format__(self, format_spec, /) from builtins.int
| Convert to a string according to format_spec.
|
| __new__(cls, value) from enum.Enum
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| bevel = <BufferJoinStyle.bevel: 3>
|
| mitre = <BufferJoinStyle.mitre: 2>
|
| round = <BufferJoinStyle.round: 1>
|
| ----------------------------------------------------------------------
| Methods inherited from enum.IntEnum:
|
| __repr__(self) from enum.Enum
| Return repr(self).
|
| __str__ = __repr__(self, /) from builtins.int
| Return repr(self).
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.int:
|
| __abs__(self, /)
| abs(self)
|
| __add__(self, value, /)
| Return self+value.
|
| __and__(self, value, /)
| Return self&value.
|
| __bool__(self, /)
| True if self else False
|
| __ceil__(...)
| Ceiling of an Integral returns itself.
|
| __divmod__(self, value, /)
| Return divmod(self, value).
|
| __eq__(self, value, /)
| Return self==value.
|
| __float__(self, /)
| float(self)
|
| __floor__(...)
| Flooring an Integral returns itself.
|
| __floordiv__(self, value, /)
| Return self//value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __getnewargs__(self, /)
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __index__(self, /)
| Return self converted to an integer, if self is suitable for use as an index into a list.
|
| __int__(self, /)
| int(self)
|
| __invert__(self, /)
| ~self
|
| __le__(self, value, /)
| Return self<=value.
|
| __lshift__(self, value, /)
| Return self<<value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __mod__(self, value, /)
| Return self%value.
|
| __mul__(self, value, /)
| Return self*value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __neg__(self, /)
| -self
|
| __or__(self, value, /)
| Return self|value.
|
| __pos__(self, /)
| +self
|
| __pow__(self, value, mod=None, /)
| Return pow(self, value, mod).
|
| __radd__(self, value, /)
| Return value+self.
|
| __rand__(self, value, /)
| Return value&self.
|
| __rdivmod__(self, value, /)
| Return divmod(value, self).
|
| __rfloordiv__(self, value, /)
| Return value//self.
|
| __rlshift__(self, value, /)
| Return value<<self.
|
| __rmod__(self, value, /)
| Return value%self.
|
| __rmul__(self, value, /)
| Return value*self.
|
| __ror__(self, value, /)
| Return value|self.
|
| __round__(...)
| Rounding an Integral returns itself.
|
| Rounding with an ndigits argument also returns an integer.
|
| __rpow__(self, value, mod=None, /)
| Return pow(value, self, mod).
|
| __rrshift__(self, value, /)
| Return value>>self.
|
| __rshift__(self, value, /)
| Return self>>value.
|
| __rsub__(self, value, /)
| Return value-self.
|
| __rtruediv__(self, value, /)
| Return value/self.
|
| __rxor__(self, value, /)
| Return value^self.
|
| __sizeof__(self, /)
| Returns size in memory, in bytes.
|
| __sub__(self, value, /)
| Return self-value.
|
| __truediv__(self, value, /)
| Return self/value.
|
| __trunc__(...)
| Truncating an Integral returns itself.
|
| __xor__(self, value, /)
| Return self^value.
|
| as_integer_ratio(self, /)
| Return a pair of integers, whose ratio is equal to the original int.
|
| The ratio is in lowest terms and has a positive denominator.
|
| >>> (10).as_integer_ratio()
| (10, 1)
| >>> (-10).as_integer_ratio()
| (-10, 1)
| >>> (0).as_integer_ratio()
| (0, 1)
|
| bit_count(self, /)
| Number of ones in the binary representation of the absolute value of self.
|
| Also known as the population count.
|
| >>> bin(13)
| '0b1101'
| >>> (13).bit_count()
| 3
|
| bit_length(self, /)
| Number of bits necessary to represent self in binary.
|
| >>> bin(37)
| '0b100101'
| >>> (37).bit_length()
| 6
|
| conjugate(...)
| Returns self, the complex conjugate of any int.
|
| is_integer(self, /)
| Returns True. Exists for duck type compatibility with float.is_integer.
|
| to_bytes(self, /, length=1, byteorder='big', *, signed=False)
| Return an array of bytes representing an integer.
|
| length
| Length of bytes object to use. An OverflowError is raised if the
| integer is not representable with the given number of bytes. Default
| is length 1.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Determines whether two's complement is used to represent the integer.
| If signed is False and a negative integer is given, an OverflowError
| is raised.
|
| ----------------------------------------------------------------------
| Class methods inherited from builtins.int:
|
| from_bytes(bytes, byteorder='big', *, signed=False)
| Return the integer represented by the given array of bytes.
|
| bytes
| Holds the array of bytes to convert. The argument must either
| support the buffer protocol or be an iterable object producing bytes.
| Bytes and bytearray are examples of built-in objects that support the
| buffer protocol.
| byteorder
| The byte order used to represent the integer. If byteorder is 'big',
| the most significant byte is at the beginning of the byte array. If
| byteorder is 'little', the most significant byte is at the end of the
| byte array. To request the native byte order of the host system, use
| `sys.byteorder' as the byte order value. Default is to use 'big'.
| signed
| Indicates whether two's complement is used to represent the integer.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.int:
|
| denominator
| the denominator of a rational number in lowest terms
|
| imag
| the imaginary part of a complex number
|
| numerator
| the numerator of a rational number in lowest terms
|
| real
| the real part of a complex number
|
| ----------------------------------------------------------------------
| Methods inherited from enum.Enum:
|
| __dir__(self)
| Returns public methods and other interesting attributes.
|
| __init__(self, *args, **kwds)
| Initialize self. See help(type(self)) for accurate signature.
|
| __reduce_ex__(self, proto)
| Helper for pickle.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from enum.Enum:
|
| name
| The name of the Enum member.
|
| value
| The value of the Enum member.
|
| ----------------------------------------------------------------------
| Static methods inherited from enum.EnumType:
|
| __contains__(value)
| Return True if `value` is in `cls`.
|
| `value` is in `cls` if:
| 1) `value` is a member of `cls`, or
| 2) `value` is the value of one of the `cls`'s members.
|
| __getitem__(name)
| Return the member matching `name`.
|
| __iter__()
| Return members in definition order.
|
| __len__()
| Return the number of members (no aliases)
|
| ----------------------------------------------------------------------
| Readonly properties inherited from enum.EnumType:
|
| __members__
| Returns a mapping of member name->value.
|
| This mapping lists all enum members, including aliases. Note that this
| is a read-only view of the internal mapping.
FUNCTIONS
boundary(geometry, **kwargs)
Return the topological boundary of a geometry.
This function will return None for geometrycollections.
Parameters
----------
geometry : Geometry or array_like
Geometry for which to return the boundary.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, LinearRing, LineString, MultiLineString, MultiPoint, Point, Polygon
>>> shapely.boundary(Point(0, 0))
<GEOMETRYCOLLECTION EMPTY>
>>> shapely.boundary(LineString([(0, 0), (1, 1), (1, 2)]))
<MULTIPOINT ((0 0), (1 2))>
>>> shapely.boundary(LinearRing([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]))
<MULTIPOINT EMPTY>
>>> shapely.boundary(Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]))
<LINESTRING (0 0, 1 0, 1 1, 0 1, 0 0)>
>>> shapely.boundary(MultiPoint([(0, 0), (1, 2)]))
<GEOMETRYCOLLECTION EMPTY>
>>> shapely.boundary(MultiLineString([[(0, 0), (1, 1)], [(0, 1), (1, 0)]]))
<MULTIPOINT ((0 0), (0 1), (1 0), (1 1))>
>>> shapely.boundary(GeometryCollection([Point(0, 0)])) is None
True
buffer(geometry, distance, quad_segs=8, cap_style='round', join_style='round', mitre_limit=5.0, single_sided=False, **kwargs)
Compute the buffer of a geometry for positive and negative buffer distance.
The buffer of a geometry is defined as the Minkowski sum (or difference,
for negative distance) of the geometry with a circle with radius equal
to the absolute value of the buffer distance.
The buffer operation always returns a polygonal result. The negative
or zero-distance buffer of lines and points is always empty.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the buffer.
distance : float or array_like
Specifies the circle radius in the Minkowski sum (or difference).
quad_segs : int, default 8
Specifies the number of linear segments in a quarter circle in the
approximation of circular arcs.
cap_style : shapely.BufferCapStyle or {'round', 'square', 'flat'}, 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 {'round', 'mitre', 'bevel'}, 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, default 5.0
Crops of 'mitre'-style joins if the point is displaced from the
buffered vertex by more than this limit.
single_sided : bool, default False
Only buffer at one side of the geometry.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``quad_segs``, ``cap_style``,
``join_style``, ``mitre_limit`` or ``single_sided`` are
specified as positional arguments. In a future release, these will
need to be specified as keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point, Polygon, BufferCapStyle, BufferJoinStyle
>>> shapely.buffer(Point(10, 10), 2, quad_segs=1)
<POLYGON ((12 10, 10 8, 8 10, 10 12, 12 10))>
>>> shapely.buffer(Point(10, 10), 2, quad_segs=2)
<POLYGON ((12 10, 11.414 8.586, 10 8, 8.586 8.586, 8 10, 8.5...>
>>> shapely.buffer(Point(10, 10), -2, quad_segs=1)
<POLYGON EMPTY>
>>> line = LineString([(10, 10), (20, 10)])
>>> shapely.buffer(line, 2, cap_style="square")
<POLYGON ((20 12, 22 12, 22 8, 10 8, 8 8, 8 12, 20 12))>
>>> shapely.buffer(line, 2, cap_style="flat")
<POLYGON ((20 12, 20 8, 10 8, 10 12, 20 12))>
>>> shapely.buffer(line, 2, single_sided=True, cap_style="flat")
<POLYGON ((20 10, 10 10, 10 12, 20 12, 20 10))>
>>> line2 = LineString([(10, 10), (20, 10), (20, 20)])
>>> shapely.buffer(line2, 2, cap_style="flat", join_style="bevel")
<POLYGON ((18 12, 18 20, 22 20, 22 10, 20 8, 10 8, 10 12, 18 12))>
>>> shapely.buffer(line2, 2, cap_style="flat", join_style="mitre")
<POLYGON ((18 12, 18 20, 22 20, 22 8, 10 8, 10 12, 18 12))>
>>> shapely.buffer(line2, 2, cap_style="flat", join_style="mitre", mitre_limit=1)
<POLYGON ((18 12, 18 20, 22 20, 22 9.172, 20.828 8, 10 8, 10 12, 18 12))>
>>> square = Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)])
>>> shapely.buffer(square, 2, join_style="mitre")
<POLYGON ((-2 -2, -2 12, 12 12, 12 -2, -2 -2))>
>>> shapely.buffer(square, -2, join_style="mitre")
<POLYGON ((2 2, 2 8, 8 8, 8 2, 2 2))>
>>> shapely.buffer(square, -5, join_style="mitre")
<POLYGON EMPTY>
>>> shapely.buffer(line, float("nan")) is None
True
build_area(geometry, **kwargs)
Create an areal geometry formed by the constituent linework of given geometry.
Equivalent of the PostGIS ST_BuildArea() function.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to build an area.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, Polygon
>>> polygon1 = Polygon([(0, 0), (3, 0), (3, 3), (0, 3), (0, 0)])
>>> polygon2 = Polygon([(1, 1), (1, 2), (2, 2), (1, 1)])
>>> shapely.build_area(GeometryCollection([polygon1, polygon2]))
<POLYGON ((0 0, 0 3, 3 3, 3 0, 0 0), (1 1, 2 2, 1 2, 1 1))>
centroid(geometry, **kwargs)
Compute the geometric center (center-of-mass) of a geometry.
For multipoints this is computed as the mean of the input coordinates.
For multilinestrings the centroid is weighted by the length of each
line segment. For multipolygons the centroid is weighted by the area of
each polygon.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the centroid.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, MultiPoint, Polygon
>>> shapely.centroid(Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]))
<POINT (5 5)>
>>> shapely.centroid(LineString([(0, 0), (2, 2), (10, 10)]))
<POINT (5 5)>
>>> shapely.centroid(MultiPoint([(0, 0), (10, 10)]))
<POINT (5 5)>
>>> shapely.centroid(Polygon())
<POINT EMPTY>
clip_by_rect(geometry, xmin, ymin, xmax, ymax, **kwargs)
Return the portion of a geometry within a rectangle.
The geometry is clipped in a fast but possibly dirty way. The output is
not guaranteed to be valid. No exceptions will be raised for topological
errors.
Note: empty geometries or geometries that do not overlap with the
specified bounds will result in GEOMETRYCOLLECTION EMPTY.
Parameters
----------
geometry : Geometry or array_like
The geometry to be clipped.
xmin : float
Minimum x value of the rectangle.
ymin : float
Minimum y value of the rectangle.
xmax : float
Maximum x value of the rectangle.
ymax : float
Maximum y value of the rectangle.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Polygon
>>> line = LineString([(0, 0), (10, 10)])
>>> shapely.clip_by_rect(line, 0., 0., 1., 1.)
<LINESTRING (0 0, 1 1)>
>>> polygon = Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)])
>>> shapely.clip_by_rect(polygon, 0., 0., 1., 1.)
<POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
concave_hull(geometry, ratio=0.0, allow_holes=False, **kwargs)
Compute a concave geometry that encloses an input geometry.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the concave hull.
ratio : float, default 0.0
Number in the range [0, 1]. Higher numbers will include fewer vertices
in the hull.
allow_holes : bool, default False
If set to True, the concave hull may have holes.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import MultiPoint, Polygon
>>> multi_point = MultiPoint([(0, 0), (0, 3), (1, 1), (3, 0), (3, 3)])
>>> shapely.concave_hull(multi_point, ratio=0.1)
<POLYGON ((0 0, 0 3, 1 1, 3 3, 3 0, 0 0))>
>>> shapely.concave_hull(multi_point, ratio=1.0)
<POLYGON ((0 0, 0 3, 3 3, 3 0, 0 0))>
>>> shapely.concave_hull(Polygon())
<POLYGON EMPTY>
constrained_delaunay_triangles(geometry, **kwargs)
Compute the constrained Delaunay triangulation of polygons.
A constrained Delaunay triangulation requires the edges of the input
polygon(s) to be in the set of resulting triangle edges. An unconstrained
delaunay triangulation only triangulates based on the vertices, hence
triangle edges could cross polygon boundaries.
.. versionadded:: 2.1.0
Parameters
----------
geometry : Geometry or array_like
**kwargs
For other keyword-only arguments, see the
`NumPy ufunc docs <https://numpy.org/doc/stable/reference/ufuncs.html#ufuncs-kwargs>`_.
Returns
-------
GeometryCollection or array of GeometryCollections
* GeometryCollection of polygons, given polygonal input
* Empty GeometryCollection, given non-polygonal input
See Also
--------
delaunay_triangles
Examples
--------
>>> import shapely
>>> from shapely import MultiPoint, MultiPolygon, Polygon
>>> shapely.constrained_delaunay_triangles(Polygon([(10, 10), (20, 40), (90, 90), (90, 10), (10, 10)]))
<GEOMETRYCOLLECTION (POLYGON ((90 10, 20 40, 90 90, 90 10)), POLYGON ((20 40...>
>>> shapely.constrained_delaunay_triangles(Polygon())
<GEOMETRYCOLLECTION EMPTY>
>>> shapely.constrained_delaunay_triangles(MultiPolygon([Polygon(((50, 30), (60, 30), (100, 100), (50, 30))), Polygon(((10, 10), (20, 40), (90, 90), (90, 10), (10, 10)))]))
<GEOMETRYCOLLECTION (POLYGON ((50 30, 100 100, 60 30, 50 30)), POLYGON ((90 ...>
>>> shapely.constrained_delaunay_triangles(MultiPolygon())
<GEOMETRYCOLLECTION EMPTY>
>>> shapely.constrained_delaunay_triangles(MultiPoint([(50, 30), (51, 30), (60, 30), (100, 100)]))
<GEOMETRYCOLLECTION EMPTY>
convex_hull(geometry, **kwargs)
Compute the minimum convex geometry that encloses an input geometry.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the convex hull.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import MultiPoint, Polygon
>>> shapely.convex_hull(MultiPoint([(0, 0), (10, 0), (10, 10)]))
<POLYGON ((0 0, 10 10, 10 0, 0 0))>
>>> shapely.convex_hull(Polygon())
<GEOMETRYCOLLECTION EMPTY>
delaunay_triangles(geometry, tolerance=0.0, only_edges=False, **kwargs)
Compute a Delaunay triangulation around the vertices of an input geometry.
The output is a geometrycollection containing polygons (default)
or linestrings (see ``only_edges``). Returns an empty geometry for input
geometries that contain less than 3 vertices.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the Delaunay triangulation.
tolerance : float or array_like, default 0.0
Snap input vertices together if their distance is less than this value.
only_edges : bool or array_like, default False
If set to True, the triangulation will return a collection of
linestrings instead of polygons.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Returns
-------
GeometryCollection or array of GeometryCollections
See Also
--------
constrained_delaunay_triangles
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, LineString, MultiPoint, Polygon
>>> points = MultiPoint([(50, 30), (60, 30), (100, 100)])
>>> shapely.delaunay_triangles(points).normalize()
<GEOMETRYCOLLECTION (POLYGON ((50 30, 100 100, 60 30, 50 30)))>
>>> shapely.delaunay_triangles(points, only_edges=True)
<MULTILINESTRING ((50 30, 100 100), (50 30, 60 30), ...>
>>> shapely.delaunay_triangles(
... MultiPoint([(50, 30), (51, 30), (60, 30), (100, 100)]),
... tolerance=2
... ).normalize()
<GEOMETRYCOLLECTION (POLYGON ((50 30, 100 100, 60 30, 50 30)))>
>>> shapely.delaunay_triangles(Polygon([(50, 30), (60, 30), (100, 100), (50, 30)])).normalize()
<GEOMETRYCOLLECTION (POLYGON ((50 30, 100 100, 60 30, 50 30)))>
>>> shapely.delaunay_triangles(LineString([(50, 30), (60, 30), (100, 100)])).normalize()
<GEOMETRYCOLLECTION (POLYGON ((50 30, 100 100, 60 30, 50 30)))>
>>> shapely.delaunay_triangles(GeometryCollection([]))
<GEOMETRYCOLLECTION EMPTY>
envelope(geometry, **kwargs)
Compute the minimum bounding box that encloses an input geometry.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the envelope.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, LineString, MultiPoint, Point
>>> shapely.envelope(LineString([(0, 0), (10, 10)]))
<POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))>
>>> shapely.envelope(MultiPoint([(0, 0), (10, 10)]))
<POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))>
>>> shapely.envelope(Point(0, 0))
<POINT (0 0)>
>>> shapely.envelope(GeometryCollection([]))
<POINT EMPTY>
extract_unique_points(geometry, **kwargs)
Return all distinct vertices of an input geometry as a multipoint.
Note that only 2 dimensions of the vertices are considered when testing
for equality.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to extract unique points.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, MultiPoint, Point, Polygon
>>> shapely.extract_unique_points(Point(0, 0))
<MULTIPOINT ((0 0))>
>>> shapely.extract_unique_points(LineString([(0, 0), (1, 1), (1, 1)]))
<MULTIPOINT ((0 0), (1 1))>
>>> shapely.extract_unique_points(Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]))
<MULTIPOINT ((0 0), (1 0), (1 1), (0 1))>
>>> shapely.extract_unique_points(MultiPoint([(0, 0), (1, 1), (0, 0)]))
<MULTIPOINT ((0 0), (1 1))>
>>> shapely.extract_unique_points(LineString())
<MULTIPOINT EMPTY>
make_valid(geometry, *, method='linework', keep_collapsed=True, **kwargs)
Repair invalid geometries.
Two ``methods`` are available:
* the 'linework' algorithm tries to preserve every edge and vertex in the input. It
combines all rings into a set of noded lines and then extracts valid polygons from
that linework. An alternating even-odd strategy is used to assign areas as
interior or exterior. A disadvantage is that for some relatively simple invalid
geometries this produces rather complex results.
* the 'structure' algorithm tries to reason from the structure of the input to find
the 'correct' repair: exterior rings bound area, interior holes exclude area.
It first makes all rings valid, then shells are merged and holes are subtracted
from the shells to generate valid result. It assumes that holes and shells are
correctly categorized in the input geometry.
Example:
.. plot:: code/make_valid_methods.py
When using ``make_valid`` on a Polygon, the result can be a GeometryCollection. For
this example this is the case when the 'linework' ``method`` is used. LineStrings in
the result are drawn in red.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to repair.
method : {'linework', 'structure'}, default 'linework'
Algorithm to use when repairing geometry. 'structure'
requires GEOS >= 3.10.
.. versionadded:: 2.1.0
keep_collapsed : bool, default True
For the 'structure' method, True will keep components that have collapsed into a
lower dimensionality. For example, a ring collapsing to a line, or a line
collapsing to a point. Must be True for the 'linework' method.
.. versionadded:: 2.1.0
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import Polygon
>>> polygon = Polygon([(0, 0), (1, 1), (1, 2), (1, 1), (0, 0)])
>>> shapely.is_valid(polygon)
False
>>> shapely.make_valid(polygon)
<MULTILINESTRING ((0 0, 1 1), (1 1, 1 2))>
>>> shapely.make_valid(polygon, method="structure", keep_collapsed=True)
<LINESTRING (0 0, 1 1, 1 2, 1 1, 0 0)>
>>> shapely.make_valid(polygon, method="structure", keep_collapsed=False)
<POLYGON EMPTY>
maximum_inscribed_circle(geometry, tolerance=None, **kwargs)
Find the largest circle that is fully contained within the input geometry.
Constructs the "maximum inscribed circle" (MIC) for a polygonal geometry,
up to a specified tolerance. The MIC is determined by a point in the
interior of the area which has the farthest distance from the area
boundary, along with a boundary point at that distance. In the context of
geography the center of the MIC is known as the "pole of inaccessibility".
A cartographic use case is to determine a suitable point to place a map
label within a polygon.
The radius length of the MIC is a measure of how "narrow" a polygon is.
It is the distance at which the negative buffer becomes empty.
The function supports polygons with holes and multipolygons.
Returns a two-point linestring, with the first point at the center of the
inscribed circle and the second on the boundary of the inscribed circle.
.. versionadded:: 2.1.0
Parameters
----------
geometry : Geometry or array_like
tolerance : float or array_like, optional
Stop the algorithm when the search area is smaller than this tolerance.
When not specified, uses `max(width, height) / 1000` per geometry as
the default.
**kwargs
For other keyword-only arguments, see the
`NumPy ufunc docs <https://numpy.org/doc/stable/reference/ufuncs.html#ufuncs-kwargs>`_.
Examples
--------
>>> import shapely
>>> from shapely import Polygon
>>> poly = Polygon([(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)])
>>> shapely.maximum_inscribed_circle(poly)
<LINESTRING (5 5, 0 5)>
See Also
--------
minimum_bounding_circle
minimum_bounding_circle(geometry, **kwargs)
Compute the minimum bounding circle that encloses an input geometry.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the minimum bounding circle.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, LineString, MultiPoint, Point, Polygon
>>> shapely.minimum_bounding_circle(
... Polygon([(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)])
... )
<POLYGON ((12.071 5, 11.935 3.621, 11.533 2.294, 10.879 1.07...>
>>> shapely.minimum_bounding_circle(LineString([(1, 1), (10, 10)]))
<POLYGON ((11.864 5.5, 11.742 4.258, 11.38 3.065, 10.791 1.9...>
>>> shapely.minimum_bounding_circle(MultiPoint([(2, 2), (4, 2)]))
<POLYGON ((4 2, 3.981 1.805, 3.924 1.617, 3.831 1.444, 3.707...>
>>> shapely.minimum_bounding_circle(Point(0, 1))
<POINT (0 1)>
>>> shapely.minimum_bounding_circle(GeometryCollection([]))
<POLYGON EMPTY>
See Also
--------
minimum_bounding_radius, maximum_inscribed_circle
minimum_clearance_line(geometry, **kwargs)
Return a LineString whose endpoints define the minimum clearance.
A geometry's "minimum clearance" is the smallest distance by which a vertex
of the geometry could be moved to produce an invalid geometry.
If the geometry has no minimum clearance, an empty LineString will be
returned.
.. versionadded:: 2.1.0
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to determine the minimum clearance line for.
**kwargs
For other keyword-only arguments, see the
`NumPy ufunc docs <https://numpy.org/doc/stable/reference/ufuncs.html#ufuncs-kwargs>`_.
Examples
--------
>>> import shapely
>>> from shapely import Polygon
>>> poly = Polygon([(0, 0), (10, 0), (10, 10), (5, 5), (0, 10), (0, 0)])
>>> shapely.minimum_clearance_line(poly)
<LINESTRING (5 5, 5 0)>
See Also
--------
minimum_clearance
minimum_rotated_rectangle = oriented_envelope(geometry, **kwargs)
Compute the oriented envelope (minimum rotated rectangle) of the input 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
:func:`~shapely.normalize` to reorganize the rectangle to
:ref:`strict canonical form <canonical-form>` so the starting point is
always the lower left point.
``minimum_rotated_rectangle`` is an alias for ``oriented_envelope``.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the oriented envelope.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, LineString, MultiPoint, Point, Polygon
>>> shapely.oriented_envelope(MultiPoint([(0, 0), (10, 0), (10, 10)])).normalize()
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))>
>>> shapely.oriented_envelope(LineString([(1, 1), (5, 1), (10, 10)])).normalize()
<POLYGON ((1 1, 10 10, 12 8, 3 -1, 1 1))>
>>> shapely.oriented_envelope(Polygon([(1, 1), (15, 1), (5, 10), (1, 1)])).normalize()
<POLYGON ((1 1, 5 10, 16.691 4.804, 12.691 -4.196, 1 1))>
>>> shapely.oriented_envelope(LineString([(1, 1), (10, 1)])).normalize()
<LINESTRING (1 1, 10 1)>
>>> shapely.oriented_envelope(Point(2, 2))
<POINT (2 2)>
>>> shapely.oriented_envelope(GeometryCollection([]))
<POLYGON EMPTY>
node(geometry, **kwargs)
Return the fully noded version of the linear input as MultiLineString.
Given a linear input geometry, this function returns a new MultiLineString
in which no lines cross each other but only touch at and points. To
obtain this, all intersections between segments are computed and added
to the segments, and duplicate segments are removed.
Non-linear input (points) will result in an empty MultiLineString.
This function can for example be used to create a fully-noded linework
suitable to passed as input to ``polygonize``.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the noded version.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> line = LineString([(0, 0), (1,1), (0, 1), (1, 0)])
>>> shapely.node(line)
<MULTILINESTRING ((0 0, 0.5 0.5), (0.5 0.5, 1 1, 0 1, 0.5 0.5), (0.5 0.5, 1 0))>
>>> shapely.node(Point(1, 1))
<MULTILINESTRING EMPTY>
normalize(geometry, **kwargs)
Convert Geometry to strict normal form (or canonical form).
In :ref:`strict canonical form <canonical-form>`, the coordinates, rings of
a polygon and parts of multi geometries are ordered consistently. Typically
useful for testing purposes (for example in combination with
``equals_exact``).
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to normalize.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import MultiLineString
>>> line = MultiLineString([[(0, 0), (1, 1)], [(2, 2), (3, 3)]])
>>> shapely.normalize(line)
<MULTILINESTRING ((2 2, 3 3), (0 0, 1 1))>
offset_curve(geometry, distance, quad_segs=8, join_style='round', mitre_limit=5.0, **kwargs)
Return a (Multi)LineString at a distance from the object.
For positive distance the offset will be at the left side of the input
line. For a negative distance it will be at the right side. In general,
this function tries to preserve the direction of the input.
Note: the behaviour regarding orientation of the resulting line depends
on the GEOS version. With GEOS < 3.11, the line retains the same
direction for a left offset (positive distance) or has opposite direction
for a right offset (negative distance), and this behaviour was documented
as such in previous Shapely versions. Starting with GEOS 3.11, the
function tries to preserve the orientation of the original line.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the offset.
distance : float or array_like
Specifies the offset distance from the input geometry. Negative
for right side offset, positive for left side offset.
quad_segs : int, default 8
Specifies the number of linear segments in a quarter circle in the
approximation of circular arcs.
join_style : {'round', 'bevel', 'mitre'}, default 'round'
Specifies the shape of outside corners. 'round' results in
rounded shapes. 'bevel' results in a beveled edge that touches the
original vertex. 'mitre' results in a single vertex that is beveled
depending on the ``mitre_limit`` parameter.
mitre_limit : float, default 5.0
Crops of 'mitre'-style joins if the point is displaced from the
buffered vertex by more than this limit.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``quad_segs``, ``join_style`` or
``mitre_limit`` are specified as positional arguments. In a future
release, these will need to be specified as keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString
>>> line = LineString([(0, 0), (0, 2)])
>>> shapely.offset_curve(line, 2)
<LINESTRING (-2 0, -2 2)>
>>> shapely.offset_curve(line, -2)
<LINESTRING (2 0, 2 2)>
orient_polygons(geometry, *, exterior_cw=False, **kwargs)
Enforce a ring orientation on all polygonal elements in the input geometry.
Forces (Multi)Polygons to use a counter-clockwise orientation for their
exterior ring, and a clockwise orientation for their interior rings (or
the oppposite if ``exterior_cw=True``).
Also processes geometries inside a GeometryCollection in the same way.
Other geometries are returned unchanged.
.. versionadded:: 2.1.0
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to orient consistently.
exterior_cw : bool, default False
If True, exterior rings will be clockwise and interior rings
will be counter-clockwise.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
A polygon with both shell and hole having clockwise orientation:
>>> from shapely import Polygon, orient_polygons
>>> polygon = Polygon(
... [(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)],
... holes=[[(2, 2), (2, 4), (4, 4), (4, 2), (2, 2)]],
... )
>>> polygon
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0), (2 2, 2 4, 4 4, 4 2, 2 2))>
By default, the exterior ring is oriented counter-clockwise and
the holes clockwise:
>>> orient_polygons(polygon)
<POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (2 2, 2 4, 4 4, 4 2, 2 2))>
Asking for the opposite orientation:
>>> orient_polygons(polygon, exterior_cw=True)
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0), (2 2, 4 2, 4 4, 2 4, 2 2))>
oriented_envelope(geometry, **kwargs)
Compute the oriented envelope (minimum rotated rectangle) of the input 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
:func:`~shapely.normalize` to reorganize the rectangle to
:ref:`strict canonical form <canonical-form>` so the starting point is
always the lower left point.
``minimum_rotated_rectangle`` is an alias for ``oriented_envelope``.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the oriented envelope.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, LineString, MultiPoint, Point, Polygon
>>> shapely.oriented_envelope(MultiPoint([(0, 0), (10, 0), (10, 10)])).normalize()
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))>
>>> shapely.oriented_envelope(LineString([(1, 1), (5, 1), (10, 10)])).normalize()
<POLYGON ((1 1, 10 10, 12 8, 3 -1, 1 1))>
>>> shapely.oriented_envelope(Polygon([(1, 1), (15, 1), (5, 10), (1, 1)])).normalize()
<POLYGON ((1 1, 5 10, 16.691 4.804, 12.691 -4.196, 1 1))>
>>> shapely.oriented_envelope(LineString([(1, 1), (10, 1)])).normalize()
<LINESTRING (1 1, 10 1)>
>>> shapely.oriented_envelope(Point(2, 2))
<POINT (2 2)>
>>> shapely.oriented_envelope(GeometryCollection([]))
<POLYGON EMPTY>
point_on_surface(geometry, **kwargs)
Return a point that intersects an input geometry.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute a point on the surface.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, MultiPoint, Polygon
>>> shapely.point_on_surface(Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]))
<POINT (5 5)>
>>> shapely.point_on_surface(LineString([(0, 0), (2, 2), (10, 10)]))
<POINT (2 2)>
>>> shapely.point_on_surface(MultiPoint([(0, 0), (10, 10)]))
<POINT (0 0)>
>>> shapely.point_on_surface(Polygon())
<POINT EMPTY>
polygonize(geometries, **kwargs)
Create polygons formed from the linework of a set of Geometries.
Polygonizes an array of Geometries that contain linework which
represents the edges of a planar graph. Any type of Geometry may be
provided as input; only the constituent lines and rings will be used to
create the output polygons.
Lines or rings that when combined do not completely close a polygon
will result in an empty GeometryCollection. Duplicate segments are
ignored.
This function returns the polygons within a GeometryCollection.
Individual Polygons can be obtained using ``get_geometry`` to get
a single polygon or ``get_parts`` to get an array of polygons.
MultiPolygons can be constructed from the output using
``shapely.multipolygons(shapely.get_parts(shapely.polygonize(geometries)))``.
Parameters
----------
geometries : array_like
An array of geometries.
axis : int
Axis along which the geometries are polygonized.
The default is to perform a reduction over the last dimension
of the input array. A 1D array results in a scalar geometry.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Returns
-------
GeometryCollection or array of GeometryCollections
See Also
--------
get_parts, get_geometry
polygonize_full
node
Examples
--------
>>> import shapely
>>> from shapely import LineString
>>> lines = [
... LineString([(0, 0), (1, 1)]),
... LineString([(0, 0), (0, 1)]),
... LineString([(0, 1), (1, 1)])
... ]
>>> shapely.polygonize(lines)
<GEOMETRYCOLLECTION (POLYGON ((1 1, 0 0, 0 1, 1 1)))>
polygonize_full(geometries, **kwargs)
Create polygons formed from the linework of a set of Geometries.
All extra outputs are returned as well.
Polygonizes an array of Geometries that contain linework which
represents the edges of a planar graph. Any type of Geometry may be
provided as input; only the constituent lines and rings will be used to
create the output polygons.
This function performs the same polygonization as ``polygonize`` but does
not only return the polygonal result but all extra outputs as well. The
return value consists of 4 elements:
* The polygonal valid output
* **Cut edges**: edges connected on both ends but not part of polygonal output
* **dangles**: edges connected on one end but not part of polygonal output
* **invalid rings**: polygons formed but which are not valid
This function returns the geometries within GeometryCollections.
Individual geometries can be obtained using ``get_geometry`` to get
a single geometry or ``get_parts`` to get an array of geometries.
Parameters
----------
geometries : array_like
An array of geometries.
axis : int
Axis along which the geometries are polygonized.
The default is to perform a reduction over the last dimension
of the input array. A 1D array results in a scalar geometry.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Returns
-------
(polygons, cuts, dangles, invalid)
tuple of 4 GeometryCollections or arrays of GeometryCollections
See Also
--------
polygonize
Examples
--------
>>> import shapely
>>> from shapely import LineString
>>> lines = [
... LineString([(0, 0), (1, 1)]),
... LineString([(0, 0), (0, 1), (1, 1)]),
... LineString([(0, 1), (1, 1)])
... ]
>>> shapely.polygonize_full(lines)
(<GEOMETRYCOLLECTION (POLYGON ((1 1, 0 0, 0 1, 1 1)))>,
<GEOMETRYCOLLECTION EMPTY>,
<GEOMETRYCOLLECTION (LINESTRING (0 1, 1 1))>,
<GEOMETRYCOLLECTION EMPTY>)
remove_repeated_points(geometry, tolerance=0.0, **kwargs)
Return a copy of a Geometry with repeated points removed.
From the start of the coordinate sequence, each next point within the
tolerance is removed.
Removing repeated points with a non-zero tolerance may result in an invalid
geometry being returned.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to remove repeated points from.
tolerance : float or array_like, default=0.0
Use 0.0 to remove only exactly repeated points.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Polygon
>>> shapely.remove_repeated_points(LineString([(0,0), (0,0), (1,0)]), tolerance=0)
<LINESTRING (0 0, 1 0)>
>>> shapely.remove_repeated_points(Polygon([(0, 0), (0, .5), (0, 1), (.5, 1), (0,0)]), tolerance=.5)
<POLYGON ((0 0, 0 1, 0 0))>
reverse(geometry, **kwargs)
Return a copy of a Geometry with the order of coordinates reversed.
If a Geometry is a polygon with interior rings, the interior rings are also
reversed.
Points are unchanged. None is returned where Geometry is None.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to reverse the coordinates of.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
is_ccw : Checks if a Geometry is clockwise.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Polygon
>>> shapely.reverse(LineString([(0, 0), (1, 2)]))
<LINESTRING (1 2, 0 0)>
>>> shapely.reverse(Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]))
<POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
>>> shapely.reverse(None) is None
True
segmentize(geometry, max_segment_length, **kwargs)
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.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to segmentize.
max_segment_length : float or array_like
Additional vertices will be added so that all line segments are no
longer than this value. Must be greater than 0.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Polygon
>>> line = LineString([(0, 0), (0, 10)])
>>> shapely.segmentize(line, max_segment_length=5)
<LINESTRING (0 0, 0 5, 0 10)>
>>> polygon = Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)])
>>> shapely.segmentize(polygon, max_segment_length=5)
<POLYGON ((0 0, 5 0, 10 0, 10 5, 10 10, 5 10, 0 10, 0 5, 0 0))>
>>> shapely.segmentize(None, max_segment_length=5) is None
True
simplify(geometry, tolerance, preserve_topology=True, **kwargs)
Return a simplified version of an input geometry.
The Douglas-Peucker algorithm is used to simplify the geometry.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to simplify.
tolerance : float or array_like
The maximum allowed geometry displacement. The higher this value, the
smaller the number of vertices in the resulting geometry.
preserve_topology : bool, default True
By default (True), the operation will avoid creating invalid
geometries (checking for collapses, ring-intersections, etc), but
this is computationally more expensive.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``preserve_topology`` is specified as
a positional argument. This will need to be specified as a keyword
argument in a future release.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Polygon
>>> line = LineString([(0, 0), (1, 10), (0, 20)])
>>> shapely.simplify(line, tolerance=0.9)
<LINESTRING (0 0, 1 10, 0 20)>
>>> shapely.simplify(line, tolerance=1)
<LINESTRING (0 0, 0 20)>
>>> polygon_with_hole = Polygon(
... [(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)],
... holes=[[(2, 2), (2, 4), (4, 4), (4, 2), (2, 2)]]
... )
>>> shapely.simplify(polygon_with_hole, tolerance=4, preserve_topology=True)
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0), (4 2, 2 4, 4 4, 4 2))>
>>> shapely.simplify(polygon_with_hole, tolerance=4, preserve_topology=False)
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))>
snap(geometry, reference, tolerance, **kwargs)
Snap the vertices and segments of the geometry to vertices of the reference.
Vertices and segments of the input geometry are snapped to vertices of the
reference geometry, returning a new geometry; the input geometries are not
modified. The result geometry is the input geometry with the vertices and
segments snapped. If no snapping occurs then the input geometry is returned
unchanged. The tolerance is used to control where snapping is performed.
Where possible, this operation tries to avoid creating invalid geometries;
however, it does not guarantee that output geometries will be valid. It is
the responsibility of the caller to check for and handle invalid geometries.
Because too much snapping can result in invalid geometries being created,
heuristics are used to determine the number and location of snapped
vertices that are likely safe to snap. These heuristics may omit
some potential snaps that are otherwise within the tolerance.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to snap.
reference : Geometry or array_like
Geometry or geometries to snap to.
tolerance : float or array_like
The maximum distance between the input and reference geometries for
snapping to occur. A value of 0 will snap only identical points.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point, Polygon, MultiPoint
>>> point = Point(0.5, 2.5)
>>> target_point = Point(0, 2)
>>> shapely.snap(point, target_point, tolerance=1)
<POINT (0 2)>
>>> shapely.snap(point, target_point, tolerance=0.49)
<POINT (0.5 2.5)>
>>> polygon = Polygon([(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)])
>>> shapely.snap(polygon, Point(8, 10), tolerance=5)
<POLYGON ((0 0, 0 10, 8 10, 10 0, 0 0))>
>>> shapely.snap(polygon, LineString([(8, 10), (8, 0)]), tolerance=5)
<POLYGON ((0 0, 0 10, 8 10, 8 0, 0 0))>
You can snap one line to another, for example to clean imprecise coordinates:
>>> line1 = LineString([(0.1, 0.1), (0.49, 0.51), (1.01, 0.89)])
>>> line2 = LineString([(0, 0), (0.5, 0.5), (1.0, 1.0)])
>>> shapely.snap(line1, line2, 0.25)
<LINESTRING (0 0, 0.5 0.5, 1 1)>
Snapping also supports Z coordinates:
>>> point1 = Point(0.1, 0.1, 0.5)
>>> multipoint = MultiPoint([(0, 0, 1), (0, 0, 0)])
>>> shapely.snap(point1, multipoint, 1)
<POINT Z (0 0 1)>
Snapping to an empty geometry has no effect:
>>> shapely.snap(line1, LineString([]), 0.25)
<LINESTRING (0.1 0.1, 0.49 0.51, 1.01 0.89)>
Snapping to a non-geometry (None) will always return None:
>>> shapely.snap(line1, None, 0.25) is None
True
Only one vertex of a polygon is snapped to a target point,
even if all vertices are equidistant to it,
in order to prevent collapse of the polygon:
>>> poly = shapely.box(0, 0, 1, 1)
>>> poly
<POLYGON ((1 0, 1 1, 0 1, 0 0, 1 0))>
>>> shapely.snap(poly, Point(0.5, 0.5), 1)
<POLYGON ((0.5 0.5, 1 1, 0 1, 0 0, 0.5 0.5))>
voronoi_polygons(geometry, tolerance=0.0, extend_to=None, only_edges=False, ordered=False, **kwargs)
Compute a Voronoi diagram from the vertices of an input geometry.
The output is a geometrycollection containing polygons (default)
or linestrings (see only_edges). Returns empty if an input geometry
contains less than 2 vertices or if the provided extent has zero area.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the Voronoi diagram.
tolerance : float or array_like, default 0.0
Snap input vertices together if their distance is less than this value.
extend_to : Geometry or array_like, optional
If provided, the diagram will be extended to cover the envelope of this
geometry (unless this envelope is smaller than the input geometry).
only_edges : bool or array_like, default False
If set to True, the triangulation will return a collection of
linestrings instead of polygons.
ordered : bool or array_like, default False
If set to True, polygons within the GeometryCollection will be ordered
according to the order of the input vertices. Note that this may slow
down the computation. Requires GEOS >= 3.12.0.
.. versionadded:: 2.1.0
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``extend_to``, ``only_edges`` or
``ordered`` are specified as positional arguments. In a future
release, these will need to be specified as keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, MultiPoint, Point
>>> points = MultiPoint([(2, 2), (4, 2)])
>>> shapely.voronoi_polygons(points).normalize()
<GEOMETRYCOLLECTION (POLYGON ((3 0, 3 4, 6 4, 6 0, 3 0)), POLYGON ((0 0, 0 4...>
>>> shapely.voronoi_polygons(points, only_edges=True)
<MULTILINESTRING ((3 4, 3 0))>
>>> shapely.voronoi_polygons(MultiPoint([(2, 2), (4, 2), (4.2, 2)]), 0.5, only_edges=True)
<MULTILINESTRING ((3 4.2, 3 -0.2))>
>>> shapely.voronoi_polygons(points, extend_to=LineString([(0, 0), (10, 10)]), only_edges=True)
<MULTILINESTRING ((3 10, 3 0))>
>>> shapely.voronoi_polygons(LineString([(2, 2), (4, 2)]), only_edges=True)
<MULTILINESTRING ((3 4, 3 0))>
>>> shapely.voronoi_polygons(Point(2, 2))
<GEOMETRYCOLLECTION EMPTY>
>>> shapely.voronoi_polygons(points, ordered=True)
<GEOMETRYCOLLECTION (POLYGON ((0 0, 0 4, 3 4, 3 0, 0 0)), POLYGON ((6 4, 6 0...>
DATA
__all__ = ['BufferCapStyle', 'BufferJoinStyle', 'boundary', 'buffer', ...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\shapely\constructive.py
shapely.contains
Python Library Documentation: function contains in module shapely.predicates
contains(a, b, **kwargs)
Return True if geometry B is completely inside geometry A.
A contains B if no points of B lie in the exterior of A and at least one
point of the interior of B lies in the interior of A.
Note: following this definition, a geometry does not contain its boundary,
but it does contain itself. See ``contains_properly`` for a version where
a geometry does not contain itself.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
within : ``contains(A, B) == within(B, A)``
contains_properly : contains with no common boundary points
prepare : improve performance by preparing ``a`` (the first argument)
contains_xy : variant for checking against a Point with x, y coordinates
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point, Polygon
>>> line = LineString([(0, 0), (1, 1)])
>>> shapely.contains(line, Point(0, 0))
False
>>> shapely.contains(line, Point(0.5, 0.5))
True
>>> area = Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)])
>>> shapely.contains(area, Point(0, 0))
False
>>> shapely.contains(area, line)
True
>>> shapely.contains(area, LineString([(0, 0), (2, 2)]))
False
>>> polygon_with_hole = Polygon(
... [(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)],
... holes=[[(2, 2), (2, 4), (4, 4), (4, 2), (2, 2)]]
... )
>>> shapely.contains(polygon_with_hole, Point(1, 1))
True
>>> shapely.contains(polygon_with_hole, Point(2, 2))
False
>>> shapely.contains(polygon_with_hole, LineString([(1, 1), (5, 5)]))
False
>>> shapely.contains(area, area)
True
>>> shapely.contains(area, None)
False
shapely.contains_properly
Python Library Documentation: function contains_properly in module shapely.predicates
contains_properly(a, b, **kwargs)
Return True if geometry B is completely inside geometry A, with no common
boundary points.
A contains B properly if B intersects the interior of A but not the
boundary (or exterior). This means that a geometry A does not
"contain properly" itself, which contrasts with the ``contains`` function,
where common points on the boundary are allowed.
Note: this function will prepare the geometries under the hood if needed.
You can prepare the geometries in advance to avoid repeated preparation
when calling this function multiple times.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
contains : contains which allows common boundary points
prepare : improve performance by preparing ``a`` (the first argument)
Examples
--------
>>> import shapely
>>> from shapely import Polygon
>>> area1 = Polygon([(0, 0), (3, 0), (3, 3), (0, 3), (0, 0)])
>>> area2 = Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)])
>>> area3 = Polygon([(1, 1), (2, 1), (2, 2), (1, 2), (1, 1)])
``area1`` and ``area2`` have a common border:
>>> shapely.contains(area1, area2)
True
>>> shapely.contains_properly(area1, area2)
False
``area3`` is completely inside ``area1`` with no common border:
>>> shapely.contains(area1, area3)
True
>>> shapely.contains_properly(area1, area3)
True
shapely.contains_xy
Python Library Documentation: function contains_xy in module shapely.predicates
contains_xy(geom, x, y=None, **kwargs)
Return True if the Point (x, y) is completely inside geom.
This is a special-case (and faster) variant of the `contains` function
which avoids having to create a Point object if you start from x/y
coordinates.
Note that in the case of points, the `contains_properly` predicate is
equivalent to `contains`.
See the docstring of `contains` for more details about the predicate.
Parameters
----------
geom : Geometry or array_like
Geometry or geometries to check if they contain the point.
x, y : float or array_like
Coordinates as separate x and y arrays, or a single array of
coordinate x, y tuples.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
contains : variant taking two geometries as input
Notes
-----
If you compare a small number of polygons or lines with many points,
it can be beneficial to prepare the geometries in advance using
:func:`shapely.prepare`.
Examples
--------
>>> import shapely
>>> from shapely import Point, Polygon
>>> area = Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)])
>>> shapely.contains(area, Point(0.5, 0.5))
True
>>> shapely.contains_xy(area, 0.5, 0.5)
True
shapely.convex_hull
Python Library Documentation: function convex_hull in module shapely.constructive
convex_hull(geometry, **kwargs)
Compute the minimum convex geometry that encloses an input geometry.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the convex hull.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import MultiPoint, Polygon
>>> shapely.convex_hull(MultiPoint([(0, 0), (10, 0), (10, 10)]))
<POLYGON ((0 0, 10 10, 10 0, 0 0))>
>>> shapely.convex_hull(Polygon())
<GEOMETRYCOLLECTION EMPTY>
shapely.coordinates
Python Library Documentation: module shapely.coordinates in shapely
NAME
shapely.coordinates - Methods that operate on the coordinates of geometries.
FUNCTIONS
count_coordinates(geometry)
Count the number of coordinate pairs in a geometry array.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to count the coordinates of.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> shapely.count_coordinates(Point(0, 0))
1
>>> shapely.count_coordinates(LineString([(2, 2), (4, 2)]))
2
>>> shapely.count_coordinates(None)
0
>>> shapely.count_coordinates([Point(0, 0), None])
1
get_coordinates(geometry, include_z=False, return_index=False, *, include_m=False)
Get coordinates from a geometry array as an array of floats.
The shape of the returned array is (N, 2), with N being the number of
coordinate pairs. The shape of the data may also be (N, 3) or (N, 4),
depending on ``include_z`` and ``include_m`` options.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to get the coordinates of.
include_z, include_m : bool, default False
If both are False, return XY (2D) geometries.
If both are True, return XYZM (4D) geometries.
If either are True, return XYZ or XYM (3D) geometries.
If a geometry has no Z or M dimension, extra coordinate data will be NaN.
.. versionadded:: 2.1.0
The ``include_m`` parameter was added to support XYM (3D) and
XYZM (4D) geometries available with GEOS 3.12.0 or later.
With older GEOS versions, M dimension coordinates will be NaN.
return_index : bool, default False
If True, also return the index of each returned geometry as a separate
ndarray of integers. For multidimensional arrays, this indexes into the
flattened array (in C contiguous order).
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``include_z`` or ``return_index`` are
specified as positional arguments. In a future release, these will
need to be specified as keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> shapely.get_coordinates(Point(1, 2)).tolist()
[[1.0, 2.0]]
>>> shapely.get_coordinates(LineString([(2, 2), (4, 4)])).tolist()
[[2.0, 2.0], [4.0, 4.0]]
>>> shapely.get_coordinates(None)
array([], shape=(0, 2), dtype=float64)
By default the third dimension is ignored:
>>> shapely.get_coordinates(Point(1, 2, 3)).tolist()
[[1.0, 2.0]]
>>> shapely.get_coordinates(Point(1, 2, 3), include_z=True).tolist()
[[1.0, 2.0, 3.0]]
If geometries don't have Z or M dimension, these values will be NaN:
>>> pt = Point(1, 2)
>>> shapely.get_coordinates(pt, include_z=True).tolist()
[[1.0, 2.0, nan]]
>>> shapely.get_coordinates(pt, include_z=True, include_m=True).tolist()
[[1.0, 2.0, nan, nan]]
When ``return_index=True``, indexes are returned also:
>>> geometries = [LineString([(2, 2), (4, 4)]), Point(0, 0)]
>>> coordinates, index = shapely.get_coordinates(geometries, return_index=True)
>>> coordinates.tolist(), index.tolist()
([[2.0, 2.0], [4.0, 4.0], [0.0, 0.0]], [0, 0, 1])
set_coordinates(geometry, coordinates)
Adapts the coordinates of a geometry array in-place.
If the coordinates array has shape (N, 2), all returned geometries
will be two-dimensional, and the third dimension will be discarded,
if present. If the coordinates array has shape (N, 3), the returned
geometries preserve the dimensionality of the input geometries.
.. warning::
The geometry array is modified in-place! If you do not want to
modify the original array, you can do
``set_coordinates(arr.copy(), newcoords)``.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to set the coordinates of.
coordinates: array_like
An array of coordinates to set.
See Also
--------
transform : Returns a copy of a geometry array with a function applied to its
coordinates.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> shapely.set_coordinates(Point(0, 0), [[1, 1]])
<POINT (1 1)>
>>> shapely.set_coordinates(
... [Point(0, 0), LineString([(0, 0), (0, 0)])],
... [[1, 2], [3, 4], [5, 6]]
... ).tolist()
[<POINT (1 2)>, <LINESTRING (3 4, 5 6)>]
>>> shapely.set_coordinates([None, Point(0, 0)], [[1, 2]]).tolist()
[None, <POINT (1 2)>]
Third dimension of input geometry is discarded if coordinates array does
not include one:
>>> shapely.set_coordinates(Point(0, 0, 0), [[1, 1]])
<POINT (1 1)>
>>> shapely.set_coordinates(Point(0, 0, 0), [[1, 1, 1]])
<POINT Z (1 1 1)>
transform(geometry, transformation, include_z: bool | None = False, *, interleaved: bool = True)
Apply a function to the coordinates of a geometry.
With the default of ``include_z=False``, all returned geometries will be
two-dimensional; the third dimension will be discarded, if present.
When specifying ``include_z=True``, the returned geometries preserve
the dimensionality of the respective input geometries.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to transform.
transformation : function
A function that transforms a (N, 2) or (N, 3) ndarray of float64 to
another (N, 2) or (N, 3) ndarray of float64.
The function may not change N.
include_z : bool, optional, default False
If False, always return 2D geometries.
If True, the data being passed to the
transformation function will include the third dimension
(if a geometry has no third dimension, the z-coordinates
will be NaN). If None, will infer the dimensionality per
input geometry using ``has_z``, which may result in 2 calls to
the transformation function. Note that this inference
can be unreliable with empty geometries or NaN coordinates: for a
guaranteed result, it is recommended to specify ``include_z`` explicitly.
interleaved : bool, default True
If set to False, the transformation function should accept 2 or 3 separate
one-dimensional arrays (x, y and optional z) instead of a single
two-dimensional array.
.. versionadded:: 2.1.0
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``include_z`` is specified as a
positional argument. This will need to be specified as a keyword
argument in a future release.
See Also
--------
has_z
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> shapely.transform(Point(0, 0), lambda x: x + 1)
<POINT (1 1)>
>>> shapely.transform(LineString([(2, 2), (4, 4)]), lambda x: x * [2, 3])
<LINESTRING (4 6, 8 12)>
>>> shapely.transform(None, lambda x: x) is None
True
>>> shapely.transform([Point(0, 0), None], lambda x: x).tolist()
[<POINT (0 0)>, None]
The presence of a third dimension can be automatically detected, or
controlled explicitly:
>>> shapely.transform(Point(0, 0, 0), lambda x: x + 1)
<POINT (1 1)>
>>> shapely.transform(Point(0, 0, 0), lambda x: x + 1, include_z=True)
<POINT Z (1 1 1)>
>>> shapely.transform(Point(0, 0, 0), lambda x: x + 1, include_z=None)
<POINT Z (1 1 1)>
With interleaved=False, the call signature of the transformation is different:
>>> shapely.transform(LineString([(1, 2), (3, 4)]), lambda x, y: (x + 1, y), interleaved=False)
<LINESTRING (2 2, 4 4)>
Or with a z coordinate:
>>> shapely.transform(Point(0, 0, 0), lambda x, y, z: (x + 1, y, z + 2), interleaved=False, include_z=True)
<POINT Z (1 0 2)>
Using pyproj >= 2.1, the following example will reproject Shapely geometries
from EPSG 4326 to EPSG 32618:
>>> from pyproj import Transformer
>>> transformer = Transformer.from_crs(4326, 32618, always_xy=True)
>>> shapely.transform(Point(-75, 50), transformer.transform, interleaved=False)
<POINT (500000 5538630.703)>
DATA
__all__ = ['count_coordinates', 'get_coordinates', 'set_coordinates', ...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\shapely\coordinates.py
shapely.coords
Python Library Documentation: module shapely.coords in shapely
NAME
shapely.coords - Coordinate sequence utilities.
CLASSES
builtins.object
CoordinateSequence
class CoordinateSequence(builtins.object)
| CoordinateSequence(coords)
|
| Access to coordinate tuples from the parent geometry's coordinate sequence.
|
| Examples
| --------
| >>> from shapely.wkt import loads
| >>> g = loads('POINT (0.0 0.0)')
| >>> list(g.coords)
| [(0.0, 0.0)]
| >>> g = loads('POINT M (1 2 4)')
| >>> g.coords[:]
| [(1.0, 2.0, 4.0)]
|
| Methods defined here:
|
| __array__(self, dtype=None, copy=None)
| Return a copy of the coordinate array.
|
| Parameters
| ----------
| dtype : data-type, optional
| The desired data-type for the array.
| copy : bool, optional
| If None (default) or True, a copy of the array is always returned.
| If False, a ValueError is raised as this is not supported.
|
| Returns
| -------
| array
| The coordinate array.
|
| Raises
| ------
| ValueError
| If `copy=False` is specified.
|
| __getitem__(self, key)
| Get the item at the specified index or slice.
|
| Parameters
| ----------
| key : int or slice
| The index or slice.
|
| Returns
| -------
| tuple or list
| The item at the specified index or slice.
|
| __init__(self, coords)
| Initialize the CoordinateSequence.
|
| Parameters
| ----------
| coords : array
| The coordinate array.
|
| __iter__(self)
| Iterate over the CoordinateSequence.
|
| __len__(self)
| Return the length of the CoordinateSequence.
|
| Returns
| -------
| int
| The length of the CoordinateSequence.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| xy
| X and Y arrays.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\shapely\coords.py
shapely.count_coordinates
Python Library Documentation: function count_coordinates in module shapely.coordinates
count_coordinates(geometry)
Count the number of coordinate pairs in a geometry array.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to count the coordinates of.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> shapely.count_coordinates(Point(0, 0))
1
>>> shapely.count_coordinates(LineString([(2, 2), (4, 2)]))
2
>>> shapely.count_coordinates(None)
0
>>> shapely.count_coordinates([Point(0, 0), None])
1
shapely.coverage_invalid_edges
Python Library Documentation: function coverage_invalid_edges in module shapely._coverage
coverage_invalid_edges(geometry, gap_width=0.0, **kwargs)
Verify if a coverage is valid and return invalid edges.
This functions returns linear indicators showing the location of invalid
edges (if any) in each polygon in the input array.
The coverage is represented by an array of polygonal geometries with
exactly matching edges and no overlap.
A valid coverage may contain holes (regions of no coverage). However,
sometimes it might be desirable to detect narrow gaps as invalidities in
the coverage. The `gap_width` parameter allows to specify the maximum
width of gaps to detect. When gaps are detected, the `coverage_is_valid`
function will return False and this function can be used to find the
edges of those gaps.
Geometries that are not Polygon or MultiPolygon are ignored.
.. versionadded:: 2.1.0
Parameters
----------
geometry : array_like
Array of geometries to verify.
gap_width : float, default 0.0
The maximum width of gaps to detect.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Returns
-------
numpy.ndarray | shapely.Geometry
See Also
--------
coverage_is_valid, coverage_simplify
shapely.coverage_is_valid
Python Library Documentation: function coverage_is_valid in module shapely._coverage
coverage_is_valid(geometry, gap_width=0.0, **kwargs)
Verify if a coverage is valid.
The coverage is represented by an array of polygonal geometries with
exactly matching edges and no overlap.
A valid coverage may contain holes (regions of no coverage). However,
sometimes it might be desirable to detect narrow gaps as invalidities in
the coverage. The `gap_width` parameter allows to specify the maximum
width of gaps to detect. When gaps are detected, this function will
return False and the `coverage_invalid_edges` function can be used to
find the edges of those gaps.
Geometries that are not Polygon or MultiPolygon are ignored.
.. versionadded:: 2.1.0
Parameters
----------
geometry : array_like
Array of geometries to verify.
gap_width : float, default 0.0
The maximum width of gaps to detect.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Returns
-------
bool
See Also
--------
coverage_invalid_edges, coverage_simplify
shapely.coverage_simplify
Python Library Documentation: function coverage_simplify in module shapely._coverage
coverage_simplify(geometry, tolerance, *, simplify_boundary=True)
Return a simplified version of an input geometry using coverage simplification.
Assumes that the geometry forms a polygonal coverage. Under this assumption, the
function simplifies the edges using the Visvalingam-Whyatt algorithm, while
preserving a valid coverage. In the most simplified case, polygons are reduced to
triangles.
A collection of valid polygons is considered a coverage if the polygons are:
* **Non-overlapping** - polygons do not overlap (their interiors do not intersect)
* **Edge-Matched** - vertices along shared edges are identical
The function allows simplification of all edges including the outer boundaries of
the coverage or simplification of only the inner (shared) edges.
If there are other geometry types than Polygons or MultiPolygons present,
the function will raise an error.
If the geometry is polygonal but does not form a valid coverage due to overlaps,
it will be simplified but it may result in invalid topology.
.. versionadded:: 2.1.0
Parameters
----------
geometry : Geometry or array_like
tolerance : float or array_like
The degree of simplification roughly equal to the square root of the area
of triangles that will be removed.
simplify_boundary : bool, optional
By default (True), simplifies both internal edges of the coverage as well
as its boundary. If set to False, only simplifies internal edges.
Returns
-------
numpy.ndarray | shapely.Geometry
See Also
--------
coverage_is_valid, coverage_invalid_edges
Examples
--------
>>> import shapely
>>> from shapely import Polygon
>>> poly = Polygon([(0, 0), (20, 0), (20, 10), (10, 5), (0, 10), (0, 0)])
>>> shapely.coverage_simplify(poly, tolerance=2)
<POLYGON ((0 0, 20 0, 20 10, 10 5, 0 10, 0 0))>
shapely.coverage_union
Python Library Documentation: function coverage_union in module shapely.set_operations
coverage_union(a, b, **kwargs)
Merge multiple polygons into one.
This is an optimized version of union which assumes the polygons to be
non-overlapping.
If this assumption is not met, the exact result is not guaranteed
(depending on the GEOS version, it may return the input unchanged or raise
an error).
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to merge (union).
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
coverage_union_all
Examples
--------
>>> import shapely
>>> from shapely import Polygon
>>> polygon_1 = Polygon([(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)])
>>> polygon_2 = Polygon([(1, 0), (1, 1), (2, 1), (2, 0), (1, 0)])
>>> shapely.coverage_union(polygon_1, polygon_2).normalize()
<POLYGON ((0 0, 0 1, 1 1, 2 1, 2 0, 1 0, 0 0))>
Union with None returns same polygon
>>> shapely.coverage_union(polygon_1, None).normalize()
<POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
shapely.coverage_union_all
Python Library Documentation: function coverage_union_all in module shapely.set_operations
coverage_union_all(geometries, axis=None, **kwargs)
Return the union of multiple polygons of a geometry collection.
This is an optimized version of union which assumes the polygons
to be non-overlapping.
This function ignores None values when other Geometry elements are present.
If all elements of the given axis are None, an empty GeometryCollection is
returned (before GEOS 3.12 this was an empty MultiPolygon).
Parameters
----------
geometries : array_like
Geometries to merge/union.
axis : int, optional
Axis along which the operation is performed. The default (None)
performs the operation over all axes, returning a scalar value.
Axis may be negative, in which case it counts from the last to the
first axis.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``axis`` is specified as a
positional argument. This will need to be specified as a keyword
argument in a future release.
See Also
--------
coverage_union
Examples
--------
>>> import shapely
>>> from shapely import Polygon
>>> polygon_1 = Polygon([(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)])
>>> polygon_2 = Polygon([(1, 0), (1, 1), (2, 1), (2, 0), (1, 0)])
>>> shapely.coverage_union_all([polygon_1, polygon_2]).normalize()
<POLYGON ((0 0, 0 1, 1 1, 2 1, 2 0, 1 0, 0 0))>
>>> shapely.coverage_union_all([polygon_1, None]).normalize()
<POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
>>> shapely.coverage_union_all([None, None]).normalize()
<GEOMETRYCOLLECTION EMPTY>
shapely.covered_by
Python Library Documentation: function covered_by in module shapely.predicates
covered_by(a, b, **kwargs)
Return True if no point in geometry A is outside geometry B.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
covers : ``covered_by(A, B) == covers(B, A)``
prepare : improve performance by preparing ``a`` (the first argument)
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point, Polygon
>>> line = LineString([(0, 0), (1, 1)])
>>> shapely.covered_by(Point(0, 0), line)
True
>>> shapely.covered_by(Point(0.5, 0.5), line)
True
>>> area = Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)])
>>> shapely.covered_by(Point(0, 0), area)
True
>>> shapely.covered_by(line, area)
True
>>> shapely.covered_by(LineString([(0, 0), (2, 2)]), area)
False
>>> polygon_with_hole = Polygon(
... [(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)],
... holes=[[(2, 2), (2, 4), (4, 4), (4, 2), (2, 2)]]
... )
>>> shapely.covered_by(Point(1, 1), polygon_with_hole)
True
>>> shapely.covered_by(Point(2, 2), polygon_with_hole)
True
>>> shapely.covered_by(LineString([(1, 1), (5, 5)]), polygon_with_hole)
False
>>> shapely.covered_by(area, area)
True
>>> shapely.covered_by(None, area)
False
shapely.covers
Python Library Documentation: function covers in module shapely.predicates
covers(a, b, **kwargs)
Return True if no point in geometry B is outside geometry A.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
covered_by : ``covers(A, B) == covered_by(B, A)``
prepare : improve performance by preparing ``a`` (the first argument)
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point, Polygon
>>> line = LineString([(0, 0), (1, 1)])
>>> shapely.covers(line, Point(0, 0))
True
>>> shapely.covers(line, Point(0.5, 0.5))
True
>>> area = Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)])
>>> shapely.covers(area, Point(0, 0))
True
>>> shapely.covers(area, line)
True
>>> shapely.covers(area, LineString([(0, 0), (2, 2)]))
False
>>> polygon_with_hole = Polygon(
... [(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)],
... holes=[[(2, 2), (2, 4), (4, 4), (4, 2), (2, 2)]]
... )
>>> shapely.covers(polygon_with_hole, Point(1, 1))
True
>>> shapely.covers(polygon_with_hole, Point(2, 2))
True
>>> shapely.covers(polygon_with_hole, LineString([(1, 1), (5, 5)]))
False
>>> shapely.covers(area, area)
True
>>> shapely.covers(area, None)
False
shapely.creation
Python Library Documentation: module shapely.creation in shapely
NAME
shapely.creation - Methods to create geometries.
FUNCTIONS
box(xmin, ymin, xmax, ymax, ccw=True, **kwargs)
Create box polygons.
Parameters
----------
xmin : float or array_like
Float or array of minimum x coordinates.
ymin : float or array_like
Float or array of minimum y coordinates.
xmax : float or array_like
Float or array of maximum x coordinates.
ymax : float or array_like
Float or array of maximum y coordinates.
ccw : bool, default True
If True, box will be created in counterclockwise direction starting
from bottom right coordinate (xmax, ymin).
If False, box will be created in clockwise direction starting from
bottom left coordinate (xmin, ymin).
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``ccw`` is specified as a
positional argument. This will need to be specified as a keyword
argument in a future release.
Examples
--------
>>> import shapely
>>> shapely.box(0, 0, 1, 1)
<POLYGON ((1 0, 1 1, 0 1, 0 0, 1 0))>
>>> shapely.box(0, 0, 1, 1, ccw=False)
<POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
destroy_prepared(geometry, **kwargs)
Destroy the prepared part of a geometry, freeing up memory.
Note that the prepared geometry will always be cleaned up if the geometry itself
is dereferenced. This function needs only be called in very specific circumstances,
such as freeing up memory without losing the geometries, or benchmarking.
Parameters
----------
geometry : Geometry or array_like
Geometries are changed in-place
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
prepare
empty(shape, geom_type=None, order='C')
Create a geometry array prefilled with None or with empty geometries.
Parameters
----------
shape : int or tuple of int
Shape of the empty array, e.g., ``(2, 3)`` or ``2``.
geom_type : shapely.GeometryType, optional
The desired geometry type in case the array should be prefilled
with empty geometries. Default ``None``.
order : {'C', 'F'}, optional, default: 'C'
Whether to store multi-dimensional data in row-major
(C-style) or column-major (Fortran-style) order in
memory.
Examples
--------
>>> import shapely
>>> shapely.empty((2, 3)).tolist()
[[None, None, None], [None, None, None]]
>>> shapely.empty(2, geom_type=shapely.GeometryType.POINT).tolist()
[<POINT EMPTY>, <POINT EMPTY>]
geometrycollections(geometries, indices=None, out=None, **kwargs)
Create geometrycollections from arrays of geometries.
Parameters
----------
geometries : array_like
An array of geometries.
indices : array_like, optional
Indices into the target array where input geometries belong. If
provided, both geometries and indices should be 1D and have matching
sizes. Indices should be in increasing order. Missing indices result
in a ValueError unless ``out`` is provided, in which case the original
value in ``out`` is kept.
out : ndarray, optional
An array (with dtype object) to output the geometries into.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Ignored if ``indices`` is provided.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``indices`` is specified as a
positional argument. This will need to be specified as a keyword
argument in a future release.
See Also
--------
multipoints
linearrings(coords, y=None, z=None, indices=None, *, handle_nan=<HandleNaN.allow: 0>, out=None, **kwargs)
Create an array of linearrings.
If the provided coords do not constitute a closed linestring, or if there
are only 3 provided coords, the first
coordinate is duplicated at the end to close the ring. This function will
raise an exception if a linearring contains less than three points or if
the terminal coordinates contain NaN (not-a-number).
Parameters
----------
coords : array_like
An array of lists of coordinate tuples (2- or 3-dimensional) or, if ``y``
is provided, an array of lists of x coordinates
y : array_like, optional
An array of y coordinates.
z : array_like, optional
An array of z coordinates.
indices : array_like, optional
Indices into the target array where input coordinates belong. If
provided, the coords should be 2D with shape (N, 2) or (N, 3) and
indices should be an array of shape (N,) with integers in increasing
order. Missing indices result in a ValueError unless ``out`` is
provided, in which case the original value in ``out`` is kept.
handle_nan : shapely.HandleNaN or {'allow', 'skip', 'error'}, default 'allow'
Specifies what to do when a NaN or Inf is encountered in the coordinates:
- 'allow': the geometries are created with NaN or Inf coordinates.
Note that this can result in unexpected behaviour in subsequent
operations, and generally it is discouraged to have non-finite
coordinate values. One can use this option if you know all
coordinates are finite and want to avoid the overhead of checking
for this.
- 'skip': the coordinate pairs where any of x, y or z values are
NaN or Inf are ignored. If this results in ignoring all coordinates
for one geometry, an empty geometry is created.
- 'error': if any NaN or Inf is detected in the coordinates, a ValueError
is raised. This option ensures that the created geometries have all
finite coordinate values.
.. versionadded:: 2.1.0
out : ndarray, optional
An array (with dtype object) to output the geometries into.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Ignored if ``indices`` is provided.
See Also
--------
linestrings
Examples
--------
>>> import shapely
>>> shapely.linearrings([[0, 0], [0, 1], [1, 1], [0, 0]])
<LINEARRING (0 0, 0 1, 1 1, 0 0)>
>>> shapely.linearrings([[0, 0], [0, 1], [1, 1]])
<LINEARRING (0 0, 0 1, 1 1, 0 0)>
Notes
-----
- Usage of the ``y`` and ``z`` arguments will prevents lazy evaluation in
``dask``. Instead provide the coordinates as a ``(..., 2)`` or
``(..., 3)`` array using only ``coords``.
linestrings(coords, y=None, z=None, indices=None, *, handle_nan=<HandleNaN.allow: 0>, out=None, **kwargs)
Create an array of linestrings.
This function will raise an exception if a linestring contains less than
two points.
Parameters
----------
coords : array_like
An array of lists of coordinate tuples (2- or 3-dimensional) or, if ``y``
is provided, an array of lists of x coordinates.
y : array_like, optional
An array of y coordinates.
z : array_like, optional
An array of z coordinates.
indices : array_like, optional
Indices into the target array where input coordinates belong. If
provided, the coords should be 2D with shape (N, 2) or (N, 3) and
indices should be an array of shape (N,) with integers in increasing
order. Missing indices result in a ValueError unless ``out`` is
provided, in which case the original value in ``out`` is kept.
handle_nan : shapely.HandleNaN or {'allow', 'skip', 'error'}, default 'allow'
Specifies what to do when a NaN or Inf is encountered in the coordinates:
- 'allow': the geometries are created with NaN or Inf coordinates.
Note that this can result in unexpected behaviour in subsequent
operations, and generally it is discouraged to have non-finite
coordinate values. One can use this option if you know all
coordinates are finite and want to avoid the overhead of checking
for this.
- 'skip': the coordinate pairs where any of x, y or z values are
NaN or Inf are ignored. If this results in ignoring all coordinates
for one geometry, an empty geometry is created.
- 'error': if any NaN or Inf is detected in the coordinates, a ValueError
is raised. This option ensures that the created geometries have all
finite coordinate values.
.. versionadded:: 2.1.0
out : ndarray, optional
An array (with dtype object) to output the geometries into.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Ignored if ``indices`` is provided.
Examples
--------
>>> import shapely
>>> shapely.linestrings([[[0, 1], [4, 5]], [[2, 3], [5, 6]]]).tolist()
[<LINESTRING (0 1, 4 5)>, <LINESTRING (2 3, 5 6)>]
>>> shapely.linestrings(
... [[0, 1], [4, 5], [2, 3], [5, 6], [7, 8]],
... indices=[0, 0, 1, 1, 1]
... ).tolist()
[<LINESTRING (0 1, 4 5)>, <LINESTRING (2 3, 5 6, 7 8)>]
Notes
-----
- Usage of the ``y`` and ``z`` arguments will prevents lazy evaluation in
``dask``. Instead provide the coordinates as a ``(..., 2)`` or
``(..., 3)`` array using only ``coords``.
multilinestrings(geometries, indices=None, *, out=None, **kwargs)
Create multilinestrings from arrays of linestrings.
Parameters
----------
geometries : array_like
An array of linestrings or coordinates (see linestrings).
indices : array_like, optional
Indices into the target array where input geometries belong. If
provided, both geometries and indices should be 1D and have matching
sizes. Indices should be in increasing order. Missing indices result
in a ValueError unless ``out`` is provided, in which case the original
value in ``out`` is kept.
out : ndarray, optional
An array (with dtype object) to output the geometries into.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Ignored if ``indices`` is provided.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``indices`` is specified as a
positional argument. This will need to be specified as a keyword
argument in a future release.
See Also
--------
multipoints
multipoints(geometries, indices=None, *, out=None, **kwargs)
Create multipoints from arrays of points.
Parameters
----------
geometries : array_like
An array of points or coordinates (see points).
indices : array_like, optional
Indices into the target array where input geometries belong. If
provided, both geometries and indices should be 1D and have matching
sizes. Indices should be in increasing order. Missing indices result
in a ValueError unless ``out`` is provided, in which case the original
value in ``out`` is kept.
out : ndarray, optional
An array (with dtype object) to output the geometries into.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Ignored if ``indices`` is provided.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``indices`` is specified as a
positional argument. This will need to be specified as a keyword
argument in a future release.
Examples
--------
>>> import shapely
Multipoints are constructed from points:
>>> point_1 = shapely.points([1, 1])
>>> point_2 = shapely.points([2, 2])
>>> shapely.multipoints([point_1, point_2])
<MULTIPOINT ((1 1), (2 2))>
>>> shapely.multipoints([[point_1, point_2], [point_2, None]]).tolist()
[<MULTIPOINT ((1 1), (2 2))>, <MULTIPOINT ((2 2))>]
Or from coordinates directly:
>>> shapely.multipoints([[0, 0], [2, 2], [3, 3]])
<MULTIPOINT ((0 0), (2 2), (3 3))>
Multiple multipoints of different sizes can be constructed efficiently using the
``indices`` keyword argument:
>>> shapely.multipoints([point_1, point_2, point_2], indices=[0, 0, 1]).tolist()
[<MULTIPOINT ((1 1), (2 2))>, <MULTIPOINT ((2 2))>]
Missing input values (``None``) are skipped and may result in an
empty multipoint:
>>> shapely.multipoints([None])
<MULTIPOINT EMPTY>
>>> shapely.multipoints([point_1, None], indices=[0, 0]).tolist()
[<MULTIPOINT ((1 1))>]
>>> shapely.multipoints([point_1, None], indices=[0, 1]).tolist()
[<MULTIPOINT ((1 1))>, <MULTIPOINT EMPTY>]
multipolygons(geometries, indices=None, *, out=None, **kwargs)
Create multipolygons from arrays of polygons.
Parameters
----------
geometries : array_like
An array of polygons or coordinates (see polygons).
indices : array_like, optional
Indices into the target array where input geometries belong. If
provided, both geometries and indices should be 1D and have matching
sizes. Indices should be in increasing order. Missing indices result
in a ValueError unless ``out`` is provided, in which case the original
value in ``out`` is kept.
out : ndarray, optional
An array (with dtype object) to output the geometries into.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Ignored if ``indices`` is provided.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``indices`` is specified as a
positional argument. This will need to be specified as a keyword
argument in a future release.
See Also
--------
multipoints
points(coords, y=None, z=None, indices=None, *, handle_nan=<HandleNaN.allow: 0>, out=None, **kwargs)
Create an array of points.
Parameters
----------
coords : array_like
An array of coordinate tuples (2- or 3-dimensional) or, if ``y`` is
provided, an array of x coordinates.
y : array_like, optional
An array of y coordinates.
z : array_like, optional
An array of z coordinates.
indices : array_like, optional
Indices into the target array where input coordinates belong. If
provided, the coords should be 2D with shape (N, 2) or (N, 3) and
indices should be an array of shape (N,) with integers in increasing
order. Missing indices result in a ValueError unless ``out`` is
provided, in which case the original value in ``out`` is kept.
handle_nan : shapely.HandleNaN or {'allow', 'skip', 'error'}, default 'allow'
Specifies what to do when a NaN or Inf is encountered in the coordinates:
- 'allow': the geometries are created with NaN or Inf coordinates.
Note that this can result in unexpected behaviour in subsequent
operations, and generally it is discouraged to have non-finite
coordinate values. One can use this option if you know all
coordinates are finite and want to avoid the overhead of checking
for this.
- 'skip': if any of x, y or z values are NaN or Inf, an empty point
will be created.
- 'error': if any NaN or Inf is detected in the coordinates, a ValueError
is raised. This option ensures that the created geometries have all
finite coordinate values.
.. versionadded:: 2.1.0
out : ndarray, optional
An array (with dtype object) to output the geometries into.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Ignored if ``indices`` is provided.
Examples
--------
>>> import shapely
>>> shapely.points([[0, 1], [4, 5]]).tolist()
[<POINT (0 1)>, <POINT (4 5)>]
>>> shapely.points([0, 1, 2])
<POINT Z (0 1 2)>
Notes
-----
- GEOS 3.10, 3.11 and 3.12 automatically converts POINT (nan nan) to POINT EMPTY.
- GEOS 3.10 and 3.11 will transform a 3D point to 2D if its Z coordinate is NaN.
- Usage of the ``y`` and ``z`` arguments will prevents lazy evaluation in
``dask``. Instead provide the coordinates as an array with shape
``(..., 2)`` or ``(..., 3)`` using only the ``coords`` argument.
polygons(geometries, holes=None, indices=None, *, out=None, **kwargs)
Create an array of polygons.
Parameters
----------
geometries : array_like
An array of linearrings or coordinates (see linearrings).
Unless ``indices`` are given (see description below), this
include the outer shells only. The ``holes`` argument should be used
to create polygons with holes.
holes : array_like, optional
An array of lists of linearrings that constitute holes for each shell.
Not to be used in combination with ``indices``.
indices : array_like, optional
Indices into the target array where input geometries belong. If
provided, the holes are expected to be present inside ``geometries``;
the first geometry for each index is the outer shell
and all subsequent geometries in that index are the holes.
Both geometries and indices should be 1D and have matching sizes.
Indices should be in increasing order. Missing indices result in a
ValueError unless ``out`` is provided, in which case the original value
in ``out`` is kept.
out : ndarray, optional
An array (with dtype object) to output the geometries into.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Ignored if ``indices`` is provided.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``indices`` is specified as a
positional argument. This will need to be specified as a keyword
argument in a future release.
Examples
--------
>>> import shapely
Polygons are constructed from rings:
>>> ring_1 = shapely.linearrings([[0, 0], [0, 10], [10, 10], [10, 0]])
>>> ring_2 = shapely.linearrings([[2, 6], [2, 7], [3, 7], [3, 6]])
>>> shapely.polygons([ring_1, ring_2])[0]
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))>
>>> shapely.polygons([ring_1, ring_2])[1]
<POLYGON ((2 6, 2 7, 3 7, 3 6, 2 6))>
Or from coordinates directly:
>>> shapely.polygons([[0, 0], [0, 10], [10, 10], [10, 0]])
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))>
Adding holes can be done using the ``holes`` keyword argument:
>>> shapely.polygons(ring_1, holes=[ring_2])
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0), (2 6, 2 7, 3 7, 3 6, 2 6))>
Or using the ``indices`` argument:
>>> shapely.polygons([ring_1, ring_2], indices=[0, 1])[0]
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))>
>>> shapely.polygons([ring_1, ring_2], indices=[0, 1])[1]
<POLYGON ((2 6, 2 7, 3 7, 3 6, 2 6))>
>>> shapely.polygons([ring_1, ring_2], indices=[0, 0])[0]
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0), (2 6, 2 7, 3 7, 3 6, 2 6))>
Missing input values (``None``) are skipped and may result in an
empty polygon:
>>> shapely.polygons(None)
<POLYGON EMPTY>
>>> shapely.polygons(ring_1, holes=[None])
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))>
>>> shapely.polygons([ring_1, None], indices=[0, 0])[0]
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))>
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, ``prepare`` should 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 does not return any values; geometries are modified in place.
Parameters
----------
geometry : Geometry or array_like
Geometries are changed in place
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
is_prepared : Identify whether a geometry is prepared already.
destroy_prepared : Destroy 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)
>>> shapely.contains_properly(poly, [Point(0.0, 0.0), Point(0.5, 0.5)]).tolist()
[False, True]
DATA
__all__ = ['box', 'destroy_prepared', 'empty', 'geometrycollections', ...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\shapely\creation.py
shapely.crosses
Python Library Documentation: function crosses in module shapely.predicates
crosses(a, b, **kwargs)
Return True if A and B spatially cross.
A crosses B if they have some but not all interior points in common,
the intersection is one dimension less than the maximum dimension of A or B,
and the intersection is not equal to either A or B.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
prepare : improve performance by preparing ``a`` (the first argument)
Examples
--------
>>> import shapely
>>> from shapely import LineString, MultiPoint, Point, Polygon
>>> line = LineString([(0, 0), (1, 1)])
>>> # A contains B:
>>> shapely.crosses(line, Point(0.5, 0.5))
False
>>> # A and B intersect at a point but do not share all points:
>>> shapely.crosses(line, MultiPoint([(0, 1), (0.5, 0.5)]))
True
>>> shapely.crosses(line, LineString([(0, 1), (1, 0)]))
True
>>> # A is contained by B; their intersection is a line (same dimension):
>>> shapely.crosses(line, LineString([(0, 0), (2, 2)]))
False
>>> area = Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)])
>>> # A contains B:
>>> shapely.crosses(area, line)
False
>>> # A and B intersect with a line (lower dimension) but do not share all points:
>>> shapely.crosses(area, LineString([(0, 0), (2, 2)]))
True
>>> # A contains B:
>>> shapely.crosses(area, Point(0.5, 0.5))
False
>>> # A contains some but not all points of B; they intersect at a point:
>>> shapely.crosses(area, MultiPoint([(2, 2), (0.5, 0.5)]))
True
shapely.decorators
Python Library Documentation: module shapely.decorators in shapely
NAME
shapely.decorators - Decorators for Shapely functions.
CLASSES
builtins.object
requires_geos
class requires_geos(builtins.object)
| requires_geos(version)
|
| Decorator to require a minimum GEOS version.
|
| Methods defined here:
|
| __call__(self, func)
| Return the wrapped function.
|
| __init__(self, version)
| Create a decorator that requires a minimum GEOS version.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
FUNCTIONS
deprecate_positional(should_be_kwargs: collections.abc.Iterable[str], category: type[Warning] = <class 'DeprecationWarning'>)
Show warning if positional arguments are used that should be keyword.
Parameters
----------
should_be_kwargs : Iterable[str]
Names of parameters that should be passed as keyword arguments.
category : type[Warning], optional (default: DeprecationWarning)
Warning category to use for deprecation warnings.
Returns
-------
callable
Decorator function that adds positional argument deprecation warnings.
Examples
--------
>>> from shapely.decorators import deprecate_positional
>>> @deprecate_positional(['b', 'c'])
... def example(a, b, c=None):
... return a, b, c
...
>>> example(1, 2) # doctest: +SKIP
DeprecationWarning: positional argument `b` for `example` is deprecated. ...
(1, 2, None)
>>> example(1, b=2) # No warnings
(1, 2, None)
multithreading_enabled(func)
Enable multithreading.
To do this, the writable flags of object type ndarrays are set to False.
NB: multithreading also requires the GIL to be released, which is done in
the C extension (ufuncs.c).
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\shapely\decorators.py
shapely.delaunay_triangles
Python Library Documentation: function delaunay_triangles in module shapely.constructive
delaunay_triangles(geometry, tolerance=0.0, only_edges=False, **kwargs)
Compute a Delaunay triangulation around the vertices of an input geometry.
The output is a geometrycollection containing polygons (default)
or linestrings (see ``only_edges``). Returns an empty geometry for input
geometries that contain less than 3 vertices.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the Delaunay triangulation.
tolerance : float or array_like, default 0.0
Snap input vertices together if their distance is less than this value.
only_edges : bool or array_like, default False
If set to True, the triangulation will return a collection of
linestrings instead of polygons.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Returns
-------
GeometryCollection or array of GeometryCollections
See Also
--------
constrained_delaunay_triangles
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, LineString, MultiPoint, Polygon
>>> points = MultiPoint([(50, 30), (60, 30), (100, 100)])
>>> shapely.delaunay_triangles(points).normalize()
<GEOMETRYCOLLECTION (POLYGON ((50 30, 100 100, 60 30, 50 30)))>
>>> shapely.delaunay_triangles(points, only_edges=True)
<MULTILINESTRING ((50 30, 100 100), (50 30, 60 30), ...>
>>> shapely.delaunay_triangles(
... MultiPoint([(50, 30), (51, 30), (60, 30), (100, 100)]),
... tolerance=2
... ).normalize()
<GEOMETRYCOLLECTION (POLYGON ((50 30, 100 100, 60 30, 50 30)))>
>>> shapely.delaunay_triangles(Polygon([(50, 30), (60, 30), (100, 100), (50, 30)])).normalize()
<GEOMETRYCOLLECTION (POLYGON ((50 30, 100 100, 60 30, 50 30)))>
>>> shapely.delaunay_triangles(LineString([(50, 30), (60, 30), (100, 100)])).normalize()
<GEOMETRYCOLLECTION (POLYGON ((50 30, 100 100, 60 30, 50 30)))>
>>> shapely.delaunay_triangles(GeometryCollection([]))
<GEOMETRYCOLLECTION EMPTY>
shapely.destroy_prepared
Python Library Documentation: function destroy_prepared in module shapely.creation
destroy_prepared(geometry, **kwargs)
Destroy the prepared part of a geometry, freeing up memory.
Note that the prepared geometry will always be cleaned up if the geometry itself
is dereferenced. This function needs only be called in very specific circumstances,
such as freeing up memory without losing the geometries, or benchmarking.
Parameters
----------
geometry : Geometry or array_like
Geometries are changed in-place
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
prepare
shapely.difference
Python Library Documentation: function difference in module shapely.set_operations
difference(a, b, grid_size=None, **kwargs)
Return the part of geometry A that does not intersect with geometry B.
If grid_size is nonzero, input coordinates will be snapped to a precision
grid of that size and resulting coordinates will be snapped to that same
grid. If 0, this operation will use double precision coordinates. If None,
the highest precision of the inputs will be used, which may be previously
set using set_precision. Note: returned geometry does not have precision
set unless specified previously by set_precision.
Parameters
----------
a : Geometry or array_like
Geometry or geometries to subtract b from.
b : Geometry or array_like
Geometry or geometries to subtract from a.
grid_size : float, optional
Precision grid size; will use the highest precision of the inputs by default.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``grid_size`` is specified as a
positional argument. This will need to be specified as a keyword
argument in a future release.
See Also
--------
set_precision
Examples
--------
>>> import shapely
>>> from shapely import LineString
>>> line = LineString([(0, 0), (2, 2)])
>>> shapely.difference(line, LineString([(1, 1), (3, 3)]))
<LINESTRING (0 0, 1 1)>
>>> shapely.difference(line, LineString())
<LINESTRING (0 0, 2 2)>
>>> shapely.difference(line, None) is None
True
>>> box1 = shapely.box(0, 0, 2, 2)
>>> box2 = shapely.box(1, 1, 3, 3)
>>> shapely.difference(box1, box2).normalize()
<POLYGON ((0 0, 0 2, 1 2, 1 1, 2 1, 2 0, 0 0))>
>>> box1 = shapely.box(0.1, 0.2, 2.1, 2.1)
>>> shapely.difference(box1, box2, grid_size=1)
<POLYGON ((2 0, 0 0, 0 2, 1 2, 1 1, 2 1, 2 0))>
shapely.disjoint
Python Library Documentation: function disjoint in module shapely.predicates
disjoint(a, b, **kwargs)
Return True if A and B do not share any point in space.
Disjoint implies that overlaps, touches, within, and intersects are False.
Note missing (None) values are never disjoint.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
intersects : ``disjoint(A, B) == ~intersects(A, B)``
prepare : improve performance by preparing ``a`` (the first argument)
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, LineString, Point
>>> line = LineString([(0, 0), (1, 1)])
>>> shapely.disjoint(line, Point(0, 0))
False
>>> shapely.disjoint(line, Point(0, 1))
True
>>> shapely.disjoint(line, LineString([(0, 2), (2, 0)]))
False
>>> empty = GeometryCollection()
>>> shapely.disjoint(line, empty)
True
>>> shapely.disjoint(empty, empty)
True
>>> shapely.disjoint(empty, None)
False
>>> shapely.disjoint(None, None)
False
shapely.disjoint_subset_union
Python Library Documentation: function disjoint_subset_union in module shapely.set_operations
disjoint_subset_union(a, b, **kwargs)
Merge multiple polygons into one using algorithm optimised for subsets.
This is an optimized version of union which assumes inputs can be
divided into subsets that do not intersect.
If there is only one such subset, performance can be expected to be worse than
:func:`union`. As such, it is recommeded to use ``disjoint_subset_union`` with
GeometryCollections rather than individual geometries.
.. versionadded:: 2.1.0
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to merge (union).
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
union
coverage_union
disjoint_subset_union_all
Examples
--------
>>> import shapely
>>> from shapely import Polygon
>>> polygon_1 = Polygon([(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)])
>>> polygon_2 = Polygon([(1, 0), (1, 1), (2, 1), (2, 0), (1, 0)])
>>> shapely.disjoint_subset_union(polygon_1, polygon_2).normalize()
<POLYGON ((0 0, 0 1, 1 1, 2 1, 2 0, 1 0, 0 0))>
Union with None returns same polygon:
>>> shapely.disjoint_subset_union(polygon_1, None).normalize()
<POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
shapely.disjoint_subset_union_all
Python Library Documentation: function disjoint_subset_union_all in module shapely.set_operations
disjoint_subset_union_all(geometries, *, axis=None, **kwargs)
Return the union of multiple polygons.
This is an optimized version of union which assumes inputs can be divided into
subsets that do not intersect.
If there is only one such subset, performance can be expected to be worse than
:func:`union_all`.
This function ignores None values when other Geometry elements are present.
If all elements of the given axis are None, an empty GeometryCollection is
returned.
.. versionadded:: 2.1.0
Parameters
----------
geometries : array_like
Geometries to union.
axis : int, optional
Axis along which the operation is performed. The default (None)
performs the operation over all axes, returning a scalar value.
Axis may be negative, in which case it counts from the last to the
first axis.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
coverage_union_all
union_all
disjoint_subset_union
Examples
--------
>>> import shapely
>>> from shapely import Polygon
>>> polygon_1 = Polygon([(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)])
>>> polygon_2 = Polygon([(1, 0), (1, 1), (2, 1), (2, 0), (1, 0)])
>>> shapely.disjoint_subset_union_all([polygon_1, polygon_2]).normalize()
<POLYGON ((0 0, 0 1, 1 1, 2 1, 2 0, 1 0, 0 0))>
>>> shapely.disjoint_subset_union_all([polygon_1, None]).normalize()
<POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
>>> shapely.disjoint_subset_union_all([None, None]).normalize()
<GEOMETRYCOLLECTION EMPTY>
shapely.distance
Python Library Documentation: function distance in module shapely.measurement
distance(a, b, **kwargs)
Compute the Cartesian distance between two geometries.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to compute the distance between.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point, Polygon
>>> point = Point(0, 0)
>>> shapely.distance(Point(10, 0), point)
10.0
>>> shapely.distance(LineString([(1, 1), (1, -1)]), point)
1.0
>>> shapely.distance(Polygon([(3, 0), (5, 0), (5, 5), (3, 5), (3, 0)]), point)
3.0
>>> shapely.distance(Point(), point)
nan
>>> shapely.distance(None, point)
nan
shapely.dwithin
Python Library Documentation: function dwithin in module shapely.predicates
dwithin(a, b, distance, **kwargs)
Return True if the geometries are within a given distance.
Using this function is more efficient than computing the distance and
comparing the result.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
distance : float
Negative distances always return False.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
distance : compute the actual distance between A and B
prepare : improve performance by preparing ``a`` (the first argument)
Examples
--------
>>> import shapely
>>> from shapely import Point
>>> point = Point(0.5, 0.5)
>>> shapely.dwithin(point, Point(2, 0.5), 2)
True
>>> shapely.dwithin(point, Point(2, 0.5), [2, 1.5, 1]).tolist()
[True, True, False]
>>> shapely.dwithin(point, Point(0.5, 0.5), 0)
True
>>> shapely.dwithin(point, None, 100)
False
shapely.empty
Python Library Documentation: function empty in module shapely.creation
empty(shape, geom_type=None, order='C')
Create a geometry array prefilled with None or with empty geometries.
Parameters
----------
shape : int or tuple of int
Shape of the empty array, e.g., ``(2, 3)`` or ``2``.
geom_type : shapely.GeometryType, optional
The desired geometry type in case the array should be prefilled
with empty geometries. Default ``None``.
order : {'C', 'F'}, optional, default: 'C'
Whether to store multi-dimensional data in row-major
(C-style) or column-major (Fortran-style) order in
memory.
Examples
--------
>>> import shapely
>>> shapely.empty((2, 3)).tolist()
[[None, None, None], [None, None, None]]
>>> shapely.empty(2, geom_type=shapely.GeometryType.POINT).tolist()
[<POINT EMPTY>, <POINT EMPTY>]
shapely.envelope
Python Library Documentation: function envelope in module shapely.constructive
envelope(geometry, **kwargs)
Compute the minimum bounding box that encloses an input geometry.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the envelope.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, LineString, MultiPoint, Point
>>> shapely.envelope(LineString([(0, 0), (10, 10)]))
<POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))>
>>> shapely.envelope(MultiPoint([(0, 0), (10, 10)]))
<POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))>
>>> shapely.envelope(Point(0, 0))
<POINT (0 0)>
>>> shapely.envelope(GeometryCollection([]))
<POINT EMPTY>
shapely.equals
Python Library Documentation: function equals in module shapely.predicates
equals(a, b, **kwargs)
Return True if A and B are spatially equal.
If A is within B and B is within A, A and B are considered equal. The
ordering of points can be different.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
equals_exact : Check if A and B are structurally equal given a specified
tolerance.
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, LineString, Polygon
>>> line = LineString([(0, 0), (5, 5), (10, 10)])
>>> shapely.equals(line, LineString([(0, 0), (10, 10)]))
True
>>> shapely.equals(Polygon(), GeometryCollection())
True
>>> shapely.equals(None, None)
False
shapely.equals_exact
Python Library Documentation: function equals_exact in module shapely.predicates
equals_exact(a, b, tolerance=0.0, *, normalize=False, **kwargs)
Return True if the geometries are structurally equivalent within a given
tolerance.
This method uses exact coordinate equality, which requires coordinates
to be equal (within specified tolerance) and in the same order for
all components (vertices, rings, or parts) of a geometry. This is in
contrast with the :func:`equals` function which uses spatial
(topological) equality and does not require all components to be in the
same order. Because of this, it is possible for :func:`equals` to
be ``True`` while :func:`equals_exact` is ``False``.
The order of the coordinates can be normalized (by setting the `normalize`
keyword to ``True``) so that this function will return ``True`` when geometries
are structurally equivalent but differ only in the ordering of vertices.
However, this function will still return ``False`` if the order of interior
rings within a :class:`Polygon` or the order of geometries within a multi
geometry are different.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
tolerance : float or array_like (default: 0.)
The tolerance to use in the comparison.
normalize : bool, optional (default: False)
If True, normalize the two geometries so that the coordinates are
in the same order.
.. versionadded:: 2.1.0
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
equals : Check if `a` and `b` are spatially (topologically) equal.
Examples
--------
>>> import shapely
>>> from shapely import Point, Polygon
>>> point1 = Point(50, 50)
>>> point2 = Point(50.1, 50.1)
>>> shapely.equals_exact(point1, point2)
False
>>> shapely.equals_exact(point1, point2, tolerance=0.2)
True
>>> shapely.equals_exact(point1, None, tolerance=0.2)
False
Difference between structural and spatial equality:
>>> polygon1 = Polygon([(0, 0), (1, 1), (0, 1), (0, 0)])
>>> polygon2 = Polygon([(0, 0), (0, 1), (1, 1), (0, 0)])
>>> shapely.equals_exact(polygon1, polygon2)
False
>>> shapely.equals(polygon1, polygon2)
True
shapely.equals_identical
Python Library Documentation: function equals_identical in module shapely.predicates
equals_identical(a, b, **kwargs)
Return True if the geometries are identical.
This function verifies whether geometries are pointwise equivalent by checking
that the structure, ordering, and values of all vertices are identical
in all dimensions.
Similarly to :func:`equals_exact`, this function uses exact coordinate
equality and requires coordinates to be in the same order for all
components (vertices, rings, or parts) of a geometry. However, in
contrast :func:`equals_exact`, this function does not allow to specify
a tolerance, but does require all dimensions to be the same
(:func:`equals_exact` ignores the Z and M dimensions), and NaN values
are considered to be equal to other NaN values.
This function is the vectorized equivalent of scalar equality of
geometry objects (``a == b``, i.e. ``__eq__``).
.. versionadded:: 2.1.0
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
equals_exact : Check if geometries are structurally equal given a specified
tolerance.
equals : Check if geometries are spatially (topologically) equal.
Examples
--------
>>> import shapely
>>> from shapely import Point
>>> shapely.equals_identical(Point(1, 2, 3), Point(1, 2, 3))
True
>>> shapely.equals_identical(Point(1, 2, 3), Point(1, 2, 0))
False
shapely.errors
Python Library Documentation: module shapely.errors in shapely
NAME
shapely.errors - Shapely errors.
CLASSES
builtins.Exception(builtins.BaseException)
ShapelyError
DimensionError
EmptyPartError
GEOSException
GeometryTypeError
TopologicalError
UnsupportedGEOSVersionError
builtins.FutureWarning(builtins.Warning)
ShapelyDeprecationWarning
class DimensionError(ShapelyError)
| An error in the number of coordinate dimensions.
|
| Method resolution order:
| DimensionError
| ShapelyError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors inherited from ShapelyError:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class EmptyPartError(ShapelyError)
| An error signifying an empty part was encountered when creating a multi-part.
|
| Method resolution order:
| EmptyPartError
| ShapelyError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors inherited from ShapelyError:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class GEOSException(ShapelyError)
| Method resolution order:
| GEOSException
| ShapelyError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors inherited from ShapelyError:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class GeometryTypeError(ShapelyError)
| An error raised when the geometry has an unrecognized or inappropriate type.
|
| Method resolution order:
| GeometryTypeError
| ShapelyError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors inherited from ShapelyError:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class ShapelyDeprecationWarning(builtins.FutureWarning)
| Warning for features that will be removed or changed in a future release.
|
| Method resolution order:
| ShapelyDeprecationWarning
| builtins.FutureWarning
| builtins.Warning
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors defined here:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.FutureWarning:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.FutureWarning:
|
| __new__(*args, **kwargs) class method of builtins.FutureWarning
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class ShapelyError(builtins.Exception)
| Method resolution order:
| ShapelyError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors defined here:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class TopologicalError(ShapelyError)
| A geometry is invalid or topologically incorrect.
|
| Method resolution order:
| TopologicalError
| ShapelyError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors inherited from ShapelyError:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
class UnsupportedGEOSVersionError(ShapelyError)
| Raised when the GEOS library version does not support a certain operation.
|
| Method resolution order:
| UnsupportedGEOSVersionError
| ShapelyError
| builtins.Exception
| builtins.BaseException
| builtins.object
|
| Data descriptors inherited from ShapelyError:
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.Exception:
|
| __init__(self, /, *args, **kwargs)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Static methods inherited from builtins.Exception:
|
| __new__(*args, **kwargs) class method of builtins.Exception
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Methods inherited from builtins.BaseException:
|
| __getattribute__(self, name, /)
| Return getattr(self, name).
|
| __reduce__(...)
| Helper for pickle.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
|
| __str__(self, /)
| Return str(self).
|
| add_note(...)
| Exception.add_note(note) --
| add a note to the exception
|
| with_traceback(...)
| Exception.with_traceback(tb) --
| set self.__traceback__ to tb and return self.
|
| ----------------------------------------------------------------------
| Data descriptors inherited from builtins.BaseException:
|
| __cause__
| exception cause
|
| __context__
| exception context
|
| __dict__
|
| __suppress_context__
|
| __traceback__
|
| args
FUNCTIONS
__getattr__(name)
setup_signal_checks(interval=10000)
Enable Python signal checks in the ufunc inner loops.
Doing so allows termination (using CTRL+C) of operations on large arrays of
vectors.
Parameters
----------
interval : int, default 10000
Check for interrupts every x iterations. The higher the number, the
slower shapely will respond to a signal. However, at low values there
will be a negative effect on performance. The default of 10000 does not
have any measureable effects on performance.
Notes
-----
For more information on signals consult the Python docs:
https://docs.python.org/3/library/signal.html
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\shapely\errors.py
shapely.extract_unique_points
Python Library Documentation: function extract_unique_points in module shapely.constructive
extract_unique_points(geometry, **kwargs)
Return all distinct vertices of an input geometry as a multipoint.
Note that only 2 dimensions of the vertices are considered when testing
for equality.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to extract unique points.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, MultiPoint, Point, Polygon
>>> shapely.extract_unique_points(Point(0, 0))
<MULTIPOINT ((0 0))>
>>> shapely.extract_unique_points(LineString([(0, 0), (1, 1), (1, 1)]))
<MULTIPOINT ((0 0), (1 1))>
>>> shapely.extract_unique_points(Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]))
<MULTIPOINT ((0 0), (1 0), (1 1), (0 1))>
>>> shapely.extract_unique_points(MultiPoint([(0, 0), (1, 1), (0, 0)]))
<MULTIPOINT ((0 0), (1 1))>
>>> shapely.extract_unique_points(LineString())
<MULTIPOINT EMPTY>
shapely.force_2d
Python Library Documentation: function force_2d in module shapely._geometry
force_2d(geometry, **kwargs)
Force the dimensionality of a geometry to 2D.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to force to 2D.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point, Polygon, from_wkt
>>> shapely.force_2d(Point(0, 0, 1))
<POINT (0 0)>
>>> shapely.force_2d(Point(0, 0))
<POINT (0 0)>
>>> shapely.force_2d(LineString([(0, 0, 0), (0, 1, 1), (1, 1, 2)]))
<LINESTRING (0 0, 0 1, 1 1)>
>>> shapely.force_2d(from_wkt("POLYGON Z EMPTY"))
<POLYGON EMPTY>
>>> shapely.force_2d(None) is None
True
shapely.force_3d
Python Library Documentation: function force_3d in module shapely._geometry
force_3d(geometry, z=0.0, **kwargs)
Force the dimensionality of a geometry to 3D.
2D geometries will get the provided Z coordinate; Z coordinates of 3D geometries
are unchanged (unless they are nan).
Note that for empty geometries, 3D is only supported since GEOS 3.9 and then
still only for simple geometries (non-collections).
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to force to 3D.
z : float or array_like, default 0.0
The Z coordinate value to set on the geometry.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> shapely.force_3d(Point(0, 0), z=3)
<POINT Z (0 0 3)>
>>> shapely.force_3d(Point(0, 0, 0), z=3)
<POINT Z (0 0 0)>
>>> shapely.force_3d(LineString([(0, 0), (0, 1), (1, 1)]))
<LINESTRING Z (0 0 0, 0 1 0, 1 1 0)>
>>> shapely.force_3d(None) is None
True
shapely.frechet_distance
Python Library Documentation: function frechet_distance in module shapely.measurement
frechet_distance(a, b, densify=None, **kwargs)
Compute the discrete Fréchet distance between two geometries.
The Fréchet distance is a measure of similarity: it is the greatest
distance between any point in A and the closest point in B. The discrete
distance is an approximation of this metric: only vertices are considered.
The parameter 'densify' makes this approximation less coarse by splitting
the line segments between vertices before computing the distance.
Fréchet distance sweep continuously along their respective curves
and the direction of curves is significant. This makes it a better measure
of similarity than Hausdorff distance for curve or surface matching.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to compute the distance between.
densify : float or array_like, optional
The value of densify is required to be between 0 and 1.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString
>>> line1 = LineString([(0, 0), (100, 0)])
>>> line2 = LineString([(0, 0), (50, 50), (100, 0)])
>>> shapely.frechet_distance(line1, line2)
70.71067811865476
>>> shapely.frechet_distance(line1, line2, densify=0.5)
50.0
>>> shapely.frechet_distance(line1, LineString())
nan
>>> shapely.frechet_distance(line1, None)
nan
shapely.from_geojson
Python Library Documentation: function from_geojson in module shapely.io
from_geojson(geometry, on_invalid='raise', **kwargs)
Create geometries from GeoJSON representations (strings).
If a GeoJSON is a FeatureCollection, it is read as a single geometry
(with type GEOMETRYCOLLECTION). This may be unpacked using
:meth:`shapely.get_parts`. Properties are not read.
The GeoJSON format is defined in `RFC 7946 <https://geojson.org/>`__.
The following are currently unsupported:
- Three-dimensional geometries: the third dimension is ignored.
- Geometries having 'null' in the coordinates.
Parameters
----------
geometry : str, bytes or array_like
The GeoJSON string or byte object(s) to convert.
on_invalid : {"raise", "warn", "ignore"}, default "raise"
- raise: an exception will be raised if an input GeoJSON is invalid.
- warn: a warning will be raised and invalid input geometries will be
returned as ``None``.
- ignore: invalid input geometries will be returned as ``None`` without
a warning.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
get_parts
Examples
--------
>>> import shapely
>>> shapely.from_geojson('{"type": "Point","coordinates": [1, 2]}')
<POINT (1 2)>
shapely.from_ragged_array
Python Library Documentation: function from_ragged_array in module shapely._ragged_array
from_ragged_array(geometry_type, coords, offsets=None)
Create geometries from a contiguous array of coordinates and offset arrays.
This function creates geometries from the ragged array representation
as returned by ``to_ragged_array``.
This follows the in-memory layout of the variable size list arrays defined
by Apache Arrow, as specified for geometries by the GeoArrow project:
https://github.com/geoarrow/geoarrow.
See :func:`to_ragged_array` for more details.
Parameters
----------
geometry_type : GeometryType
The type of geometry to create.
coords : np.ndarray
Contiguous array of shape (n, 2) or (n, 3) of all coordinates
for the geometries.
offsets: tuple of np.ndarray
Offset arrays that allow to reconstruct the geometries based on the
flat coordinates array. The number of offset arrays depends on the
geometry type. See
https://github.com/geoarrow/geoarrow/blob/main/format.md for details.
Returns
-------
np.ndarray
Array of geometries (1-dimensional).
See Also
--------
to_ragged_array
shapely.from_wkb
Python Library Documentation: function from_wkb in module shapely.io
from_wkb(geometry, on_invalid='raise', **kwargs)
Create geometries from the Well-Known Binary (WKB) representation.
The Well-Known Binary format is defined in the `OGC Simple Features
Specification for SQL <https://www.opengeospatial.org/standards/sfs>`__.
Parameters
----------
geometry : str or array_like
The WKB byte object(s) to convert.
on_invalid : {"raise", "warn", "ignore", "fix"}, default "raise"
Indicates what to do when an invalid WKB is encountered. Note that the
validations involved are very basic, e.g. the minimum number of points
for the geometry type. For a thorough check, use :func:`is_valid` after
conversion to geometries. Valid options are:
- raise: an exception will be raised if any input geometry is invalid.
- warn: a warning will be raised and invalid WKT geometries will be
returned as ``None``.
- ignore: invalid geometries will be returned as ``None`` without a
warning.
- fix: an effort is made to fix invalid input geometries (currently just
unclosed rings). If this is not possible, they are returned as
``None`` without a warning. Requires GEOS >= 3.11.
.. versionadded:: 2.1.0
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> shapely.from_wkb(b'\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0?')
<POINT (1 1)>
shapely.from_wkt
Python Library Documentation: function from_wkt in module shapely.io
from_wkt(geometry, on_invalid='raise', **kwargs)
Create geometries from the Well-Known Text (WKT) representation.
The Well-known Text format is defined in the `OGC Simple Features
Specification for SQL <https://www.opengeospatial.org/standards/sfs>`__.
Parameters
----------
geometry : str or array_like
The WKT string(s) to convert.
on_invalid : {"raise", "warn", "ignore", "fix"}, default "raise"
Indicates what to do when an invalid WKT string is encountered. Note
that the validations involved are very basic, e.g. the minimum number of
points for the geometry type. For a thorough check, use
:func:`is_valid` after conversion to geometries. Valid options are:
- raise: an exception will be raised if any input geometry is invalid.
- warn: a warning will be raised and invalid WKT geometries will be
returned as ``None``.
- ignore: invalid geometries will be returned as ``None`` without a
warning.
- fix: an effort is made to fix invalid input geometries (currently just
unclosed rings). If this is not possible, they are returned as
``None`` without a warning. Requires GEOS >= 3.11.
.. versionadded:: 2.1.0
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> shapely.from_wkt('POINT (0 0)')
<POINT (0 0)>
shapely.geometry
Python Library Documentation: package shapely.geometry in shapely
NAME
shapely.geometry - Geometry classes and factories.
PACKAGE CONTENTS
base
collection
geo
linestring
multilinestring
multipoint
multipolygon
point
polygon
CLASSES
builtins.object
shapely.geometry.base.CAP_STYLE
shapely.geometry.base.JOIN_STYLE
shapely.geometry.base.BaseGeometry(shapely.lib.Geometry)
shapely.geometry.linestring.LineString
shapely.geometry.polygon.LinearRing
shapely.geometry.point.Point
shapely.geometry.polygon.Polygon
shapely.geometry.base.BaseMultipartGeometry(shapely.geometry.base.BaseGeometry)
shapely.geometry.collection.GeometryCollection
shapely.geometry.multilinestring.MultiLineString
shapely.geometry.multipoint.MultiPoint
shapely.geometry.multipolygon.MultiPolygon
class CAP_STYLE(builtins.object)
| Buffer cap styles.
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| flat = <BufferCapStyle.flat: 2>
|
| round = <BufferCapStyle.round: 1>
|
| square = <BufferCapStyle.square: 3>
class GeometryCollection(shapely.geometry.base.BaseMultipartGeometry)
| GeometryCollection(geoms=None)
|
| Collection of one or more geometries that can be of different types.
|
| Parameters
| ----------
| geoms : list
| A list of shapely geometry instances, which may be of varying geometry
| types.
|
| Attributes
| ----------
| geoms : sequence
| A sequence of Shapely geometry instances
|
| Examples
| --------
| Create a GeometryCollection with a Point and a LineString
|
| >>> from shapely import GeometryCollection, LineString, Point
| >>> p = Point(51, -1)
| >>> l = LineString([(52, -1), (49, 2)])
| >>> gc = GeometryCollection([p, l])
|
| Method resolution order:
| GeometryCollection
| shapely.geometry.base.BaseMultipartGeometry
| shapely.geometry.base.BaseGeometry
| shapely.lib.Geometry
| builtins.object
|
| Static methods defined here:
|
| __new__(self, geoms=None)
| Create a new GeometryCollection.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __geo_interface__
| Return a GeoJSON-like mapping of the geometry collection.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.geometry.base.BaseMultipartGeometry:
|
| __bool__(self)
| Return True if the geometry is not empty, else False.
|
| __eq__(self, other)
| Return True if geometries are equal, else False.
|
| __hash__(self)
| Return the hash value of the geometry.
|
| svg(self, scale_factor=1.0, color=None)
| Return a group of SVG elements for the multipart geometry.
|
| Parameters
| ----------
| scale_factor : float
| Multiplication factor for the SVG stroke-width. Default is 1.
| color : str, optional
| Hex string for stroke or fill color. Default is to use "#66cc99"
| if geometry is valid, and "#ff3333" if invalid.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from shapely.geometry.base.BaseMultipartGeometry:
|
| coords
| Not implemented.
|
| Sub-geometries may have coordinate sequences, but multi-part geometries
| do not.
|
| geoms
| Access to the contained geometries.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.geometry.base.BaseGeometry:
|
| __and__(self, other)
| Return the intersection of the geometries.
|
| __format__(self, format_spec)
| Format a geometry using a format specification.
|
| __nonzero__(self)
| Return True if the geometry is not empty, else False.
|
| __or__(self, other)
| Return the union of the geometries.
|
| __reduce__(self)
| Pickle support.
|
| __repr__(self)
| Return a string representation of the geometry.
|
| __str__(self)
| Return a string representation of the geometry.
|
| __sub__(self, other)
| Return the difference of the geometries.
|
| __xor__(self, other)
| Return the symmetric difference of the geometries.
|
| buffer(self, 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.
| quad_segs : int, optional
| Sets the number of line segments used to approximate an
| angle fillet.
| cap_style : shapely.BufferCapStyle or {'round', 'square', 'flat'}, 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 {'round', 'mitre', 'bevel'}, 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_sided : 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, resolution : int, optional
| Deprecated aliases for `quad_segs`.
| **kwargs : dict, optional
| For backwards compatibility of renamed parameters. If an unsupported
| kwarg is passed, a `ValueError` will be raised.
|
| Returns
| -------
| Geometry
|
| Notes
| -----
| The return value is a strictly two-dimensional geometry. All
| Z coordinates of the original geometry will be ignored.
|
| .. deprecated:: 2.1.0
| A deprecation warning is shown if ``quad_segs``, ``cap_style``,
| ``join_style``, ``mitre_limit`` or ``single_sided`` are
| specified as positional arguments. In a future release, these will
| need to be specified as keyword arguments.
|
| Examples
| --------
| >>> from shapely import BufferCapStyle
| >>> 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.1365484905459398
|
| 128-gon approximation:
|
| >>> g.buffer(1.0, 128).area
| 3.1415138011443013
|
| triangle approximation:
|
| >>> g.buffer(1.0, 3).area
| 3.0
| >>> list(g.buffer(1.0, cap_style=BufferCapStyle.square).exterior.coords)
| [(1.0, 1.0), (1.0, -1.0), (-1.0, -1.0), (-1.0, 1.0), (1.0, 1.0)]
| >>> g.buffer(1.0, cap_style=BufferCapStyle.square).area
| 4.0
|
| contains(self, other)
| Return True if the geometry contains the other, else False.
|
| contains_properly(self, other)
| Return True if the geometry completely contains the other.
|
| There should be no common boundary points.
|
| Refer to `shapely.contains_properly` for full documentation.
|
| covered_by(self, other)
| Return True if the geometry is covered by the other, else False.
|
| covers(self, other)
| Return True if the geometry covers the other, else False.
|
| crosses(self, other)
| Return True if the geometries cross, else False.
|
| difference(self, other, grid_size=None)
| Return the difference of the geometries.
|
| Refer to `shapely.difference` for full documentation.
|
| disjoint(self, other)
| Return True if geometries are disjoint, else False.
|
| distance(self, other)
| Unitless distance to other geometry (float).
|
| dwithin(self, other, distance)
| Return True if geometry is within a given distance from the other.
|
| Refer to `shapely.dwithin` for full documentation.
|
| equals(self, other)
| 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)).
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals(
| ... LineString([(0, 0), (1, 1), (2, 2)])
| ... )
| True
|
| Returns
| -------
| bool
|
| equals_exact(self, other, tolerance=0.0, *, normalize=False)
| Return True if the geometries are equivalent within the tolerance.
|
| Refer to :func:`~shapely.equals_exact` for full documentation.
|
| Parameters
| ----------
| other : BaseGeometry
| The other geometry object in this comparison.
| tolerance : float, optional (default: 0.)
| Absolute tolerance in the same units as coordinates.
| normalize : bool, optional (default: False)
| If True, normalize the two geometries so that the coordinates are
| in the same order.
|
| .. versionadded:: 2.1.0
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals_exact(
| ... LineString([(0, 0), (1, 1), (2, 2)]),
| ... 1e-6
| ... )
| False
|
| Returns
| -------
| bool
|
| geometryType(self)
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| hausdorff_distance(self, other)
| Unitless hausdorff distance to other geometry (float).
|
| interpolate(self, distance, normalized=False)
| 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`.
|
| intersection(self, other, grid_size=None)
| Return the intersection of the geometries.
|
| Refer to `shapely.intersection` for full documentation.
|
| intersects(self, other)
| Return True if geometries intersect, else False.
|
| line_interpolate_point(self, distance, normalized=False)
| 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`.
|
| line_locate_point(self, other, normalized=False)
| 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`.
|
| normalize(self)
| 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`).
|
| Examples
| --------
| >>> from shapely import MultiLineString
| >>> line = MultiLineString([[(0, 0), (1, 1)], [(3, 3), (2, 2)]])
| >>> line.normalize()
| <MULTILINESTRING ((2 2, 3 3), (0 0, 1 1))>
|
| overlaps(self, other)
| Return True if geometries overlap, else False.
|
| point_on_surface(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `representative_point`.
|
| project(self, other, normalized=False)
| 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`.
|
| relate(self, other)
| Return the DE-9IM intersection matrix for the two geometries (string).
|
| relate_pattern(self, other, pattern)
| Return True if the DE-9IM relationship code satisfies the pattern.
|
| representative_point(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `point_on_surface`.
|
| reverse(self)
| Return a copy of this geometry with the order of coordinates reversed.
|
| If the geometry is a polygon with interior rings, the interior rings are also
| reversed.
|
| Points are unchanged.
|
| See Also
| --------
| is_ccw : Checks if a geometry is clockwise.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (1, 2)]).reverse()
| <LINESTRING (1 2, 0 0)>
| >>> Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]).reverse()
| <POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
|
| segmentize(self, max_segment_length)
| 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.
|
| Parameters
| ----------
| max_segment_length : float or array_like
| Additional vertices will be added so that all line segments are no
| longer this value. Must be greater than 0.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (0, 10)]).segmentize(max_segment_length=5)
| <LINESTRING (0 0, 0 5, 0 10)>
| >>> Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]).segmentize(max_segment_length=5)
| <POLYGON ((0 0, 5 0, 10 0, 10 5, 10 10, 5 10, 0 10, 0 5, 0 0))>
|
| simplify(self, tolerance, preserve_topology=True)
| 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.
|
| symmetric_difference(self, other, grid_size=None)
| Return the symmetric difference of the geometries.
|
| Refer to `shapely.symmetric_difference` for full documentation.
|
| touches(self, other)
| Return True if geometries touch, else False.
|
| union(self, other, grid_size=None)
| Return the union of the geometries.
|
| Refer to `shapely.union` for full documentation.
|
| within(self, other)
| Return True if geometry is within the other, else False.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from shapely.geometry.base.BaseGeometry:
|
| area
| Unitless area of the geometry (float).
|
| 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.
|
| bounds
| Return minimum bounding region (minx, miny, maxx, maxy).
|
| centroid
| Return the geometric center of the object.
|
| 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.
|
| envelope
| A figure that envelopes the geometry.
|
| geom_type
| Name of the geometry's type, such as 'Point'.
|
| has_m
| True if the geometry's coordinate sequence(s) have m values.
|
| has_z
| True if the geometry's coordinate sequence(s) have z values.
|
| is_closed
| True if the geometry is closed, else False.
|
| Applicable only to linear geometries.
|
| is_empty
| True if the set of points in this geometry is empty, else False.
|
| is_ring
| True if the geometry is a closed ring, else False.
|
| is_simple
| True if the geometry is simple.
|
| Simple means that any self-intersections are only at boundary points.
|
| is_valid
| True if the geometry is valid.
|
| The definition depends on sub-class.
|
| length
| Unitless length of the geometry (float).
|
| minimum_clearance
| Unitless distance a node can be moved to produce an invalid geometry (float).
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `oriented_envelope`.
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `minimum_rotated_rectangle`.
|
| type
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| wkb
| WKB representation of the geometry.
|
| wkb_hex
| WKB hex representation of the geometry.
|
| wkt
| WKT representation of the geometry.
|
| xy
| Separate arrays of X and Y coordinate values.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.lib.Geometry:
|
| __ge__(self, value, /)
| Return self>=value.
|
| __gt__(self, value, /)
| Return self>value.
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __setstate__(...)
| For unpickling pre-shapely 2.0 pickles
class JOIN_STYLE(builtins.object)
| Buffer join styles.
|
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
|
| ----------------------------------------------------------------------
| Data and other attributes defined here:
|
| bevel = <BufferJoinStyle.bevel: 3>
|
| mitre = <BufferJoinStyle.mitre: 2>
|
| round = <BufferJoinStyle.round: 1>
class LineString(shapely.geometry.base.BaseGeometry)
| LineString(coordinates=None)
|
| A geometry type composed of one or more line segments.
|
| A LineString is a one-dimensional feature and has a non-zero length but
| zero area. It may approximate a curve and need not be straight. A LineString may
| be closed.
|
| Parameters
| ----------
| coordinates : 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, or combination of both.
|
| Examples
| --------
| Create a LineString with two segments
|
| >>> from shapely import LineString
| >>> a = LineString([[0, 0], [1, 0], [1, 1]])
| >>> a.length
| 2.0
|
| Method resolution order:
| LineString
| shapely.geometry.base.BaseGeometry
| shapely.lib.Geometry
| builtins.object
|
| Methods defined here:
|
| offset_curve(self, distance, quad_segs=16, join_style=<BufferJoinStyle.round: 1>, mitre_limit=5.0)
| Return a (Multi)LineString at a distance from the object.
|
| The side, left or right, is determined by the sign of the `distance`
| parameter (negative for right side offset, positive for left side
| offset). The resolution of the buffer around each vertex of the object
| increases by increasing the `quad_segs` keyword parameter.
|
| The join style is for outside corners between line segments. Accepted
| values are JOIN_STYLE.round (1), JOIN_STYLE.mitre (2), and
| JOIN_STYLE.bevel (3).
|
| The mitre ratio limit is used for very sharp corners. It 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
| far beyond 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.
|
| Note: the behaviour regarding orientation of the resulting line
| depends on the GEOS version. With GEOS < 3.11, the line retains the
| same direction for a left offset (positive distance) or has reverse
| direction for a right offset (negative distance), and this behaviour
| was documented as such in previous Shapely versions. Starting with
| GEOS 3.11, the function tries to preserve the orientation of the
| original line.
|
| parallel_offset(self, distance, side='right', resolution=16, join_style=<BufferJoinStyle.round: 1>, mitre_limit=5.0)
| Alternative method to :meth:`offset_curve` method.
|
| Older alternative method to the :meth:`offset_curve` method, but uses
| ``resolution`` instead of ``quad_segs`` and a ``side`` keyword
| ('left' or 'right') instead of sign of the distance. This method is
| kept for backwards compatibility for now, but is is recommended to
| use :meth:`offset_curve` instead.
|
| svg(self, scale_factor=1.0, stroke_color=None, opacity=None)
| Return SVG polyline element for the LineString geometry.
|
| Parameters
| ----------
| scale_factor : float
| Multiplication factor for the SVG stroke-width. Default is 1.
| stroke_color : str, optional
| Hex string for stroke color. Default is to use "#66cc99" if
| geometry is valid, and "#ff3333" if invalid.
| opacity : float
| Float number between 0 and 1 for color opacity. Default value is 0.8
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(self, coordinates=None)
| Create a new LineString geometry.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __geo_interface__
| Return a GeoJSON-like mapping of the LineString geometry.
|
| xy
| Separate arrays of X and Y coordinate values.
|
| Examples
| --------
| >>> from shapely import LineString
| >>> x, y = LineString([(0, 0), (1, 1)]).xy
| >>> list(x)
| [0.0, 1.0]
| >>> list(y)
| [0.0, 1.0]
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.geometry.base.BaseGeometry:
|
| __and__(self, other)
| Return the intersection of the geometries.
|
| __bool__(self)
| Return True if the geometry is not empty, else False.
|
| __format__(self, format_spec)
| Format a geometry using a format specification.
|
| __nonzero__(self)
| Return True if the geometry is not empty, else False.
|
| __or__(self, other)
| Return the union of the geometries.
|
| __reduce__(self)
| Pickle support.
|
| __repr__(self)
| Return a string representation of the geometry.
|
| __str__(self)
| Return a string representation of the geometry.
|
| __sub__(self, other)
| Return the difference of the geometries.
|
| __xor__(self, other)
| Return the symmetric difference of the geometries.
|
| buffer(self, 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.
| quad_segs : int, optional
| Sets the number of line segments used to approximate an
| angle fillet.
| cap_style : shapely.BufferCapStyle or {'round', 'square', 'flat'}, 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 {'round', 'mitre', 'bevel'}, 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_sided : 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, resolution : int, optional
| Deprecated aliases for `quad_segs`.
| **kwargs : dict, optional
| For backwards compatibility of renamed parameters. If an unsupported
| kwarg is passed, a `ValueError` will be raised.
|
| Returns
| -------
| Geometry
|
| Notes
| -----
| The return value is a strictly two-dimensional geometry. All
| Z coordinates of the original geometry will be ignored.
|
| .. deprecated:: 2.1.0
| A deprecation warning is shown if ``quad_segs``, ``cap_style``,
| ``join_style``, ``mitre_limit`` or ``single_sided`` are
| specified as positional arguments. In a future release, these will
| need to be specified as keyword arguments.
|
| Examples
| --------
| >>> from shapely import BufferCapStyle
| >>> 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.1365484905459398
|
| 128-gon approximation:
|
| >>> g.buffer(1.0, 128).area
| 3.1415138011443013
|
| triangle approximation:
|
| >>> g.buffer(1.0, 3).area
| 3.0
| >>> list(g.buffer(1.0, cap_style=BufferCapStyle.square).exterior.coords)
| [(1.0, 1.0), (1.0, -1.0), (-1.0, -1.0), (-1.0, 1.0), (1.0, 1.0)]
| >>> g.buffer(1.0, cap_style=BufferCapStyle.square).area
| 4.0
|
| contains(self, other)
| Return True if the geometry contains the other, else False.
|
| contains_properly(self, other)
| Return True if the geometry completely contains the other.
|
| There should be no common boundary points.
|
| Refer to `shapely.contains_properly` for full documentation.
|
| covered_by(self, other)
| Return True if the geometry is covered by the other, else False.
|
| covers(self, other)
| Return True if the geometry covers the other, else False.
|
| crosses(self, other)
| Return True if the geometries cross, else False.
|
| difference(self, other, grid_size=None)
| Return the difference of the geometries.
|
| Refer to `shapely.difference` for full documentation.
|
| disjoint(self, other)
| Return True if geometries are disjoint, else False.
|
| distance(self, other)
| Unitless distance to other geometry (float).
|
| dwithin(self, other, distance)
| Return True if geometry is within a given distance from the other.
|
| Refer to `shapely.dwithin` for full documentation.
|
| equals(self, other)
| 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)).
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals(
| ... LineString([(0, 0), (1, 1), (2, 2)])
| ... )
| True
|
| Returns
| -------
| bool
|
| equals_exact(self, other, tolerance=0.0, *, normalize=False)
| Return True if the geometries are equivalent within the tolerance.
|
| Refer to :func:`~shapely.equals_exact` for full documentation.
|
| Parameters
| ----------
| other : BaseGeometry
| The other geometry object in this comparison.
| tolerance : float, optional (default: 0.)
| Absolute tolerance in the same units as coordinates.
| normalize : bool, optional (default: False)
| If True, normalize the two geometries so that the coordinates are
| in the same order.
|
| .. versionadded:: 2.1.0
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals_exact(
| ... LineString([(0, 0), (1, 1), (2, 2)]),
| ... 1e-6
| ... )
| False
|
| Returns
| -------
| bool
|
| geometryType(self)
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| hausdorff_distance(self, other)
| Unitless hausdorff distance to other geometry (float).
|
| interpolate(self, distance, normalized=False)
| 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`.
|
| intersection(self, other, grid_size=None)
| Return the intersection of the geometries.
|
| Refer to `shapely.intersection` for full documentation.
|
| intersects(self, other)
| Return True if geometries intersect, else False.
|
| line_interpolate_point(self, distance, normalized=False)
| 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`.
|
| line_locate_point(self, other, normalized=False)
| 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`.
|
| normalize(self)
| 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`).
|
| Examples
| --------
| >>> from shapely import MultiLineString
| >>> line = MultiLineString([[(0, 0), (1, 1)], [(3, 3), (2, 2)]])
| >>> line.normalize()
| <MULTILINESTRING ((2 2, 3 3), (0 0, 1 1))>
|
| overlaps(self, other)
| Return True if geometries overlap, else False.
|
| point_on_surface(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `representative_point`.
|
| project(self, other, normalized=False)
| 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`.
|
| relate(self, other)
| Return the DE-9IM intersection matrix for the two geometries (string).
|
| relate_pattern(self, other, pattern)
| Return True if the DE-9IM relationship code satisfies the pattern.
|
| representative_point(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `point_on_surface`.
|
| reverse(self)
| Return a copy of this geometry with the order of coordinates reversed.
|
| If the geometry is a polygon with interior rings, the interior rings are also
| reversed.
|
| Points are unchanged.
|
| See Also
| --------
| is_ccw : Checks if a geometry is clockwise.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (1, 2)]).reverse()
| <LINESTRING (1 2, 0 0)>
| >>> Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]).reverse()
| <POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
|
| segmentize(self, max_segment_length)
| 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.
|
| Parameters
| ----------
| max_segment_length : float or array_like
| Additional vertices will be added so that all line segments are no
| longer this value. Must be greater than 0.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (0, 10)]).segmentize(max_segment_length=5)
| <LINESTRING (0 0, 0 5, 0 10)>
| >>> Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]).segmentize(max_segment_length=5)
| <POLYGON ((0 0, 5 0, 10 0, 10 5, 10 10, 5 10, 0 10, 0 5, 0 0))>
|
| simplify(self, tolerance, preserve_topology=True)
| 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.
|
| symmetric_difference(self, other, grid_size=None)
| Return the symmetric difference of the geometries.
|
| Refer to `shapely.symmetric_difference` for full documentation.
|
| touches(self, other)
| Return True if geometries touch, else False.
|
| union(self, other, grid_size=None)
| Return the union of the geometries.
|
| Refer to `shapely.union` for full documentation.
|
| within(self, other)
| Return True if geometry is within the other, else False.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from shapely.geometry.base.BaseGeometry:
|
| area
| Unitless area of the geometry (float).
|
| 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.
|
| bounds
| Return minimum bounding region (minx, miny, maxx, maxy).
|
| centroid
| Return the geometric center of the object.
|
| 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.
|
| coords
| Access to geometry's coordinates (CoordinateSequence).
|
| envelope
| A figure that envelopes the geometry.
|
| geom_type
| Name of the geometry's type, such as 'Point'.
|
| has_m
| True if the geometry's coordinate sequence(s) have m values.
|
| has_z
| True if the geometry's coordinate sequence(s) have z values.
|
| is_closed
| True if the geometry is closed, else False.
|
| Applicable only to linear geometries.
|
| is_empty
| True if the set of points in this geometry is empty, else False.
|
| is_ring
| True if the geometry is a closed ring, else False.
|
| is_simple
| True if the geometry is simple.
|
| Simple means that any self-intersections are only at boundary points.
|
| is_valid
| True if the geometry is valid.
|
| The definition depends on sub-class.
|
| length
| Unitless length of the geometry (float).
|
| minimum_clearance
| Unitless distance a node can be moved to produce an invalid geometry (float).
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `oriented_envelope`.
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `minimum_rotated_rectangle`.
|
| type
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| wkb
| WKB representation of the geometry.
|
| wkb_hex
| WKB hex representation of the geometry.
|
| wkt
| WKT representation of the geometry.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.lib.Geometry:
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __setstate__(...)
| For unpickling pre-shapely 2.0 pickles
class LinearRing(shapely.geometry.linestring.LineString)
| LinearRing(coordinates=None)
|
| Geometry type composed of one or more line segments that forms a closed loop.
|
| A LinearRing is a closed, one-dimensional feature.
| A LinearRing that crosses itself or touches itself at a single point is
| invalid and operations on it may fail.
|
| Parameters
| ----------
| coordinates : 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.
|
| Notes
| -----
| Rings are automatically closed. There is no need to specify a final
| coordinate pair identical to the first.
|
| Examples
| --------
| Construct a square ring.
|
| >>> from shapely import LinearRing
| >>> ring = LinearRing( ((0, 0), (0, 1), (1 ,1 ), (1 , 0)) )
| >>> ring.is_closed
| True
| >>> list(ring.coords)
| [(0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0), (0.0, 0.0)]
| >>> ring.length
| 4.0
|
| Method resolution order:
| LinearRing
| shapely.geometry.linestring.LineString
| shapely.geometry.base.BaseGeometry
| shapely.lib.Geometry
| builtins.object
|
| Methods defined here:
|
| __reduce__(self)
| Pickle support.
|
| WKB doesn't differentiate between LineString and LinearRing so we
| need to move the coordinate sequence into the correct geometry type
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(self, coordinates=None)
| Create a new LinearRing geometry.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __geo_interface__
| Return a GeoJSON-like mapping of the LinearRing geometry.
|
| is_ccw
| True if the ring is oriented counter clock-wise.
|
| is_simple
| True if the geometry is simple.
|
| Simple means that any self-intersections are only at boundary points.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.geometry.linestring.LineString:
|
| offset_curve(self, distance, quad_segs=16, join_style=<BufferJoinStyle.round: 1>, mitre_limit=5.0)
| Return a (Multi)LineString at a distance from the object.
|
| The side, left or right, is determined by the sign of the `distance`
| parameter (negative for right side offset, positive for left side
| offset). The resolution of the buffer around each vertex of the object
| increases by increasing the `quad_segs` keyword parameter.
|
| The join style is for outside corners between line segments. Accepted
| values are JOIN_STYLE.round (1), JOIN_STYLE.mitre (2), and
| JOIN_STYLE.bevel (3).
|
| The mitre ratio limit is used for very sharp corners. It 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
| far beyond 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.
|
| Note: the behaviour regarding orientation of the resulting line
| depends on the GEOS version. With GEOS < 3.11, the line retains the
| same direction for a left offset (positive distance) or has reverse
| direction for a right offset (negative distance), and this behaviour
| was documented as such in previous Shapely versions. Starting with
| GEOS 3.11, the function tries to preserve the orientation of the
| original line.
|
| parallel_offset(self, distance, side='right', resolution=16, join_style=<BufferJoinStyle.round: 1>, mitre_limit=5.0)
| Alternative method to :meth:`offset_curve` method.
|
| Older alternative method to the :meth:`offset_curve` method, but uses
| ``resolution`` instead of ``quad_segs`` and a ``side`` keyword
| ('left' or 'right') instead of sign of the distance. This method is
| kept for backwards compatibility for now, but is is recommended to
| use :meth:`offset_curve` instead.
|
| svg(self, scale_factor=1.0, stroke_color=None, opacity=None)
| Return SVG polyline element for the LineString geometry.
|
| Parameters
| ----------
| scale_factor : float
| Multiplication factor for the SVG stroke-width. Default is 1.
| stroke_color : str, optional
| Hex string for stroke color. Default is to use "#66cc99" if
| geometry is valid, and "#ff3333" if invalid.
| opacity : float
| Float number between 0 and 1 for color opacity. Default value is 0.8
|
| ----------------------------------------------------------------------
| Readonly properties inherited from shapely.geometry.linestring.LineString:
|
| xy
| Separate arrays of X and Y coordinate values.
|
| Examples
| --------
| >>> from shapely import LineString
| >>> x, y = LineString([(0, 0), (1, 1)]).xy
| >>> list(x)
| [0.0, 1.0]
| >>> list(y)
| [0.0, 1.0]
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.geometry.base.BaseGeometry:
|
| __and__(self, other)
| Return the intersection of the geometries.
|
| __bool__(self)
| Return True if the geometry is not empty, else False.
|
| __format__(self, format_spec)
| Format a geometry using a format specification.
|
| __nonzero__(self)
| Return True if the geometry is not empty, else False.
|
| __or__(self, other)
| Return the union of the geometries.
|
| __repr__(self)
| Return a string representation of the geometry.
|
| __str__(self)
| Return a string representation of the geometry.
|
| __sub__(self, other)
| Return the difference of the geometries.
|
| __xor__(self, other)
| Return the symmetric difference of the geometries.
|
| buffer(self, 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.
| quad_segs : int, optional
| Sets the number of line segments used to approximate an
| angle fillet.
| cap_style : shapely.BufferCapStyle or {'round', 'square', 'flat'}, 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 {'round', 'mitre', 'bevel'}, 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_sided : 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, resolution : int, optional
| Deprecated aliases for `quad_segs`.
| **kwargs : dict, optional
| For backwards compatibility of renamed parameters. If an unsupported
| kwarg is passed, a `ValueError` will be raised.
|
| Returns
| -------
| Geometry
|
| Notes
| -----
| The return value is a strictly two-dimensional geometry. All
| Z coordinates of the original geometry will be ignored.
|
| .. deprecated:: 2.1.0
| A deprecation warning is shown if ``quad_segs``, ``cap_style``,
| ``join_style``, ``mitre_limit`` or ``single_sided`` are
| specified as positional arguments. In a future release, these will
| need to be specified as keyword arguments.
|
| Examples
| --------
| >>> from shapely import BufferCapStyle
| >>> 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.1365484905459398
|
| 128-gon approximation:
|
| >>> g.buffer(1.0, 128).area
| 3.1415138011443013
|
| triangle approximation:
|
| >>> g.buffer(1.0, 3).area
| 3.0
| >>> list(g.buffer(1.0, cap_style=BufferCapStyle.square).exterior.coords)
| [(1.0, 1.0), (1.0, -1.0), (-1.0, -1.0), (-1.0, 1.0), (1.0, 1.0)]
| >>> g.buffer(1.0, cap_style=BufferCapStyle.square).area
| 4.0
|
| contains(self, other)
| Return True if the geometry contains the other, else False.
|
| contains_properly(self, other)
| Return True if the geometry completely contains the other.
|
| There should be no common boundary points.
|
| Refer to `shapely.contains_properly` for full documentation.
|
| covered_by(self, other)
| Return True if the geometry is covered by the other, else False.
|
| covers(self, other)
| Return True if the geometry covers the other, else False.
|
| crosses(self, other)
| Return True if the geometries cross, else False.
|
| difference(self, other, grid_size=None)
| Return the difference of the geometries.
|
| Refer to `shapely.difference` for full documentation.
|
| disjoint(self, other)
| Return True if geometries are disjoint, else False.
|
| distance(self, other)
| Unitless distance to other geometry (float).
|
| dwithin(self, other, distance)
| Return True if geometry is within a given distance from the other.
|
| Refer to `shapely.dwithin` for full documentation.
|
| equals(self, other)
| 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)).
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals(
| ... LineString([(0, 0), (1, 1), (2, 2)])
| ... )
| True
|
| Returns
| -------
| bool
|
| equals_exact(self, other, tolerance=0.0, *, normalize=False)
| Return True if the geometries are equivalent within the tolerance.
|
| Refer to :func:`~shapely.equals_exact` for full documentation.
|
| Parameters
| ----------
| other : BaseGeometry
| The other geometry object in this comparison.
| tolerance : float, optional (default: 0.)
| Absolute tolerance in the same units as coordinates.
| normalize : bool, optional (default: False)
| If True, normalize the two geometries so that the coordinates are
| in the same order.
|
| .. versionadded:: 2.1.0
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals_exact(
| ... LineString([(0, 0), (1, 1), (2, 2)]),
| ... 1e-6
| ... )
| False
|
| Returns
| -------
| bool
|
| geometryType(self)
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| hausdorff_distance(self, other)
| Unitless hausdorff distance to other geometry (float).
|
| interpolate(self, distance, normalized=False)
| 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`.
|
| intersection(self, other, grid_size=None)
| Return the intersection of the geometries.
|
| Refer to `shapely.intersection` for full documentation.
|
| intersects(self, other)
| Return True if geometries intersect, else False.
|
| line_interpolate_point(self, distance, normalized=False)
| 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`.
|
| line_locate_point(self, other, normalized=False)
| 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`.
|
| normalize(self)
| 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`).
|
| Examples
| --------
| >>> from shapely import MultiLineString
| >>> line = MultiLineString([[(0, 0), (1, 1)], [(3, 3), (2, 2)]])
| >>> line.normalize()
| <MULTILINESTRING ((2 2, 3 3), (0 0, 1 1))>
|
| overlaps(self, other)
| Return True if geometries overlap, else False.
|
| point_on_surface(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `representative_point`.
|
| project(self, other, normalized=False)
| 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`.
|
| relate(self, other)
| Return the DE-9IM intersection matrix for the two geometries (string).
|
| relate_pattern(self, other, pattern)
| Return True if the DE-9IM relationship code satisfies the pattern.
|
| representative_point(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `point_on_surface`.
|
| reverse(self)
| Return a copy of this geometry with the order of coordinates reversed.
|
| If the geometry is a polygon with interior rings, the interior rings are also
| reversed.
|
| Points are unchanged.
|
| See Also
| --------
| is_ccw : Checks if a geometry is clockwise.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (1, 2)]).reverse()
| <LINESTRING (1 2, 0 0)>
| >>> Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]).reverse()
| <POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
|
| segmentize(self, max_segment_length)
| 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.
|
| Parameters
| ----------
| max_segment_length : float or array_like
| Additional vertices will be added so that all line segments are no
| longer this value. Must be greater than 0.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (0, 10)]).segmentize(max_segment_length=5)
| <LINESTRING (0 0, 0 5, 0 10)>
| >>> Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]).segmentize(max_segment_length=5)
| <POLYGON ((0 0, 5 0, 10 0, 10 5, 10 10, 5 10, 0 10, 0 5, 0 0))>
|
| simplify(self, tolerance, preserve_topology=True)
| 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.
|
| symmetric_difference(self, other, grid_size=None)
| Return the symmetric difference of the geometries.
|
| Refer to `shapely.symmetric_difference` for full documentation.
|
| touches(self, other)
| Return True if geometries touch, else False.
|
| union(self, other, grid_size=None)
| Return the union of the geometries.
|
| Refer to `shapely.union` for full documentation.
|
| within(self, other)
| Return True if geometry is within the other, else False.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from shapely.geometry.base.BaseGeometry:
|
| area
| Unitless area of the geometry (float).
|
| 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.
|
| bounds
| Return minimum bounding region (minx, miny, maxx, maxy).
|
| centroid
| Return the geometric center of the object.
|
| 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.
|
| coords
| Access to geometry's coordinates (CoordinateSequence).
|
| envelope
| A figure that envelopes the geometry.
|
| geom_type
| Name of the geometry's type, such as 'Point'.
|
| has_m
| True if the geometry's coordinate sequence(s) have m values.
|
| has_z
| True if the geometry's coordinate sequence(s) have z values.
|
| is_closed
| True if the geometry is closed, else False.
|
| Applicable only to linear geometries.
|
| is_empty
| True if the set of points in this geometry is empty, else False.
|
| is_ring
| True if the geometry is a closed ring, else False.
|
| is_valid
| True if the geometry is valid.
|
| The definition depends on sub-class.
|
| length
| Unitless length of the geometry (float).
|
| minimum_clearance
| Unitless distance a node can be moved to produce an invalid geometry (float).
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `oriented_envelope`.
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `minimum_rotated_rectangle`.
|
| type
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| wkb
| WKB representation of the geometry.
|
| wkb_hex
| WKB hex representation of the geometry.
|
| wkt
| WKT representation of the geometry.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.lib.Geometry:
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __setstate__(...)
| For unpickling pre-shapely 2.0 pickles
class MultiLineString(shapely.geometry.base.BaseMultipartGeometry)
| MultiLineString(lines=None)
|
| A collection of one or more LineStrings.
|
| A MultiLineString has non-zero length and zero area.
|
| Parameters
| ----------
| lines : sequence
| A sequence LineStrings, or a sequence of line-like coordinate
| sequences or array-likes (see accepted input for LineString).
|
| Attributes
| ----------
| geoms : sequence
| A sequence of LineStrings
|
| Examples
| --------
| Construct a MultiLineString containing two LineStrings.
|
| >>> from shapely import MultiLineString
| >>> lines = MultiLineString([[[0, 0], [1, 2]], [[4, 4], [5, 6]]])
|
| Method resolution order:
| MultiLineString
| shapely.geometry.base.BaseMultipartGeometry
| shapely.geometry.base.BaseGeometry
| shapely.lib.Geometry
| builtins.object
|
| Methods defined here:
|
| svg(self, scale_factor=1.0, stroke_color=None, opacity=None)
| Return a group of SVG polyline elements for the LineString geometry.
|
| Parameters
| ----------
| scale_factor : float
| Multiplication factor for the SVG stroke-width. Default is 1.
| stroke_color : str, optional
| Hex string for stroke color. Default is to use "#66cc99" if
| geometry is valid, and "#ff3333" if invalid.
| opacity : float
| Float number between 0 and 1 for color opacity. Default value is 0.8
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(self, lines=None)
| Create a new MultiLineString geometry.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __geo_interface__
| Return a GeoJSON-like mapping interface for this MultiLineString.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.geometry.base.BaseMultipartGeometry:
|
| __bool__(self)
| Return True if the geometry is not empty, else False.
|
| __eq__(self, other)
| Return True if geometries are equal, else False.
|
| __hash__(self)
| Return the hash value of the geometry.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from shapely.geometry.base.BaseMultipartGeometry:
|
| coords
| Not implemented.
|
| Sub-geometries may have coordinate sequences, but multi-part geometries
| do not.
|
| geoms
| Access to the contained geometries.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.geometry.base.BaseGeometry:
|
| __and__(self, other)
| Return the intersection of the geometries.
|
| __format__(self, format_spec)
| Format a geometry using a format specification.
|
| __nonzero__(self)
| Return True if the geometry is not empty, else False.
|
| __or__(self, other)
| Return the union of the geometries.
|
| __reduce__(self)
| Pickle support.
|
| __repr__(self)
| Return a string representation of the geometry.
|
| __str__(self)
| Return a string representation of the geometry.
|
| __sub__(self, other)
| Return the difference of the geometries.
|
| __xor__(self, other)
| Return the symmetric difference of the geometries.
|
| buffer(self, 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.
| quad_segs : int, optional
| Sets the number of line segments used to approximate an
| angle fillet.
| cap_style : shapely.BufferCapStyle or {'round', 'square', 'flat'}, 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 {'round', 'mitre', 'bevel'}, 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_sided : 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, resolution : int, optional
| Deprecated aliases for `quad_segs`.
| **kwargs : dict, optional
| For backwards compatibility of renamed parameters. If an unsupported
| kwarg is passed, a `ValueError` will be raised.
|
| Returns
| -------
| Geometry
|
| Notes
| -----
| The return value is a strictly two-dimensional geometry. All
| Z coordinates of the original geometry will be ignored.
|
| .. deprecated:: 2.1.0
| A deprecation warning is shown if ``quad_segs``, ``cap_style``,
| ``join_style``, ``mitre_limit`` or ``single_sided`` are
| specified as positional arguments. In a future release, these will
| need to be specified as keyword arguments.
|
| Examples
| --------
| >>> from shapely import BufferCapStyle
| >>> 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.1365484905459398
|
| 128-gon approximation:
|
| >>> g.buffer(1.0, 128).area
| 3.1415138011443013
|
| triangle approximation:
|
| >>> g.buffer(1.0, 3).area
| 3.0
| >>> list(g.buffer(1.0, cap_style=BufferCapStyle.square).exterior.coords)
| [(1.0, 1.0), (1.0, -1.0), (-1.0, -1.0), (-1.0, 1.0), (1.0, 1.0)]
| >>> g.buffer(1.0, cap_style=BufferCapStyle.square).area
| 4.0
|
| contains(self, other)
| Return True if the geometry contains the other, else False.
|
| contains_properly(self, other)
| Return True if the geometry completely contains the other.
|
| There should be no common boundary points.
|
| Refer to `shapely.contains_properly` for full documentation.
|
| covered_by(self, other)
| Return True if the geometry is covered by the other, else False.
|
| covers(self, other)
| Return True if the geometry covers the other, else False.
|
| crosses(self, other)
| Return True if the geometries cross, else False.
|
| difference(self, other, grid_size=None)
| Return the difference of the geometries.
|
| Refer to `shapely.difference` for full documentation.
|
| disjoint(self, other)
| Return True if geometries are disjoint, else False.
|
| distance(self, other)
| Unitless distance to other geometry (float).
|
| dwithin(self, other, distance)
| Return True if geometry is within a given distance from the other.
|
| Refer to `shapely.dwithin` for full documentation.
|
| equals(self, other)
| 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)).
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals(
| ... LineString([(0, 0), (1, 1), (2, 2)])
| ... )
| True
|
| Returns
| -------
| bool
|
| equals_exact(self, other, tolerance=0.0, *, normalize=False)
| Return True if the geometries are equivalent within the tolerance.
|
| Refer to :func:`~shapely.equals_exact` for full documentation.
|
| Parameters
| ----------
| other : BaseGeometry
| The other geometry object in this comparison.
| tolerance : float, optional (default: 0.)
| Absolute tolerance in the same units as coordinates.
| normalize : bool, optional (default: False)
| If True, normalize the two geometries so that the coordinates are
| in the same order.
|
| .. versionadded:: 2.1.0
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals_exact(
| ... LineString([(0, 0), (1, 1), (2, 2)]),
| ... 1e-6
| ... )
| False
|
| Returns
| -------
| bool
|
| geometryType(self)
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| hausdorff_distance(self, other)
| Unitless hausdorff distance to other geometry (float).
|
| interpolate(self, distance, normalized=False)
| 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`.
|
| intersection(self, other, grid_size=None)
| Return the intersection of the geometries.
|
| Refer to `shapely.intersection` for full documentation.
|
| intersects(self, other)
| Return True if geometries intersect, else False.
|
| line_interpolate_point(self, distance, normalized=False)
| 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`.
|
| line_locate_point(self, other, normalized=False)
| 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`.
|
| normalize(self)
| 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`).
|
| Examples
| --------
| >>> from shapely import MultiLineString
| >>> line = MultiLineString([[(0, 0), (1, 1)], [(3, 3), (2, 2)]])
| >>> line.normalize()
| <MULTILINESTRING ((2 2, 3 3), (0 0, 1 1))>
|
| overlaps(self, other)
| Return True if geometries overlap, else False.
|
| point_on_surface(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `representative_point`.
|
| project(self, other, normalized=False)
| 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`.
|
| relate(self, other)
| Return the DE-9IM intersection matrix for the two geometries (string).
|
| relate_pattern(self, other, pattern)
| Return True if the DE-9IM relationship code satisfies the pattern.
|
| representative_point(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `point_on_surface`.
|
| reverse(self)
| Return a copy of this geometry with the order of coordinates reversed.
|
| If the geometry is a polygon with interior rings, the interior rings are also
| reversed.
|
| Points are unchanged.
|
| See Also
| --------
| is_ccw : Checks if a geometry is clockwise.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (1, 2)]).reverse()
| <LINESTRING (1 2, 0 0)>
| >>> Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]).reverse()
| <POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
|
| segmentize(self, max_segment_length)
| 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.
|
| Parameters
| ----------
| max_segment_length : float or array_like
| Additional vertices will be added so that all line segments are no
| longer this value. Must be greater than 0.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (0, 10)]).segmentize(max_segment_length=5)
| <LINESTRING (0 0, 0 5, 0 10)>
| >>> Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]).segmentize(max_segment_length=5)
| <POLYGON ((0 0, 5 0, 10 0, 10 5, 10 10, 5 10, 0 10, 0 5, 0 0))>
|
| simplify(self, tolerance, preserve_topology=True)
| 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.
|
| symmetric_difference(self, other, grid_size=None)
| Return the symmetric difference of the geometries.
|
| Refer to `shapely.symmetric_difference` for full documentation.
|
| touches(self, other)
| Return True if geometries touch, else False.
|
| union(self, other, grid_size=None)
| Return the union of the geometries.
|
| Refer to `shapely.union` for full documentation.
|
| within(self, other)
| Return True if geometry is within the other, else False.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from shapely.geometry.base.BaseGeometry:
|
| area
| Unitless area of the geometry (float).
|
| 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.
|
| bounds
| Return minimum bounding region (minx, miny, maxx, maxy).
|
| centroid
| Return the geometric center of the object.
|
| 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.
|
| envelope
| A figure that envelopes the geometry.
|
| geom_type
| Name of the geometry's type, such as 'Point'.
|
| has_m
| True if the geometry's coordinate sequence(s) have m values.
|
| has_z
| True if the geometry's coordinate sequence(s) have z values.
|
| is_closed
| True if the geometry is closed, else False.
|
| Applicable only to linear geometries.
|
| is_empty
| True if the set of points in this geometry is empty, else False.
|
| is_ring
| True if the geometry is a closed ring, else False.
|
| is_simple
| True if the geometry is simple.
|
| Simple means that any self-intersections are only at boundary points.
|
| is_valid
| True if the geometry is valid.
|
| The definition depends on sub-class.
|
| length
| Unitless length of the geometry (float).
|
| minimum_clearance
| Unitless distance a node can be moved to produce an invalid geometry (float).
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `oriented_envelope`.
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `minimum_rotated_rectangle`.
|
| type
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| wkb
| WKB representation of the geometry.
|
| wkb_hex
| WKB hex representation of the geometry.
|
| wkt
| WKT representation of the geometry.
|
| xy
| Separate arrays of X and Y coordinate values.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.lib.Geometry:
|
| __ge__(self, value, /)
| Return self>=value.
|
| __gt__(self, value, /)
| Return self>value.
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __setstate__(...)
| For unpickling pre-shapely 2.0 pickles
class MultiPoint(shapely.geometry.base.BaseMultipartGeometry)
| MultiPoint(points=None)
|
| A collection of one or more Points.
|
| A MultiPoint has zero area and zero length.
|
| Parameters
| ----------
| points : sequence
| A sequence of Points, or a sequence of (x, y [,z]) numeric coordinate
| pairs or triples, or an array-like of shape (N, 2) or (N, 3).
|
| Attributes
| ----------
| geoms : sequence
| A sequence of Points
|
| Examples
| --------
| Construct a MultiPoint containing two Points
|
| >>> from shapely import MultiPoint, Point
| >>> ob = MultiPoint([[0.0, 0.0], [1.0, 2.0]])
| >>> len(ob.geoms)
| 2
| >>> type(ob.geoms[0]) == Point
| True
|
| Method resolution order:
| MultiPoint
| shapely.geometry.base.BaseMultipartGeometry
| shapely.geometry.base.BaseGeometry
| shapely.lib.Geometry
| builtins.object
|
| Methods defined here:
|
| svg(self, scale_factor=1.0, fill_color=None, opacity=None)
| Return a group of SVG circle elements for the MultiPoint geometry.
|
| Parameters
| ----------
| scale_factor : float
| Multiplication factor for the SVG circle diameters. Default is 1.
| fill_color : str, optional
| Hex string for fill color. Default is to use "#66cc99" if
| geometry is valid, and "#ff3333" if invalid.
| opacity : float
| Float number between 0 and 1 for color opacity. Default value is 0.6
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(self, points=None)
| Create a new MultiPoint geometry.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __geo_interface__
| Return a GeoJSON-like mapping interface for this MultiPoint.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.geometry.base.BaseMultipartGeometry:
|
| __bool__(self)
| Return True if the geometry is not empty, else False.
|
| __eq__(self, other)
| Return True if geometries are equal, else False.
|
| __hash__(self)
| Return the hash value of the geometry.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from shapely.geometry.base.BaseMultipartGeometry:
|
| coords
| Not implemented.
|
| Sub-geometries may have coordinate sequences, but multi-part geometries
| do not.
|
| geoms
| Access to the contained geometries.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.geometry.base.BaseGeometry:
|
| __and__(self, other)
| Return the intersection of the geometries.
|
| __format__(self, format_spec)
| Format a geometry using a format specification.
|
| __nonzero__(self)
| Return True if the geometry is not empty, else False.
|
| __or__(self, other)
| Return the union of the geometries.
|
| __reduce__(self)
| Pickle support.
|
| __repr__(self)
| Return a string representation of the geometry.
|
| __str__(self)
| Return a string representation of the geometry.
|
| __sub__(self, other)
| Return the difference of the geometries.
|
| __xor__(self, other)
| Return the symmetric difference of the geometries.
|
| buffer(self, 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.
| quad_segs : int, optional
| Sets the number of line segments used to approximate an
| angle fillet.
| cap_style : shapely.BufferCapStyle or {'round', 'square', 'flat'}, 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 {'round', 'mitre', 'bevel'}, 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_sided : 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, resolution : int, optional
| Deprecated aliases for `quad_segs`.
| **kwargs : dict, optional
| For backwards compatibility of renamed parameters. If an unsupported
| kwarg is passed, a `ValueError` will be raised.
|
| Returns
| -------
| Geometry
|
| Notes
| -----
| The return value is a strictly two-dimensional geometry. All
| Z coordinates of the original geometry will be ignored.
|
| .. deprecated:: 2.1.0
| A deprecation warning is shown if ``quad_segs``, ``cap_style``,
| ``join_style``, ``mitre_limit`` or ``single_sided`` are
| specified as positional arguments. In a future release, these will
| need to be specified as keyword arguments.
|
| Examples
| --------
| >>> from shapely import BufferCapStyle
| >>> 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.1365484905459398
|
| 128-gon approximation:
|
| >>> g.buffer(1.0, 128).area
| 3.1415138011443013
|
| triangle approximation:
|
| >>> g.buffer(1.0, 3).area
| 3.0
| >>> list(g.buffer(1.0, cap_style=BufferCapStyle.square).exterior.coords)
| [(1.0, 1.0), (1.0, -1.0), (-1.0, -1.0), (-1.0, 1.0), (1.0, 1.0)]
| >>> g.buffer(1.0, cap_style=BufferCapStyle.square).area
| 4.0
|
| contains(self, other)
| Return True if the geometry contains the other, else False.
|
| contains_properly(self, other)
| Return True if the geometry completely contains the other.
|
| There should be no common boundary points.
|
| Refer to `shapely.contains_properly` for full documentation.
|
| covered_by(self, other)
| Return True if the geometry is covered by the other, else False.
|
| covers(self, other)
| Return True if the geometry covers the other, else False.
|
| crosses(self, other)
| Return True if the geometries cross, else False.
|
| difference(self, other, grid_size=None)
| Return the difference of the geometries.
|
| Refer to `shapely.difference` for full documentation.
|
| disjoint(self, other)
| Return True if geometries are disjoint, else False.
|
| distance(self, other)
| Unitless distance to other geometry (float).
|
| dwithin(self, other, distance)
| Return True if geometry is within a given distance from the other.
|
| Refer to `shapely.dwithin` for full documentation.
|
| equals(self, other)
| 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)).
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals(
| ... LineString([(0, 0), (1, 1), (2, 2)])
| ... )
| True
|
| Returns
| -------
| bool
|
| equals_exact(self, other, tolerance=0.0, *, normalize=False)
| Return True if the geometries are equivalent within the tolerance.
|
| Refer to :func:`~shapely.equals_exact` for full documentation.
|
| Parameters
| ----------
| other : BaseGeometry
| The other geometry object in this comparison.
| tolerance : float, optional (default: 0.)
| Absolute tolerance in the same units as coordinates.
| normalize : bool, optional (default: False)
| If True, normalize the two geometries so that the coordinates are
| in the same order.
|
| .. versionadded:: 2.1.0
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals_exact(
| ... LineString([(0, 0), (1, 1), (2, 2)]),
| ... 1e-6
| ... )
| False
|
| Returns
| -------
| bool
|
| geometryType(self)
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| hausdorff_distance(self, other)
| Unitless hausdorff distance to other geometry (float).
|
| interpolate(self, distance, normalized=False)
| 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`.
|
| intersection(self, other, grid_size=None)
| Return the intersection of the geometries.
|
| Refer to `shapely.intersection` for full documentation.
|
| intersects(self, other)
| Return True if geometries intersect, else False.
|
| line_interpolate_point(self, distance, normalized=False)
| 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`.
|
| line_locate_point(self, other, normalized=False)
| 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`.
|
| normalize(self)
| 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`).
|
| Examples
| --------
| >>> from shapely import MultiLineString
| >>> line = MultiLineString([[(0, 0), (1, 1)], [(3, 3), (2, 2)]])
| >>> line.normalize()
| <MULTILINESTRING ((2 2, 3 3), (0 0, 1 1))>
|
| overlaps(self, other)
| Return True if geometries overlap, else False.
|
| point_on_surface(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `representative_point`.
|
| project(self, other, normalized=False)
| 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`.
|
| relate(self, other)
| Return the DE-9IM intersection matrix for the two geometries (string).
|
| relate_pattern(self, other, pattern)
| Return True if the DE-9IM relationship code satisfies the pattern.
|
| representative_point(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `point_on_surface`.
|
| reverse(self)
| Return a copy of this geometry with the order of coordinates reversed.
|
| If the geometry is a polygon with interior rings, the interior rings are also
| reversed.
|
| Points are unchanged.
|
| See Also
| --------
| is_ccw : Checks if a geometry is clockwise.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (1, 2)]).reverse()
| <LINESTRING (1 2, 0 0)>
| >>> Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]).reverse()
| <POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
|
| segmentize(self, max_segment_length)
| 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.
|
| Parameters
| ----------
| max_segment_length : float or array_like
| Additional vertices will be added so that all line segments are no
| longer this value. Must be greater than 0.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (0, 10)]).segmentize(max_segment_length=5)
| <LINESTRING (0 0, 0 5, 0 10)>
| >>> Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]).segmentize(max_segment_length=5)
| <POLYGON ((0 0, 5 0, 10 0, 10 5, 10 10, 5 10, 0 10, 0 5, 0 0))>
|
| simplify(self, tolerance, preserve_topology=True)
| 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.
|
| symmetric_difference(self, other, grid_size=None)
| Return the symmetric difference of the geometries.
|
| Refer to `shapely.symmetric_difference` for full documentation.
|
| touches(self, other)
| Return True if geometries touch, else False.
|
| union(self, other, grid_size=None)
| Return the union of the geometries.
|
| Refer to `shapely.union` for full documentation.
|
| within(self, other)
| Return True if geometry is within the other, else False.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from shapely.geometry.base.BaseGeometry:
|
| area
| Unitless area of the geometry (float).
|
| 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.
|
| bounds
| Return minimum bounding region (minx, miny, maxx, maxy).
|
| centroid
| Return the geometric center of the object.
|
| 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.
|
| envelope
| A figure that envelopes the geometry.
|
| geom_type
| Name of the geometry's type, such as 'Point'.
|
| has_m
| True if the geometry's coordinate sequence(s) have m values.
|
| has_z
| True if the geometry's coordinate sequence(s) have z values.
|
| is_closed
| True if the geometry is closed, else False.
|
| Applicable only to linear geometries.
|
| is_empty
| True if the set of points in this geometry is empty, else False.
|
| is_ring
| True if the geometry is a closed ring, else False.
|
| is_simple
| True if the geometry is simple.
|
| Simple means that any self-intersections are only at boundary points.
|
| is_valid
| True if the geometry is valid.
|
| The definition depends on sub-class.
|
| length
| Unitless length of the geometry (float).
|
| minimum_clearance
| Unitless distance a node can be moved to produce an invalid geometry (float).
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `oriented_envelope`.
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `minimum_rotated_rectangle`.
|
| type
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| wkb
| WKB representation of the geometry.
|
| wkb_hex
| WKB hex representation of the geometry.
|
| wkt
| WKT representation of the geometry.
|
| xy
| Separate arrays of X and Y coordinate values.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.lib.Geometry:
|
| __ge__(self, value, /)
| Return self>=value.
|
| __gt__(self, value, /)
| Return self>value.
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __setstate__(...)
| For unpickling pre-shapely 2.0 pickles
class MultiPolygon(shapely.geometry.base.BaseMultipartGeometry)
| MultiPolygon(polygons=None)
|
| A collection of one or more Polygons.
|
| If component polygons overlap the collection is invalid and some
| operations on it may fail.
|
| Parameters
| ----------
| polygons : sequence
| A sequence of Polygons, or a sequence of (shell, holes) tuples
| where shell is the sequence representation of a linear ring
| (see LinearRing) and holes is a sequence of such linear rings.
|
| Attributes
| ----------
| geoms : sequence
| A sequence of `Polygon` instances
|
| Examples
| --------
| Construct a MultiPolygon from a sequence of coordinate tuples
|
| >>> from shapely import MultiPolygon, Polygon
| >>> ob = MultiPolygon([
| ... (
| ... ((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)),
| ... [((0.1,0.1), (0.1,0.2), (0.2,0.2), (0.2,0.1))]
| ... )
| ... ])
| >>> len(ob.geoms)
| 1
| >>> type(ob.geoms[0]) == Polygon
| True
|
| Method resolution order:
| MultiPolygon
| shapely.geometry.base.BaseMultipartGeometry
| shapely.geometry.base.BaseGeometry
| shapely.lib.Geometry
| builtins.object
|
| Methods defined here:
|
| svg(self, scale_factor=1.0, fill_color=None, opacity=None)
| Return group of SVG path elements for the MultiPolygon geometry.
|
| Parameters
| ----------
| scale_factor : float
| Multiplication factor for the SVG stroke-width. Default is 1.
| fill_color : str, optional
| Hex string for fill color. Default is to use "#66cc99" if
| geometry is valid, and "#ff3333" if invalid.
| opacity : float
| Float number between 0 and 1 for color opacity. Default value is 0.6
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(self, polygons=None)
| Create a new MultiPolygon geometry.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __geo_interface__
| Return a GeoJSON-like mapping of the MultiPolygon geometry.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.geometry.base.BaseMultipartGeometry:
|
| __bool__(self)
| Return True if the geometry is not empty, else False.
|
| __eq__(self, other)
| Return True if geometries are equal, else False.
|
| __hash__(self)
| Return the hash value of the geometry.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from shapely.geometry.base.BaseMultipartGeometry:
|
| coords
| Not implemented.
|
| Sub-geometries may have coordinate sequences, but multi-part geometries
| do not.
|
| geoms
| Access to the contained geometries.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.geometry.base.BaseGeometry:
|
| __and__(self, other)
| Return the intersection of the geometries.
|
| __format__(self, format_spec)
| Format a geometry using a format specification.
|
| __nonzero__(self)
| Return True if the geometry is not empty, else False.
|
| __or__(self, other)
| Return the union of the geometries.
|
| __reduce__(self)
| Pickle support.
|
| __repr__(self)
| Return a string representation of the geometry.
|
| __str__(self)
| Return a string representation of the geometry.
|
| __sub__(self, other)
| Return the difference of the geometries.
|
| __xor__(self, other)
| Return the symmetric difference of the geometries.
|
| buffer(self, 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.
| quad_segs : int, optional
| Sets the number of line segments used to approximate an
| angle fillet.
| cap_style : shapely.BufferCapStyle or {'round', 'square', 'flat'}, 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 {'round', 'mitre', 'bevel'}, 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_sided : 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, resolution : int, optional
| Deprecated aliases for `quad_segs`.
| **kwargs : dict, optional
| For backwards compatibility of renamed parameters. If an unsupported
| kwarg is passed, a `ValueError` will be raised.
|
| Returns
| -------
| Geometry
|
| Notes
| -----
| The return value is a strictly two-dimensional geometry. All
| Z coordinates of the original geometry will be ignored.
|
| .. deprecated:: 2.1.0
| A deprecation warning is shown if ``quad_segs``, ``cap_style``,
| ``join_style``, ``mitre_limit`` or ``single_sided`` are
| specified as positional arguments. In a future release, these will
| need to be specified as keyword arguments.
|
| Examples
| --------
| >>> from shapely import BufferCapStyle
| >>> 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.1365484905459398
|
| 128-gon approximation:
|
| >>> g.buffer(1.0, 128).area
| 3.1415138011443013
|
| triangle approximation:
|
| >>> g.buffer(1.0, 3).area
| 3.0
| >>> list(g.buffer(1.0, cap_style=BufferCapStyle.square).exterior.coords)
| [(1.0, 1.0), (1.0, -1.0), (-1.0, -1.0), (-1.0, 1.0), (1.0, 1.0)]
| >>> g.buffer(1.0, cap_style=BufferCapStyle.square).area
| 4.0
|
| contains(self, other)
| Return True if the geometry contains the other, else False.
|
| contains_properly(self, other)
| Return True if the geometry completely contains the other.
|
| There should be no common boundary points.
|
| Refer to `shapely.contains_properly` for full documentation.
|
| covered_by(self, other)
| Return True if the geometry is covered by the other, else False.
|
| covers(self, other)
| Return True if the geometry covers the other, else False.
|
| crosses(self, other)
| Return True if the geometries cross, else False.
|
| difference(self, other, grid_size=None)
| Return the difference of the geometries.
|
| Refer to `shapely.difference` for full documentation.
|
| disjoint(self, other)
| Return True if geometries are disjoint, else False.
|
| distance(self, other)
| Unitless distance to other geometry (float).
|
| dwithin(self, other, distance)
| Return True if geometry is within a given distance from the other.
|
| Refer to `shapely.dwithin` for full documentation.
|
| equals(self, other)
| 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)).
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals(
| ... LineString([(0, 0), (1, 1), (2, 2)])
| ... )
| True
|
| Returns
| -------
| bool
|
| equals_exact(self, other, tolerance=0.0, *, normalize=False)
| Return True if the geometries are equivalent within the tolerance.
|
| Refer to :func:`~shapely.equals_exact` for full documentation.
|
| Parameters
| ----------
| other : BaseGeometry
| The other geometry object in this comparison.
| tolerance : float, optional (default: 0.)
| Absolute tolerance in the same units as coordinates.
| normalize : bool, optional (default: False)
| If True, normalize the two geometries so that the coordinates are
| in the same order.
|
| .. versionadded:: 2.1.0
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals_exact(
| ... LineString([(0, 0), (1, 1), (2, 2)]),
| ... 1e-6
| ... )
| False
|
| Returns
| -------
| bool
|
| geometryType(self)
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| hausdorff_distance(self, other)
| Unitless hausdorff distance to other geometry (float).
|
| interpolate(self, distance, normalized=False)
| 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`.
|
| intersection(self, other, grid_size=None)
| Return the intersection of the geometries.
|
| Refer to `shapely.intersection` for full documentation.
|
| intersects(self, other)
| Return True if geometries intersect, else False.
|
| line_interpolate_point(self, distance, normalized=False)
| 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`.
|
| line_locate_point(self, other, normalized=False)
| 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`.
|
| normalize(self)
| 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`).
|
| Examples
| --------
| >>> from shapely import MultiLineString
| >>> line = MultiLineString([[(0, 0), (1, 1)], [(3, 3), (2, 2)]])
| >>> line.normalize()
| <MULTILINESTRING ((2 2, 3 3), (0 0, 1 1))>
|
| overlaps(self, other)
| Return True if geometries overlap, else False.
|
| point_on_surface(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `representative_point`.
|
| project(self, other, normalized=False)
| 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`.
|
| relate(self, other)
| Return the DE-9IM intersection matrix for the two geometries (string).
|
| relate_pattern(self, other, pattern)
| Return True if the DE-9IM relationship code satisfies the pattern.
|
| representative_point(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `point_on_surface`.
|
| reverse(self)
| Return a copy of this geometry with the order of coordinates reversed.
|
| If the geometry is a polygon with interior rings, the interior rings are also
| reversed.
|
| Points are unchanged.
|
| See Also
| --------
| is_ccw : Checks if a geometry is clockwise.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (1, 2)]).reverse()
| <LINESTRING (1 2, 0 0)>
| >>> Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]).reverse()
| <POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
|
| segmentize(self, max_segment_length)
| 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.
|
| Parameters
| ----------
| max_segment_length : float or array_like
| Additional vertices will be added so that all line segments are no
| longer this value. Must be greater than 0.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (0, 10)]).segmentize(max_segment_length=5)
| <LINESTRING (0 0, 0 5, 0 10)>
| >>> Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]).segmentize(max_segment_length=5)
| <POLYGON ((0 0, 5 0, 10 0, 10 5, 10 10, 5 10, 0 10, 0 5, 0 0))>
|
| simplify(self, tolerance, preserve_topology=True)
| 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.
|
| symmetric_difference(self, other, grid_size=None)
| Return the symmetric difference of the geometries.
|
| Refer to `shapely.symmetric_difference` for full documentation.
|
| touches(self, other)
| Return True if geometries touch, else False.
|
| union(self, other, grid_size=None)
| Return the union of the geometries.
|
| Refer to `shapely.union` for full documentation.
|
| within(self, other)
| Return True if geometry is within the other, else False.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from shapely.geometry.base.BaseGeometry:
|
| area
| Unitless area of the geometry (float).
|
| 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.
|
| bounds
| Return minimum bounding region (minx, miny, maxx, maxy).
|
| centroid
| Return the geometric center of the object.
|
| 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.
|
| envelope
| A figure that envelopes the geometry.
|
| geom_type
| Name of the geometry's type, such as 'Point'.
|
| has_m
| True if the geometry's coordinate sequence(s) have m values.
|
| has_z
| True if the geometry's coordinate sequence(s) have z values.
|
| is_closed
| True if the geometry is closed, else False.
|
| Applicable only to linear geometries.
|
| is_empty
| True if the set of points in this geometry is empty, else False.
|
| is_ring
| True if the geometry is a closed ring, else False.
|
| is_simple
| True if the geometry is simple.
|
| Simple means that any self-intersections are only at boundary points.
|
| is_valid
| True if the geometry is valid.
|
| The definition depends on sub-class.
|
| length
| Unitless length of the geometry (float).
|
| minimum_clearance
| Unitless distance a node can be moved to produce an invalid geometry (float).
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `oriented_envelope`.
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `minimum_rotated_rectangle`.
|
| type
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| wkb
| WKB representation of the geometry.
|
| wkb_hex
| WKB hex representation of the geometry.
|
| wkt
| WKT representation of the geometry.
|
| xy
| Separate arrays of X and Y coordinate values.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.lib.Geometry:
|
| __ge__(self, value, /)
| Return self>=value.
|
| __gt__(self, value, /)
| Return self>value.
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __setstate__(...)
| For unpickling pre-shapely 2.0 pickles
class Point(shapely.geometry.base.BaseGeometry)
| Point(*args)
|
| A geometry type that represents a single coordinate.
|
| Each coordinate has x, y and possibly z and/or m values.
|
| A point is a zero-dimensional feature and has zero length and zero area.
|
| Parameters
| ----------
| args : float, or sequence of floats
| The coordinates can either be passed as a single parameter, or as
| individual float values using multiple parameters:
|
| 1) 1 parameter: a sequence or array-like of with 2 or 3 values.
| 2) 2 or 3 parameters (float): x, y, and possibly z.
|
| Attributes
| ----------
| x, y, z, m : float
| Coordinate values
|
| Examples
| --------
| Constructing the Point using separate parameters for x and y:
|
| >>> from shapely import Point
| >>> p = Point(1.0, -1.0)
|
| Constructing the Point using a list of x, y coordinates:
|
| >>> p = Point([1.0, -1.0])
| >>> print(p)
| POINT (1 -1)
| >>> p.y
| -1.0
| >>> p.x
| 1.0
|
| Method resolution order:
| Point
| shapely.geometry.base.BaseGeometry
| shapely.lib.Geometry
| builtins.object
|
| Methods defined here:
|
| svg(self, scale_factor=1.0, fill_color=None, opacity=None)
| Return SVG circle element for the Point geometry.
|
| Parameters
| ----------
| scale_factor : float
| Multiplication factor for the SVG circle diameter. Default is 1.
| fill_color : str, optional
| Hex string for fill color. Default is to use "#66cc99" if
| geometry is valid, and "#ff3333" if invalid.
| opacity : float
| Float number between 0 and 1 for color opacity. Default value is 0.6
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(self, *args)
| Create a new Point geometry.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __geo_interface__
| Return a GeoJSON-like mapping of the Point geometry.
|
| m
| Return m coordinate.
|
| .. versionadded:: 2.1.0
| Also requires GEOS 3.12.0 or later.
|
| x
| Return x coordinate.
|
| xy
| Separate arrays of X and Y coordinate values.
|
| Examples
| --------
| >>> from shapely import Point
| >>> x, y = Point(0, 0).xy
| >>> list(x)
| [0.0]
| >>> list(y)
| [0.0]
|
| y
| Return y coordinate.
|
| z
| Return z coordinate.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.geometry.base.BaseGeometry:
|
| __and__(self, other)
| Return the intersection of the geometries.
|
| __bool__(self)
| Return True if the geometry is not empty, else False.
|
| __format__(self, format_spec)
| Format a geometry using a format specification.
|
| __nonzero__(self)
| Return True if the geometry is not empty, else False.
|
| __or__(self, other)
| Return the union of the geometries.
|
| __reduce__(self)
| Pickle support.
|
| __repr__(self)
| Return a string representation of the geometry.
|
| __str__(self)
| Return a string representation of the geometry.
|
| __sub__(self, other)
| Return the difference of the geometries.
|
| __xor__(self, other)
| Return the symmetric difference of the geometries.
|
| buffer(self, 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.
| quad_segs : int, optional
| Sets the number of line segments used to approximate an
| angle fillet.
| cap_style : shapely.BufferCapStyle or {'round', 'square', 'flat'}, 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 {'round', 'mitre', 'bevel'}, 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_sided : 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, resolution : int, optional
| Deprecated aliases for `quad_segs`.
| **kwargs : dict, optional
| For backwards compatibility of renamed parameters. If an unsupported
| kwarg is passed, a `ValueError` will be raised.
|
| Returns
| -------
| Geometry
|
| Notes
| -----
| The return value is a strictly two-dimensional geometry. All
| Z coordinates of the original geometry will be ignored.
|
| .. deprecated:: 2.1.0
| A deprecation warning is shown if ``quad_segs``, ``cap_style``,
| ``join_style``, ``mitre_limit`` or ``single_sided`` are
| specified as positional arguments. In a future release, these will
| need to be specified as keyword arguments.
|
| Examples
| --------
| >>> from shapely import BufferCapStyle
| >>> 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.1365484905459398
|
| 128-gon approximation:
|
| >>> g.buffer(1.0, 128).area
| 3.1415138011443013
|
| triangle approximation:
|
| >>> g.buffer(1.0, 3).area
| 3.0
| >>> list(g.buffer(1.0, cap_style=BufferCapStyle.square).exterior.coords)
| [(1.0, 1.0), (1.0, -1.0), (-1.0, -1.0), (-1.0, 1.0), (1.0, 1.0)]
| >>> g.buffer(1.0, cap_style=BufferCapStyle.square).area
| 4.0
|
| contains(self, other)
| Return True if the geometry contains the other, else False.
|
| contains_properly(self, other)
| Return True if the geometry completely contains the other.
|
| There should be no common boundary points.
|
| Refer to `shapely.contains_properly` for full documentation.
|
| covered_by(self, other)
| Return True if the geometry is covered by the other, else False.
|
| covers(self, other)
| Return True if the geometry covers the other, else False.
|
| crosses(self, other)
| Return True if the geometries cross, else False.
|
| difference(self, other, grid_size=None)
| Return the difference of the geometries.
|
| Refer to `shapely.difference` for full documentation.
|
| disjoint(self, other)
| Return True if geometries are disjoint, else False.
|
| distance(self, other)
| Unitless distance to other geometry (float).
|
| dwithin(self, other, distance)
| Return True if geometry is within a given distance from the other.
|
| Refer to `shapely.dwithin` for full documentation.
|
| equals(self, other)
| 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)).
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals(
| ... LineString([(0, 0), (1, 1), (2, 2)])
| ... )
| True
|
| Returns
| -------
| bool
|
| equals_exact(self, other, tolerance=0.0, *, normalize=False)
| Return True if the geometries are equivalent within the tolerance.
|
| Refer to :func:`~shapely.equals_exact` for full documentation.
|
| Parameters
| ----------
| other : BaseGeometry
| The other geometry object in this comparison.
| tolerance : float, optional (default: 0.)
| Absolute tolerance in the same units as coordinates.
| normalize : bool, optional (default: False)
| If True, normalize the two geometries so that the coordinates are
| in the same order.
|
| .. versionadded:: 2.1.0
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals_exact(
| ... LineString([(0, 0), (1, 1), (2, 2)]),
| ... 1e-6
| ... )
| False
|
| Returns
| -------
| bool
|
| geometryType(self)
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| hausdorff_distance(self, other)
| Unitless hausdorff distance to other geometry (float).
|
| interpolate(self, distance, normalized=False)
| 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`.
|
| intersection(self, other, grid_size=None)
| Return the intersection of the geometries.
|
| Refer to `shapely.intersection` for full documentation.
|
| intersects(self, other)
| Return True if geometries intersect, else False.
|
| line_interpolate_point(self, distance, normalized=False)
| 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`.
|
| line_locate_point(self, other, normalized=False)
| 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`.
|
| normalize(self)
| 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`).
|
| Examples
| --------
| >>> from shapely import MultiLineString
| >>> line = MultiLineString([[(0, 0), (1, 1)], [(3, 3), (2, 2)]])
| >>> line.normalize()
| <MULTILINESTRING ((2 2, 3 3), (0 0, 1 1))>
|
| overlaps(self, other)
| Return True if geometries overlap, else False.
|
| point_on_surface(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `representative_point`.
|
| project(self, other, normalized=False)
| 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`.
|
| relate(self, other)
| Return the DE-9IM intersection matrix for the two geometries (string).
|
| relate_pattern(self, other, pattern)
| Return True if the DE-9IM relationship code satisfies the pattern.
|
| representative_point(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `point_on_surface`.
|
| reverse(self)
| Return a copy of this geometry with the order of coordinates reversed.
|
| If the geometry is a polygon with interior rings, the interior rings are also
| reversed.
|
| Points are unchanged.
|
| See Also
| --------
| is_ccw : Checks if a geometry is clockwise.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (1, 2)]).reverse()
| <LINESTRING (1 2, 0 0)>
| >>> Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]).reverse()
| <POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
|
| segmentize(self, max_segment_length)
| 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.
|
| Parameters
| ----------
| max_segment_length : float or array_like
| Additional vertices will be added so that all line segments are no
| longer this value. Must be greater than 0.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (0, 10)]).segmentize(max_segment_length=5)
| <LINESTRING (0 0, 0 5, 0 10)>
| >>> Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]).segmentize(max_segment_length=5)
| <POLYGON ((0 0, 5 0, 10 0, 10 5, 10 10, 5 10, 0 10, 0 5, 0 0))>
|
| simplify(self, tolerance, preserve_topology=True)
| 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.
|
| symmetric_difference(self, other, grid_size=None)
| Return the symmetric difference of the geometries.
|
| Refer to `shapely.symmetric_difference` for full documentation.
|
| touches(self, other)
| Return True if geometries touch, else False.
|
| union(self, other, grid_size=None)
| Return the union of the geometries.
|
| Refer to `shapely.union` for full documentation.
|
| within(self, other)
| Return True if geometry is within the other, else False.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from shapely.geometry.base.BaseGeometry:
|
| area
| Unitless area of the geometry (float).
|
| 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.
|
| bounds
| Return minimum bounding region (minx, miny, maxx, maxy).
|
| centroid
| Return the geometric center of the object.
|
| 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.
|
| coords
| Access to geometry's coordinates (CoordinateSequence).
|
| envelope
| A figure that envelopes the geometry.
|
| geom_type
| Name of the geometry's type, such as 'Point'.
|
| has_m
| True if the geometry's coordinate sequence(s) have m values.
|
| has_z
| True if the geometry's coordinate sequence(s) have z values.
|
| is_closed
| True if the geometry is closed, else False.
|
| Applicable only to linear geometries.
|
| is_empty
| True if the set of points in this geometry is empty, else False.
|
| is_ring
| True if the geometry is a closed ring, else False.
|
| is_simple
| True if the geometry is simple.
|
| Simple means that any self-intersections are only at boundary points.
|
| is_valid
| True if the geometry is valid.
|
| The definition depends on sub-class.
|
| length
| Unitless length of the geometry (float).
|
| minimum_clearance
| Unitless distance a node can be moved to produce an invalid geometry (float).
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `oriented_envelope`.
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `minimum_rotated_rectangle`.
|
| type
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| wkb
| WKB representation of the geometry.
|
| wkb_hex
| WKB hex representation of the geometry.
|
| wkt
| WKT representation of the geometry.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.lib.Geometry:
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __setstate__(...)
| For unpickling pre-shapely 2.0 pickles
class Polygon(shapely.geometry.base.BaseGeometry)
| Polygon(shell=None, holes=None)
|
| 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
|
| Attributes
| ----------
| exterior : LinearRing
| The ring which bounds the positive space of the polygon.
| interiors : sequence
| A sequence of rings which bound all existing holes.
|
| Examples
| --------
| Create a square polygon with no holes
|
| >>> from shapely import Polygon
| >>> coords = ((0., 0.), (0., 1.), (1., 1.), (1., 0.), (0., 0.))
| >>> polygon = Polygon(coords)
| >>> polygon.area
| 1.0
|
| Method resolution order:
| Polygon
| shapely.geometry.base.BaseGeometry
| shapely.lib.Geometry
| builtins.object
|
| Methods defined here:
|
| svg(self, scale_factor=1.0, fill_color=None, opacity=None)
| Return SVG path element for the Polygon geometry.
|
| Parameters
| ----------
| scale_factor : float
| Multiplication factor for the SVG stroke-width. Default is 1.
| fill_color : str, optional
| Hex string for fill color. Default is to use "#66cc99" if
| geometry is valid, and "#ff3333" if invalid.
| opacity : float
| Float number between 0 and 1 for color opacity. Default value is 0.6
|
| ----------------------------------------------------------------------
| Class methods defined here:
|
| from_bounds(xmin, ymin, xmax, ymax)
| Construct a `Polygon()` from spatial bounds.
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(self, shell=None, holes=None)
| Create a new Polygon geometry.
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| __geo_interface__
| Return a GeoJSON-like mapping of the Polygon geometry.
|
| coords
| Not implemented for polygons.
|
| exterior
| Return the exterior ring of the polygon.
|
| interiors
| Return the sequence of interior rings of the polygon.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.geometry.base.BaseGeometry:
|
| __and__(self, other)
| Return the intersection of the geometries.
|
| __bool__(self)
| Return True if the geometry is not empty, else False.
|
| __format__(self, format_spec)
| Format a geometry using a format specification.
|
| __nonzero__(self)
| Return True if the geometry is not empty, else False.
|
| __or__(self, other)
| Return the union of the geometries.
|
| __reduce__(self)
| Pickle support.
|
| __repr__(self)
| Return a string representation of the geometry.
|
| __str__(self)
| Return a string representation of the geometry.
|
| __sub__(self, other)
| Return the difference of the geometries.
|
| __xor__(self, other)
| Return the symmetric difference of the geometries.
|
| buffer(self, 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.
| quad_segs : int, optional
| Sets the number of line segments used to approximate an
| angle fillet.
| cap_style : shapely.BufferCapStyle or {'round', 'square', 'flat'}, 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 {'round', 'mitre', 'bevel'}, 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_sided : 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, resolution : int, optional
| Deprecated aliases for `quad_segs`.
| **kwargs : dict, optional
| For backwards compatibility of renamed parameters. If an unsupported
| kwarg is passed, a `ValueError` will be raised.
|
| Returns
| -------
| Geometry
|
| Notes
| -----
| The return value is a strictly two-dimensional geometry. All
| Z coordinates of the original geometry will be ignored.
|
| .. deprecated:: 2.1.0
| A deprecation warning is shown if ``quad_segs``, ``cap_style``,
| ``join_style``, ``mitre_limit`` or ``single_sided`` are
| specified as positional arguments. In a future release, these will
| need to be specified as keyword arguments.
|
| Examples
| --------
| >>> from shapely import BufferCapStyle
| >>> 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.1365484905459398
|
| 128-gon approximation:
|
| >>> g.buffer(1.0, 128).area
| 3.1415138011443013
|
| triangle approximation:
|
| >>> g.buffer(1.0, 3).area
| 3.0
| >>> list(g.buffer(1.0, cap_style=BufferCapStyle.square).exterior.coords)
| [(1.0, 1.0), (1.0, -1.0), (-1.0, -1.0), (-1.0, 1.0), (1.0, 1.0)]
| >>> g.buffer(1.0, cap_style=BufferCapStyle.square).area
| 4.0
|
| contains(self, other)
| Return True if the geometry contains the other, else False.
|
| contains_properly(self, other)
| Return True if the geometry completely contains the other.
|
| There should be no common boundary points.
|
| Refer to `shapely.contains_properly` for full documentation.
|
| covered_by(self, other)
| Return True if the geometry is covered by the other, else False.
|
| covers(self, other)
| Return True if the geometry covers the other, else False.
|
| crosses(self, other)
| Return True if the geometries cross, else False.
|
| difference(self, other, grid_size=None)
| Return the difference of the geometries.
|
| Refer to `shapely.difference` for full documentation.
|
| disjoint(self, other)
| Return True if geometries are disjoint, else False.
|
| distance(self, other)
| Unitless distance to other geometry (float).
|
| dwithin(self, other, distance)
| Return True if geometry is within a given distance from the other.
|
| Refer to `shapely.dwithin` for full documentation.
|
| equals(self, other)
| 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)).
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals(
| ... LineString([(0, 0), (1, 1), (2, 2)])
| ... )
| True
|
| Returns
| -------
| bool
|
| equals_exact(self, other, tolerance=0.0, *, normalize=False)
| Return True if the geometries are equivalent within the tolerance.
|
| Refer to :func:`~shapely.equals_exact` for full documentation.
|
| Parameters
| ----------
| other : BaseGeometry
| The other geometry object in this comparison.
| tolerance : float, optional (default: 0.)
| Absolute tolerance in the same units as coordinates.
| normalize : bool, optional (default: False)
| If True, normalize the two geometries so that the coordinates are
| in the same order.
|
| .. versionadded:: 2.1.0
|
| Examples
| --------
| >>> from shapely import LineString
| >>> LineString(
| ... [(0, 0), (2, 2)]
| ... ).equals_exact(
| ... LineString([(0, 0), (1, 1), (2, 2)]),
| ... 1e-6
| ... )
| False
|
| Returns
| -------
| bool
|
| geometryType(self)
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| hausdorff_distance(self, other)
| Unitless hausdorff distance to other geometry (float).
|
| interpolate(self, distance, normalized=False)
| 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`.
|
| intersection(self, other, grid_size=None)
| Return the intersection of the geometries.
|
| Refer to `shapely.intersection` for full documentation.
|
| intersects(self, other)
| Return True if geometries intersect, else False.
|
| line_interpolate_point(self, distance, normalized=False)
| 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`.
|
| line_locate_point(self, other, normalized=False)
| 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`.
|
| normalize(self)
| 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`).
|
| Examples
| --------
| >>> from shapely import MultiLineString
| >>> line = MultiLineString([[(0, 0), (1, 1)], [(3, 3), (2, 2)]])
| >>> line.normalize()
| <MULTILINESTRING ((2 2, 3 3), (0 0, 1 1))>
|
| overlaps(self, other)
| Return True if geometries overlap, else False.
|
| point_on_surface(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `representative_point`.
|
| project(self, other, normalized=False)
| 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`.
|
| relate(self, other)
| Return the DE-9IM intersection matrix for the two geometries (string).
|
| relate_pattern(self, other, pattern)
| Return True if the DE-9IM relationship code satisfies the pattern.
|
| representative_point(self)
| Return a point guaranteed to be within the object, cheaply.
|
| Alias of `point_on_surface`.
|
| reverse(self)
| Return a copy of this geometry with the order of coordinates reversed.
|
| If the geometry is a polygon with interior rings, the interior rings are also
| reversed.
|
| Points are unchanged.
|
| See Also
| --------
| is_ccw : Checks if a geometry is clockwise.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (1, 2)]).reverse()
| <LINESTRING (1 2, 0 0)>
| >>> Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]).reverse()
| <POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
|
| segmentize(self, max_segment_length)
| 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.
|
| Parameters
| ----------
| max_segment_length : float or array_like
| Additional vertices will be added so that all line segments are no
| longer this value. Must be greater than 0.
|
| Examples
| --------
| >>> from shapely import LineString, Polygon
| >>> LineString([(0, 0), (0, 10)]).segmentize(max_segment_length=5)
| <LINESTRING (0 0, 0 5, 0 10)>
| >>> Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]).segmentize(max_segment_length=5)
| <POLYGON ((0 0, 5 0, 10 0, 10 5, 10 10, 5 10, 0 10, 0 5, 0 0))>
|
| simplify(self, tolerance, preserve_topology=True)
| 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.
|
| symmetric_difference(self, other, grid_size=None)
| Return the symmetric difference of the geometries.
|
| Refer to `shapely.symmetric_difference` for full documentation.
|
| touches(self, other)
| Return True if geometries touch, else False.
|
| union(self, other, grid_size=None)
| Return the union of the geometries.
|
| Refer to `shapely.union` for full documentation.
|
| within(self, other)
| Return True if geometry is within the other, else False.
|
| ----------------------------------------------------------------------
| Readonly properties inherited from shapely.geometry.base.BaseGeometry:
|
| area
| Unitless area of the geometry (float).
|
| 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.
|
| bounds
| Return minimum bounding region (minx, miny, maxx, maxy).
|
| centroid
| Return the geometric center of the object.
|
| 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.
|
| envelope
| A figure that envelopes the geometry.
|
| geom_type
| Name of the geometry's type, such as 'Point'.
|
| has_m
| True if the geometry's coordinate sequence(s) have m values.
|
| has_z
| True if the geometry's coordinate sequence(s) have z values.
|
| is_closed
| True if the geometry is closed, else False.
|
| Applicable only to linear geometries.
|
| is_empty
| True if the set of points in this geometry is empty, else False.
|
| is_ring
| True if the geometry is a closed ring, else False.
|
| is_simple
| True if the geometry is simple.
|
| Simple means that any self-intersections are only at boundary points.
|
| is_valid
| True if the geometry is valid.
|
| The definition depends on sub-class.
|
| length
| Unitless length of the geometry (float).
|
| minimum_clearance
| Unitless distance a node can be moved to produce an invalid geometry (float).
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `oriented_envelope`.
|
| 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
| :func:`~shapely.normalize` to reorganize the rectangle to
| :ref:`strict canonical form <canonical-form>` so the starting point is
| always the lower left point.
|
| Alias of `minimum_rotated_rectangle`.
|
| type
| Get the geometry type (deprecated).
|
| .. deprecated:: 2.0
| Use the :py:attr:`geom_type` attribute instead.
|
| wkb
| WKB representation of the geometry.
|
| wkb_hex
| WKB hex representation of the geometry.
|
| wkt
| WKT representation of the geometry.
|
| xy
| Separate arrays of X and Y coordinate values.
|
| ----------------------------------------------------------------------
| Methods inherited from shapely.lib.Geometry:
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __setstate__(...)
| For unpickling pre-shapely 2.0 pickles
FUNCTIONS
box(minx, miny, maxx, maxy, ccw=True)
Return a rectangular polygon with configurable normal vector.
mapping(ob)
Return a GeoJSON-like mapping.
Input should be a Geometry or an object which implements __geo_interface__.
Parameters
----------
ob : geometry or object
An object which implements __geo_interface__.
Returns
-------
dict
Examples
--------
>>> from shapely.geometry import mapping, Point
>>> pt = Point(0, 0)
>>> mapping(pt)
{'type': 'Point', 'coordinates': (0.0, 0.0)}
shape(context)
Return a new, independent geometry with coordinates copied from the context.
Changes to the original context will not be reflected in the geometry
object.
Parameters
----------
context :
a GeoJSON-like dict, which provides a "type" member describing the type
of the geometry and "coordinates" member providing a list of coordinates,
or an object which implements __geo_interface__.
Returns
-------
Geometry object
Examples
--------
Create a Point from GeoJSON, and then create a copy using __geo_interface__.
>>> from shapely.geometry import shape
>>> context = {'type': 'Point', 'coordinates': [0, 1]}
>>> geom = shape(context)
>>> geom.geom_type == 'Point'
True
>>> geom.wkt
'POINT (0 1)'
>>> geom2 = shape(geom)
>>> geom == geom2
True
DATA
__all__ = ['CAP_STYLE', 'JOIN_STYLE', 'GeometryCollection', 'LineStrin...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\shapely\geometry\__init__.py
shapely.geometrycollections
Python Library Documentation: function geometrycollections in module shapely.creation
geometrycollections(geometries, indices=None, out=None, **kwargs)
Create geometrycollections from arrays of geometries.
Parameters
----------
geometries : array_like
An array of geometries.
indices : array_like, optional
Indices into the target array where input geometries belong. If
provided, both geometries and indices should be 1D and have matching
sizes. Indices should be in increasing order. Missing indices result
in a ValueError unless ``out`` is provided, in which case the original
value in ``out`` is kept.
out : ndarray, optional
An array (with dtype object) to output the geometries into.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Ignored if ``indices`` is provided.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``indices`` is specified as a
positional argument. This will need to be specified as a keyword
argument in a future release.
See Also
--------
multipoints
shapely.geos_capi_version
Python Library Documentation: tuple object class tuple(object) | tuple(iterable=(), /) | | Built-in immutable sequence. | | If no argument is given, the constructor returns an empty tuple. | If iterable is specified the tuple is initialized from iterable's items. | | If the argument is a tuple, the return value is the same object. | | Built-in subclasses: | asyncgen_hooks | UnraisableHookArgs | | Methods defined here: | | __add__(self, value, /) | Return self+value. | | __contains__(self, key, /) | Return bool(key in self). | | __eq__(self, value, /) | Return self==value. | | __ge__(self, value, /) | Return self>=value. | | __getattribute__(self, name, /) | Return getattr(self, name). | | __getitem__(self, key, /) | Return self[key]. | | __getnewargs__(self, /) | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __iter__(self, /) | Implement iter(self). | | __le__(self, value, /) | Return self<=value. | | __len__(self, /) | Return len(self). | | __lt__(self, value, /) | Return self<value. | | __mul__(self, value, /) | Return self*value. | | __ne__(self, value, /) | Return self!=value. | | __repr__(self, /) | Return repr(self). | | __rmul__(self, value, /) | Return value*self. | | count(self, value, /) | Return number of occurrences of value. | | index(self, value, start=0, stop=9223372036854775807, /) | Return first index of value. | | Raises ValueError if the value is not present. | | ---------------------------------------------------------------------- | Class methods defined here: | | __class_getitem__(...) | See PEP 585 | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature.
shapely.geos_capi_version_string
Error rendering doc: No Python documentation found for '3.13.1-CAPI-1.19.2'. Use help() to get the interactive help utility. Use help(str) for help on the str class.
shapely.geos_version
Python Library Documentation: tuple object class tuple(object) | tuple(iterable=(), /) | | Built-in immutable sequence. | | If no argument is given, the constructor returns an empty tuple. | If iterable is specified the tuple is initialized from iterable's items. | | If the argument is a tuple, the return value is the same object. | | Built-in subclasses: | asyncgen_hooks | UnraisableHookArgs | | Methods defined here: | | __add__(self, value, /) | Return self+value. | | __contains__(self, key, /) | Return bool(key in self). | | __eq__(self, value, /) | Return self==value. | | __ge__(self, value, /) | Return self>=value. | | __getattribute__(self, name, /) | Return getattr(self, name). | | __getitem__(self, key, /) | Return self[key]. | | __getnewargs__(self, /) | | __gt__(self, value, /) | Return self>value. | | __hash__(self, /) | Return hash(self). | | __iter__(self, /) | Implement iter(self). | | __le__(self, value, /) | Return self<=value. | | __len__(self, /) | Return len(self). | | __lt__(self, value, /) | Return self<value. | | __mul__(self, value, /) | Return self*value. | | __ne__(self, value, /) | Return self!=value. | | __repr__(self, /) | Return repr(self). | | __rmul__(self, value, /) | Return value*self. | | count(self, value, /) | Return number of occurrences of value. | | index(self, value, start=0, stop=9223372036854775807, /) | Return first index of value. | | Raises ValueError if the value is not present. | | ---------------------------------------------------------------------- | Class methods defined here: | | __class_getitem__(...) | See PEP 585 | | ---------------------------------------------------------------------- | Static methods defined here: | | __new__(*args, **kwargs) | Create and return a new object. See help(type) for accurate signature.
shapely.geos_version_string
Error rendering doc: No Python documentation found for '3.13.1'. Use help() to get the interactive help utility. Use help(str) for help on the str class.
shapely.get_coordinate_dimension
Python Library Documentation: function get_coordinate_dimension in module shapely._geometry
get_coordinate_dimension(geometry, **kwargs)
Return the dimensionality of the coordinates in a geometry (2, 3 or 4).
The return value can be one of the following:
* Return 2 for geometries with XY coordinate types,
* Return 3 for XYZ or XYM coordinate types
(distinguished by :meth:`has_z` or :meth:`has_m`),
* Return 4 for XYZM coordinate types,
* Return -1 for missing geometries (``None`` values).
Note that with GEOS < 3.12, if the first Z coordinate equals ``nan``, this function
will return ``2``. Geometries with M coordinates are supported with GEOS >= 3.12.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to get the coordinate dimension of.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import Point
>>> shapely.get_coordinate_dimension(Point(0, 0))
2
>>> shapely.get_coordinate_dimension(Point(0, 0, 1))
3
>>> shapely.get_coordinate_dimension(None)
-1
shapely.get_coordinates
Python Library Documentation: function get_coordinates in module shapely.coordinates
get_coordinates(geometry, include_z=False, return_index=False, *, include_m=False)
Get coordinates from a geometry array as an array of floats.
The shape of the returned array is (N, 2), with N being the number of
coordinate pairs. The shape of the data may also be (N, 3) or (N, 4),
depending on ``include_z`` and ``include_m`` options.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to get the coordinates of.
include_z, include_m : bool, default False
If both are False, return XY (2D) geometries.
If both are True, return XYZM (4D) geometries.
If either are True, return XYZ or XYM (3D) geometries.
If a geometry has no Z or M dimension, extra coordinate data will be NaN.
.. versionadded:: 2.1.0
The ``include_m`` parameter was added to support XYM (3D) and
XYZM (4D) geometries available with GEOS 3.12.0 or later.
With older GEOS versions, M dimension coordinates will be NaN.
return_index : bool, default False
If True, also return the index of each returned geometry as a separate
ndarray of integers. For multidimensional arrays, this indexes into the
flattened array (in C contiguous order).
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``include_z`` or ``return_index`` are
specified as positional arguments. In a future release, these will
need to be specified as keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> shapely.get_coordinates(Point(1, 2)).tolist()
[[1.0, 2.0]]
>>> shapely.get_coordinates(LineString([(2, 2), (4, 4)])).tolist()
[[2.0, 2.0], [4.0, 4.0]]
>>> shapely.get_coordinates(None)
array([], shape=(0, 2), dtype=float64)
By default the third dimension is ignored:
>>> shapely.get_coordinates(Point(1, 2, 3)).tolist()
[[1.0, 2.0]]
>>> shapely.get_coordinates(Point(1, 2, 3), include_z=True).tolist()
[[1.0, 2.0, 3.0]]
If geometries don't have Z or M dimension, these values will be NaN:
>>> pt = Point(1, 2)
>>> shapely.get_coordinates(pt, include_z=True).tolist()
[[1.0, 2.0, nan]]
>>> shapely.get_coordinates(pt, include_z=True, include_m=True).tolist()
[[1.0, 2.0, nan, nan]]
When ``return_index=True``, indexes are returned also:
>>> geometries = [LineString([(2, 2), (4, 4)]), Point(0, 0)]
>>> coordinates, index = shapely.get_coordinates(geometries, return_index=True)
>>> coordinates.tolist(), index.tolist()
([[2.0, 2.0], [4.0, 4.0], [0.0, 0.0]], [0, 0, 1])
shapely.get_dimensions
Python Library Documentation: function get_dimensions in module shapely._geometry
get_dimensions(geometry, **kwargs)
Return the inherent dimensionality of a geometry.
The inherent dimension is 0 for points, 1 for linestrings and linearrings,
and 2 for polygons. For geometrycollections it is the max of the containing
elements. Empty collections and None values return -1.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to get the dimensionality of.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, Point, Polygon
>>> point = Point(0, 0)
>>> shapely.get_dimensions(point)
0
>>> polygon = Polygon([(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)])
>>> shapely.get_dimensions(polygon)
2
>>> shapely.get_dimensions(GeometryCollection([point, polygon]))
2
>>> shapely.get_dimensions(GeometryCollection([]))
-1
>>> shapely.get_dimensions(None)
-1
shapely.get_exterior_ring
Python Library Documentation: function get_exterior_ring in module shapely._geometry
get_exterior_ring(geometry, **kwargs)
Return the exterior ring of a polygon.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to get the exterior ring of.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
get_interior_ring
Examples
--------
>>> import shapely
>>> from shapely import Point, Polygon
>>> shapely.get_exterior_ring(Polygon([(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)]))
<LINEARRING (0 0, 0 10, 10 10, 10 0, 0 0)>
>>> shapely.get_exterior_ring(Point(1, 1)) is None
True
shapely.get_geometry
Python Library Documentation: function get_geometry in module shapely._geometry
get_geometry(geometry, index, **kwargs)
Return the nth geometry from a collection of geometries.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to get the nth geometry of.
index : int or array_like
Negative values count from the end of the collection backwards.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
- simple geometries act as length-1 collections
- out-of-range values return None
See Also
--------
get_num_geometries, get_parts
Examples
--------
>>> import shapely
>>> from shapely import Point, MultiPoint
>>> multipoint = MultiPoint([(0, 0), (1, 1), (2, 2), (3, 3)])
>>> shapely.get_geometry(multipoint, 1)
<POINT (1 1)>
>>> shapely.get_geometry(multipoint, -1)
<POINT (3 3)>
>>> shapely.get_geometry(multipoint, 5) is None
True
>>> shapely.get_geometry(Point(1, 1), 0)
<POINT (1 1)>
>>> shapely.get_geometry(Point(1, 1), 1) is None
True
shapely.get_interior_ring
Python Library Documentation: function get_interior_ring in module shapely._geometry
get_interior_ring(geometry, index, **kwargs)
Return the nth interior ring of a polygon.
The number of interior rings in non-polygons equals zero.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to get the interior ring of.
index : int or array_like
Negative values count from the end of the interior rings backwards.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
get_exterior_ring
get_num_interior_rings
Examples
--------
>>> import shapely
>>> from shapely import Point, Polygon
>>> polygon_with_hole = Polygon(
... [(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)],
... holes=[[(2, 2), (2, 4), (4, 4), (4, 2), (2, 2)]]
... )
>>> shapely.get_interior_ring(polygon_with_hole, 0)
<LINEARRING (2 2, 2 4, 4 4, 4 2, 2 2)>
>>> shapely.get_interior_ring(polygon_with_hole, 1) is None
True
>>> polygon = Polygon([(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)])
>>> shapely.get_interior_ring(polygon, 0) is None
True
>>> shapely.get_interior_ring(Point(0, 0), 0) is None
True
shapely.get_m
Python Library Documentation: function get_m in module shapely._geometry
get_m(point, **kwargs)
Return the m-coordinate of a point.
.. versionadded:: 2.1.0
Parameters
----------
point : Geometry or array_like
Non-point geometries or geometries without M dimension will result
in NaN being returned.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
get_x, get_y, get_z
Examples
--------
>>> import shapely
>>> from shapely import Point, from_wkt
>>> shapely.get_m(from_wkt("POINT ZM (1 2 3 4)"))
4.0
>>> shapely.get_m(from_wkt("POINT M (1 2 4)"))
4.0
>>> shapely.get_m(Point(1, 2, 3))
nan
>>> shapely.get_m(from_wkt("MULTIPOINT M ((1 1 1), (2 2 2))"))
nan
shapely.get_num_coordinates
Python Library Documentation: function get_num_coordinates in module shapely._geometry
get_num_coordinates(geometry, **kwargs)
Return the total number of coordinates in a geometry.
Returns 0 for not-a-geometry values.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to get the number of coordinates of.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, LineString, Point
>>> point = Point(0, 0)
>>> shapely.get_num_coordinates(point)
1
>>> shapely.get_num_coordinates(Point(0, 0, 0))
1
>>> line = LineString([(0, 0), (1, 1)])
>>> shapely.get_num_coordinates(line)
2
>>> shapely.get_num_coordinates(GeometryCollection([point, line]))
3
>>> shapely.get_num_coordinates(None)
0
shapely.get_num_geometries
Python Library Documentation: function get_num_geometries in module shapely._geometry
get_num_geometries(geometry, **kwargs)
Return number of geometries in a collection.
Returns 0 for not-a-geometry values. The number of geometries in points,
linestrings, linearrings and polygons equals one.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to get the number of geometries of.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
get_num_points
get_geometry
Examples
--------
>>> import shapely
>>> from shapely import MultiPoint, Point
>>> shapely.get_num_geometries(MultiPoint([(0, 0), (1, 1), (2, 2), (3, 3)]))
4
>>> shapely.get_num_geometries(Point(1, 1))
1
>>> shapely.get_num_geometries(None)
0
shapely.get_num_interior_rings
Python Library Documentation: function get_num_interior_rings in module shapely._geometry
get_num_interior_rings(geometry, **kwargs)
Return number of internal rings in a polygon.
Returns 0 for not-a-geometry values.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to get the number of interior rings of.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
get_exterior_ring
get_interior_ring
Examples
--------
>>> import shapely
>>> from shapely import Point, Polygon
>>> polygon = Polygon([(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)])
>>> shapely.get_num_interior_rings(polygon)
0
>>> polygon_with_hole = Polygon(
... [(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)],
... holes=[[(2, 2), (2, 4), (4, 4), (4, 2), (2, 2)]]
... )
>>> shapely.get_num_interior_rings(polygon_with_hole)
1
>>> shapely.get_num_interior_rings(Point(0, 0))
0
>>> shapely.get_num_interior_rings(None)
0
shapely.get_num_points
Python Library Documentation: function get_num_points in module shapely._geometry
get_num_points(geometry, **kwargs)
Return the number of points in a linestring or linearring.
Returns 0 for not-a-geometry values. The number of points in geometries
other than linestring or linearring equals zero.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to get the number of points of.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
get_point
get_num_geometries
Examples
--------
>>> import shapely
>>> from shapely import LineString, MultiPoint
>>> shapely.get_num_points(LineString([(0, 0), (1, 1), (2, 2), (3, 3)]))
4
>>> shapely.get_num_points(MultiPoint([(0, 0), (1, 1), (2, 2), (3, 3)]))
0
>>> shapely.get_num_points(None)
0
shapely.get_parts
Python Library Documentation: function get_parts in module shapely._geometry
get_parts(geometry, return_index=False)
Get parts of each GeometryCollection or Multi* geometry object.
A copy of each geometry in the GeometryCollection or Multi* geometry object
is returned.
Note: This does not return the individual parts of Multi* geometry objects
in a GeometryCollection. You may need to call this function multiple times
to return individual parts of Multi* geometry objects in a
GeometryCollection.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to get the parts of.
return_index : bool, default False
If True, will return a tuple of ndarrays of (parts, indexes), where
indexes are the indexes of the original geometries in the source array.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``return_index`` is specified as
a positional argument. This will need to be specified as a keyword
argument in a future release.
Returns
-------
ndarray of parts or tuple of (parts, indexes)
See Also
--------
get_geometry, get_rings
Examples
--------
>>> import shapely
>>> from shapely import MultiPoint
>>> shapely.get_parts(MultiPoint([(0, 1), (2, 3)])).tolist()
[<POINT (0 1)>, <POINT (2 3)>]
>>> parts, index = shapely.get_parts([MultiPoint([(0, 1)]), MultiPoint([(4, 5), (6, 7)])], return_index=True)
>>> parts.tolist()
[<POINT (0 1)>, <POINT (4 5)>, <POINT (6 7)>]
>>> index.tolist()
[0, 1, 1]
shapely.get_point
Python Library Documentation: function get_point in module shapely._geometry
get_point(geometry, index, **kwargs)
Return the nth point of a linestring or linearring.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to get the point of.
index : int or array_like
Negative values count from the end of the linestring backwards.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
get_num_points
Examples
--------
>>> import shapely
>>> from shapely import LinearRing, LineString, MultiPoint, Point
>>> line = LineString([(0, 0), (1, 1), (2, 2), (3, 3)])
>>> shapely.get_point(line, 1)
<POINT (1 1)>
>>> shapely.get_point(line, -2)
<POINT (2 2)>
>>> shapely.get_point(line, [0, 3]).tolist()
[<POINT (0 0)>, <POINT (3 3)>]
The function works the same for LinearRing input:
>>> shapely.get_point(LinearRing([(0, 0), (1, 1), (2, 2), (0, 0)]), 1)
<POINT (1 1)>
For non-linear geometries it returns None:
>>> shapely.get_point(MultiPoint([(0, 0), (1, 1), (2, 2), (3, 3)]), 1) is None
True
>>> shapely.get_point(Point(1, 1), 0) is None
True
shapely.get_precision
Python Library Documentation: function get_precision in module shapely._geometry
get_precision(geometry, **kwargs)
Get the precision of a geometry.
If a precision has not been previously set, it will be 0 (double
precision). Otherwise, it will return the precision grid size that was
set on a geometry.
Returns NaN for not-a-geometry values.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to get the precision of.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
set_precision
Examples
--------
>>> import shapely
>>> from shapely import Point
>>> point = Point(1, 1)
>>> shapely.get_precision(point)
0.0
>>> geometry = shapely.set_precision(point, 1.0)
>>> shapely.get_precision(geometry)
1.0
>>> shapely.get_precision(None)
nan
shapely.get_rings
Python Library Documentation: function get_rings in module shapely._geometry
get_rings(geometry, return_index=False)
Get rings of Polygon geometry object.
For each Polygon, the first returned ring is always the exterior ring
and potential subsequent rings are interior rings.
If the geometry is not a Polygon, nothing is returned (empty array for
scalar geometry input or no element in output array for array input).
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to get the rings of.
return_index : bool, default False
If True, will return a tuple of ndarrays of (rings, indexes), where
indexes are the indexes of the original geometries in the source array.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``return_index`` is specified as
a positional argument. This will need to be specified as a keyword
argument in a future release.
Returns
-------
ndarray of rings or tuple of (rings, indexes)
See Also
--------
get_exterior_ring, get_interior_ring, get_parts
Examples
--------
>>> import shapely
>>> from shapely import Polygon
>>> polygon_with_hole = Polygon(
... [(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)],
... holes=[[(2, 2), (2, 4), (4, 4), (4, 2), (2, 2)]]
... )
>>> shapely.get_rings(polygon_with_hole).tolist()
[<LINEARRING (0 0, 0 10, 10 10, 10 0, 0 0)>,
<LINEARRING (2 2, 2 4, 4 4, 4 2, 2 2)>]
With ``return_index=True``:
>>> polygon = Polygon([(0, 0), (2, 0), (2, 2), (0, 2), (0, 0)])
>>> rings, index = shapely.get_rings(
... [polygon, polygon_with_hole],
... return_index=True
... )
>>> rings.tolist()
[<LINEARRING (0 0, 2 0, 2 2, 0 2, 0 0)>,
<LINEARRING (0 0, 0 10, 10 10, 10 0, 0 0)>,
<LINEARRING (2 2, 2 4, 4 4, 4 2, 2 2)>]
>>> index.tolist()
[0, 1, 1]
shapely.get_srid
Python Library Documentation: function get_srid in module shapely._geometry
get_srid(geometry, **kwargs)
Return the SRID of a geometry.
Returns -1 for not-a-geometry values.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to get the SRID of.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
set_srid
Examples
--------
>>> import shapely
>>> from shapely import Point
>>> point = Point(0, 0)
>>> shapely.get_srid(point)
0
>>> with_srid = shapely.set_srid(point, 4326)
>>> shapely.get_srid(with_srid)
4326
shapely.get_type_id
Python Library Documentation: function get_type_id in module shapely._geometry
get_type_id(geometry, **kwargs)
Return the type ID of a geometry.
Possible values are:
- None (missing) is -1
- POINT is 0
- LINESTRING is 1
- LINEARRING is 2
- POLYGON is 3
- MULTIPOINT is 4
- MULTILINESTRING is 5
- MULTIPOLYGON is 6
- GEOMETRYCOLLECTION is 7
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to get the type ID of.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
GeometryType
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> shapely.get_type_id(LineString([(0, 0), (1, 1), (2, 2), (3, 3)]))
1
>>> shapely.get_type_id([Point(1, 2), Point(2, 3)]).tolist()
[0, 0]
shapely.get_x
Python Library Documentation: function get_x in module shapely._geometry
get_x(point, **kwargs)
Return the x-coordinate of a point.
Parameters
----------
point : Geometry or array_like
Non-point geometries will result in NaN being returned.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
get_y, get_z, get_m
Examples
--------
>>> import shapely
>>> from shapely import MultiPoint, Point
>>> shapely.get_x(Point(1, 2))
1.0
>>> shapely.get_x(MultiPoint([(1, 1), (1, 2)]))
nan
shapely.get_y
Python Library Documentation: function get_y in module shapely._geometry
get_y(point, **kwargs)
Return the y-coordinate of a point.
Parameters
----------
point : Geometry or array_like
Non-point geometries will result in NaN being returned.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
get_x, get_z, get_m
Examples
--------
>>> import shapely
>>> from shapely import MultiPoint, Point
>>> shapely.get_y(Point(1, 2))
2.0
>>> shapely.get_y(MultiPoint([(1, 1), (1, 2)]))
nan
shapely.get_z
Python Library Documentation: function get_z in module shapely._geometry
get_z(point, **kwargs)
Return the z-coordinate of a point.
Parameters
----------
point : Geometry or array_like
Non-point geometries or geometries without Z dimension will result
in NaN being returned.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
get_x, get_y, get_m
Examples
--------
>>> import shapely
>>> from shapely import MultiPoint, Point
>>> shapely.get_z(Point(1, 2, 3))
3.0
>>> shapely.get_z(Point(1, 2))
nan
>>> shapely.get_z(MultiPoint([(1, 1, 1), (2, 2, 2)]))
nan
shapely.has_m
Python Library Documentation: function has_m in module shapely.predicates
has_m(geometry, **kwargs)
Return True if a geometry has M coordinates.
.. versionadded:: 2.1.0
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to check for M coordinates.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
get_coordinate_dimension, has_z
Examples
--------
>>> import shapely
>>> shapely.has_m(shapely.from_wkt("POINT (0 0)"))
False
>>> shapely.has_m(shapely.from_wkt("POINT Z (0 0 0)"))
False
>>> shapely.has_m(shapely.from_wkt("POINT M (0 0 0)"))
True
>>> shapely.has_m(shapely.from_wkt("POINT ZM (0 0 0 0)"))
True
shapely.has_z
Python Library Documentation: function has_z in module shapely.predicates
has_z(geometry, **kwargs)
Return True if a geometry has Z coordinates.
Note that for GEOS < 3.12 this function returns False if the (first) Z coordinate
equals NaN.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to check for Z coordinates.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
get_coordinate_dimension, has_m
Examples
--------
>>> import shapely
>>> from shapely import Point
>>> shapely.has_z(Point(0, 0))
False
>>> shapely.has_z(Point(0, 0, 0))
True
>>> shapely.has_z(Point())
False
shapely.hausdorff_distance
Python Library Documentation: function hausdorff_distance in module shapely.measurement
hausdorff_distance(a, b, densify=None, **kwargs)
Compute the discrete Hausdorff distance between two geometries.
The Hausdorff distance is a measure of similarity: it is the greatest
distance between any point in A and the closest point in B. The discrete
distance is an approximation of this metric: only vertices are considered.
The parameter 'densify' makes this approximation less coarse by splitting
the line segments between vertices before computing the distance.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to compute the distance between.
densify : float or array_like, optional
The value of densify is required to be between 0 and 1.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString
>>> line1 = LineString([(130, 0), (0, 0), (0, 150)])
>>> line2 = LineString([(10, 10), (10, 150), (130, 10)])
>>> shapely.hausdorff_distance(line1, line2)
14.142135623730951
>>> shapely.hausdorff_distance(line1, line2, densify=0.5)
70.0
>>> shapely.hausdorff_distance(line1, LineString())
nan
>>> shapely.hausdorff_distance(line1, None)
nan
shapely.intersection
Python Library Documentation: function intersection in module shapely.set_operations
intersection(a, b, grid_size=None, **kwargs)
Return the geometry that is shared between input geometries.
If grid_size is nonzero, input coordinates will be snapped to a precision
grid of that size and resulting coordinates will be snapped to that same
grid. If 0, this operation will use double precision coordinates. If None,
the highest precision of the inputs will be used, which may be previously
set using set_precision. Note: returned geometry does not have precision
set unless specified previously by set_precision.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to intersect with.
grid_size : float, optional
Precision grid size; will use the highest precision of the inputs by default.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``grid_size`` is specified as a
positional argument. This will need to be specified as a keyword
argument in a future release.
See Also
--------
intersection_all
set_precision
Examples
--------
>>> import shapely
>>> from shapely import LineString
>>> line = LineString([(0, 0), (2, 2)])
>>> shapely.intersection(line, LineString([(1, 1), (3, 3)]))
<LINESTRING (1 1, 2 2)>
>>> box1 = shapely.box(0, 0, 2, 2)
>>> box2 = shapely.box(1, 1, 3, 3)
>>> shapely.intersection(box1, box2).normalize()
<POLYGON ((1 1, 1 2, 2 2, 2 1, 1 1))>
>>> box1 = shapely.box(0.1, 0.2, 2.1, 2.1)
>>> shapely.intersection(box1, box2, grid_size=1)
<POLYGON ((2 2, 2 1, 1 1, 1 2, 2 2))>
shapely.intersection_all
Python Library Documentation: function intersection_all in module shapely.set_operations
intersection_all(geometries, axis=None, **kwargs)
Return the intersection of multiple geometries.
This function ignores None values when other Geometry elements are present.
If all elements of the given axis are None, an empty GeometryCollection is
returned.
Parameters
----------
geometries : array_like
Geometries to calculate the intersection of.
axis : int, optional
Axis along which the operation is performed. The default (None)
performs the operation over all axes, returning a scalar value.
Axis may be negative, in which case it counts from the last to the
first axis.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``axis`` is specified as a
positional argument. This will need to be specified as a keyword
argument in a future release.
See Also
--------
intersection
Examples
--------
>>> import shapely
>>> from shapely import LineString
>>> line1 = LineString([(0, 0), (2, 2)])
>>> line2 = LineString([(1, 1), (3, 3)])
>>> shapely.intersection_all([line1, line2])
<LINESTRING (1 1, 2 2)>
>>> shapely.intersection_all([[line1, line2, None]], axis=1).tolist()
[<LINESTRING (1 1, 2 2)>]
>>> shapely.intersection_all([line1, None])
<LINESTRING (0 0, 2 2)>
shapely.intersects
Python Library Documentation: function intersects in module shapely.predicates
intersects(a, b, **kwargs)
Return True if A and B share any portion of space.
Intersects implies that overlaps, touches, covers, or within are True.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
disjoint : ``intersects(A, B) == ~disjoint(A, B)``
prepare : improve performance by preparing ``a`` (the first argument)
intersects_xy : variant for checking against a Point with x, y coordinates
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> line = LineString([(0, 0), (1, 1)])
>>> shapely.intersects(line, Point(0, 0))
True
>>> shapely.intersects(line, Point(0, 1))
False
>>> shapely.intersects(line, LineString([(0, 2), (2, 0)]))
True
>>> shapely.intersects(None, None)
False
shapely.intersects_xy
Python Library Documentation: function intersects_xy in module shapely.predicates
intersects_xy(geom, x, y=None, **kwargs)
Return True if geom and the Point (x, y) share any portion of space.
This is a special-case (and faster) variant of the `intersects` function
which avoids having to create a Point object if you start from x/y
coordinates.
See the docstring of `intersects` for more details about the predicate.
Parameters
----------
geom : Geometry or array_like
Geometry or geometries to check if they intersect with the point.
x, y : float or array_like
Coordinates as separate x and y arrays, or a single array of
coordinate x, y tuples.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
intersects : variant taking two geometries as input
Notes
-----
If you compare a single or few geometries with many points, it can be
beneficial to prepare the geometries in advance using
:func:`shapely.prepare`.
The `touches` predicate can be determined with this function by getting
the boundary of the geometries: ``intersects_xy(boundary(geom), x, y)``.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> line = LineString([(0, 0), (1, 1)])
>>> shapely.intersects(line, Point(0, 0))
True
>>> shapely.intersects_xy(line, 0, 0)
True
shapely.io
Python Library Documentation: module shapely.io in shapely
NAME
shapely.io - Input/output functions for Shapely geometries.
FUNCTIONS
from_geojson(geometry, on_invalid='raise', **kwargs)
Create geometries from GeoJSON representations (strings).
If a GeoJSON is a FeatureCollection, it is read as a single geometry
(with type GEOMETRYCOLLECTION). This may be unpacked using
:meth:`shapely.get_parts`. Properties are not read.
The GeoJSON format is defined in `RFC 7946 <https://geojson.org/>`__.
The following are currently unsupported:
- Three-dimensional geometries: the third dimension is ignored.
- Geometries having 'null' in the coordinates.
Parameters
----------
geometry : str, bytes or array_like
The GeoJSON string or byte object(s) to convert.
on_invalid : {"raise", "warn", "ignore"}, default "raise"
- raise: an exception will be raised if an input GeoJSON is invalid.
- warn: a warning will be raised and invalid input geometries will be
returned as ``None``.
- ignore: invalid input geometries will be returned as ``None`` without
a warning.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
get_parts
Examples
--------
>>> import shapely
>>> shapely.from_geojson('{"type": "Point","coordinates": [1, 2]}')
<POINT (1 2)>
from_ragged_array(geometry_type, coords, offsets=None)
Create geometries from a contiguous array of coordinates and offset arrays.
This function creates geometries from the ragged array representation
as returned by ``to_ragged_array``.
This follows the in-memory layout of the variable size list arrays defined
by Apache Arrow, as specified for geometries by the GeoArrow project:
https://github.com/geoarrow/geoarrow.
See :func:`to_ragged_array` for more details.
Parameters
----------
geometry_type : GeometryType
The type of geometry to create.
coords : np.ndarray
Contiguous array of shape (n, 2) or (n, 3) of all coordinates
for the geometries.
offsets: tuple of np.ndarray
Offset arrays that allow to reconstruct the geometries based on the
flat coordinates array. The number of offset arrays depends on the
geometry type. See
https://github.com/geoarrow/geoarrow/blob/main/format.md for details.
Returns
-------
np.ndarray
Array of geometries (1-dimensional).
See Also
--------
to_ragged_array
from_wkb(geometry, on_invalid='raise', **kwargs)
Create geometries from the Well-Known Binary (WKB) representation.
The Well-Known Binary format is defined in the `OGC Simple Features
Specification for SQL <https://www.opengeospatial.org/standards/sfs>`__.
Parameters
----------
geometry : str or array_like
The WKB byte object(s) to convert.
on_invalid : {"raise", "warn", "ignore", "fix"}, default "raise"
Indicates what to do when an invalid WKB is encountered. Note that the
validations involved are very basic, e.g. the minimum number of points
for the geometry type. For a thorough check, use :func:`is_valid` after
conversion to geometries. Valid options are:
- raise: an exception will be raised if any input geometry is invalid.
- warn: a warning will be raised and invalid WKT geometries will be
returned as ``None``.
- ignore: invalid geometries will be returned as ``None`` without a
warning.
- fix: an effort is made to fix invalid input geometries (currently just
unclosed rings). If this is not possible, they are returned as
``None`` without a warning. Requires GEOS >= 3.11.
.. versionadded:: 2.1.0
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> shapely.from_wkb(b'\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0?')
<POINT (1 1)>
from_wkt(geometry, on_invalid='raise', **kwargs)
Create geometries from the Well-Known Text (WKT) representation.
The Well-known Text format is defined in the `OGC Simple Features
Specification for SQL <https://www.opengeospatial.org/standards/sfs>`__.
Parameters
----------
geometry : str or array_like
The WKT string(s) to convert.
on_invalid : {"raise", "warn", "ignore", "fix"}, default "raise"
Indicates what to do when an invalid WKT string is encountered. Note
that the validations involved are very basic, e.g. the minimum number of
points for the geometry type. For a thorough check, use
:func:`is_valid` after conversion to geometries. Valid options are:
- raise: an exception will be raised if any input geometry is invalid.
- warn: a warning will be raised and invalid WKT geometries will be
returned as ``None``.
- ignore: invalid geometries will be returned as ``None`` without a
warning.
- fix: an effort is made to fix invalid input geometries (currently just
unclosed rings). If this is not possible, they are returned as
``None`` without a warning. Requires GEOS >= 3.11.
.. versionadded:: 2.1.0
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> shapely.from_wkt('POINT (0 0)')
<POINT (0 0)>
to_geojson(geometry, indent=None, **kwargs)
Convert to the GeoJSON representation of a Geometry.
The GeoJSON format is defined in the `RFC 7946 <https://geojson.org/>`__.
NaN (not-a-number) coordinates will be written as 'null'.
The following are currently unsupported:
- Geometries of type LINEARRING: these are output as 'null'.
- Three-dimensional geometries: the third dimension is ignored.
Parameters
----------
geometry : str, bytes or array_like
Geometry or geometries to convert to GeoJSON.
indent : int, optional
If indent is a non-negative integer, then GeoJSON will be formatted.
An indent level of 0 will only insert newlines. None (the default)
selects the most compact representation.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import Point
>>> point = Point(1, 1)
>>> shapely.to_geojson(point)
'{"type":"Point","coordinates":[1.0,1.0]}'
>>> print(shapely.to_geojson(point, indent=2))
{
"type": "Point",
"coordinates": [
1.0,
1.0
]
}
to_ragged_array(geometries, include_z=None, include_m=None)
Convert geometries to a ragged array representation.
This function converts an array of geometries to a ragged array
(i.e. irregular array of arrays) of coordinates, represented in memory
using a single contiguous array of the coordinates, and
up to 3 offset arrays that keep track where each sub-array
starts and ends.
This follows the in-memory layout of the variable size list arrays defined
by Apache Arrow, as specified for geometries by the GeoArrow project:
https://github.com/geoarrow/geoarrow.
Parameters
----------
geometries : array_like
Array of geometries (1-dimensional).
include_z, include_m : bool, default None
If both are False, return XY (2D) geometries.
If both are True, return XYZM (4D) geometries.
If either is True, return either XYZ or XYM (3D) geometries.
If a geometry has no Z or M dimension, extra coordinate data will be NaN.
By default, will infer the dimensionality from the
input geometries. Note that this inference can be unreliable with
empty geometries (for a guaranteed result, it is recommended to
specify the keyword).
.. versionadded:: 2.1.0
The ``include_m`` parameter was added to support XYM (3D) and
XYZM (4D) geometries available with GEOS 3.12.0 or later.
With older GEOS versions, M dimension coordinates will be NaN.
Returns
-------
tuple of (geometry_type, coords, offsets)
geometry_type : GeometryType
The type of the input geometries (required information for
roundtrip).
coords : np.ndarray
Contiguous array of shape (n, 2), (n, 3), or (n, 4) of all
coordinates of all input geometries.
offsets: tuple of np.ndarray
Offset arrays that make it possible to reconstruct the
geometries from the flat coordinates array. The number of
offset arrays depends on the geometry type. See
https://github.com/geoarrow/geoarrow/blob/main/format.md
for details.
Uses int32 dtype offsets if possible, otherwise int64 for
large inputs (coordinates > 32GB).
Notes
-----
Mixed singular and multi geometry types of the same basic type are
allowed (e.g., Point and MultiPoint) and all singular types will be
treated as multi types.
GeometryCollections and other mixed geometry types are not supported.
See Also
--------
from_ragged_array
Examples
--------
Consider a Polygon with one hole (interior ring):
>>> import shapely
>>> from shapely import Polygon
>>> polygon = Polygon(
... [(0, 0), (10, 0), (10, 10), (0, 10)],
... holes=[[(2, 2), (3, 2), (2, 3)]]
... )
>>> polygon
<POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (2 2, 3 2, 2 3, 2 2))>
This polygon can be thought of as a list of rings (first ring is the
exterior ring, subsequent rings are the interior rings), and each ring
as a list of coordinate pairs. This is very similar to how GeoJSON
represents the coordinates:
>>> import json
>>> json.loads(shapely.to_geojson(polygon))["coordinates"]
[[[0.0, 0.0], [10.0, 0.0], [10.0, 10.0], [0.0, 10.0], [0.0, 0.0]],
[[2.0, 2.0], [3.0, 2.0], [2.0, 3.0], [2.0, 2.0]]]
This function will return a similar list of lists of lists, but
using a single contiguous array of coordinates, and multiple arrays of
offsets:
>>> geometry_type, coords, offsets = shapely.to_ragged_array([polygon])
>>> geometry_type
<GeometryType.POLYGON: 3>
>>> coords
array([[ 0., 0.],
[10., 0.],
[10., 10.],
[ 0., 10.],
[ 0., 0.],
[ 2., 2.],
[ 3., 2.],
[ 2., 3.],
[ 2., 2.]])
>>> offsets
(array([0, 5, 9], dtype=int32), array([0, 2], dtype=int32))
As an example how to interpret the offsets: the i-th ring in the
coordinates is represented by ``offsets[0][i]`` to ``offsets[0][i+1]``:
>>> exterior_ring_start, exterior_ring_end = offsets[0][0], offsets[0][1]
>>> coords[exterior_ring_start:exterior_ring_end]
array([[ 0., 0.],
[10., 0.],
[10., 10.],
[ 0., 10.],
[ 0., 0.]])
to_wkb(geometry, hex=False, output_dimension=None, byte_order=-1, include_srid=False, flavor='extended', **kwargs)
Convert to the Well-Known Binary (WKB) representation of a Geometry.
The Well-Known Binary format is defined in the `OGC Simple Features
Specification for SQL <https://www.opengeospatial.org/standards/sfs>`__.
The following limitations apply to WKB serialization:
- linearrings will be converted to linestrings
- a point with only NaN coordinates is converted to an empty point
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to convert to WKB.
hex : bool, default False
If true, export the WKB as a hexadecimal string. The default is to
return a binary bytes object.
output_dimension : int, default None
The output dimension for the WKB. Supported values are 2, 3 and 4 for
GEOS 3.12+. Default None will automatically choose 3 or 4, depending on
the version of GEOS.
Specifying 3 means that up to 3 dimensions will be written but 2D
geometries will still be represented as 2D in the WKB representation.
byte_order : int, default -1
Defaults to native machine byte order (-1). Use 0 to force big endian
and 1 for little endian.
include_srid : bool, default False
If True, the SRID is be included in WKB (this is an extension
to the OGC WKB specification). Not allowed when flavor is "iso".
flavor : {"iso", "extended"}, default "extended"
Which flavor of WKB will be returned. The flavor determines how
extra dimensionality is encoded with the type number, and whether
SRID can be included in the WKB. ISO flavor is "more standard" for
3D output, and does not support SRID embedding.
Both flavors are equivalent when ``output_dimension=2`` (or with 2D
geometries) and ``include_srid=False``.
The `from_wkb` function can read both flavors.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import Point
>>> point = Point(1, 1)
>>> shapely.to_wkb(point, byte_order=1)
b'\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0?'
>>> shapely.to_wkb(point, hex=True, byte_order=1)
'0101000000000000000000F03F000000000000F03F'
to_wkt(geometry, rounding_precision=6, trim=True, output_dimension=None, old_3d=False, **kwargs)
Convert to the Well-Known Text (WKT) representation of a Geometry.
The Well-known Text format is defined in the `OGC Simple Features
Specification for SQL <https://www.opengeospatial.org/standards/sfs>`__.
The following limitations apply to WKT serialization:
- only simple empty geometries can be 3D, empty collections are always 2D
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to convert to WKT.
rounding_precision : int, default 6
The rounding precision when writing the WKT string. Set to a value of
-1 to indicate the full precision.
trim : bool, default True
If True, trim unnecessary decimals (trailing zeros). If False,
use fixed-precision number formatting.
output_dimension : int, default None
The output dimension for the WKT string. Supported values are 2, 3 and
4 for GEOS 3.12+. Default None will automatically choose 3 or 4,
depending on the version of GEOS.
Specifying 3 means that up to 3 dimensions will be written but 2D
geometries will still be represented as 2D in the WKT string.
old_3d : bool, default False
Enable old style 3D/4D WKT generation. By default, new style 3D/4D WKT
(ie. "POINT Z (10 20 30)") is returned, but with ``old_3d=True``
the WKT will be formatted in the style "POINT (10 20 30)".
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import Point
>>> shapely.to_wkt(Point(0, 0))
'POINT (0 0)'
>>> shapely.to_wkt(Point(0, 0), rounding_precision=3, trim=False)
'POINT (0.000 0.000)'
>>> shapely.to_wkt(Point(0, 0), rounding_precision=-1, trim=False)
'POINT (0.0000000000000000 0.0000000000000000)'
>>> shapely.to_wkt(Point(1, 2, 3), trim=True)
'POINT Z (1 2 3)'
>>> shapely.to_wkt(Point(1, 2, 3), trim=True, output_dimension=2)
'POINT (1 2)'
>>> shapely.to_wkt(Point(1, 2, 3), trim=True, old_3d=True)
'POINT (1 2 3)'
Notes
-----
The defaults differ from the default of some GEOS versions. To mimic this for
versions before GEOS 3.12, use::
shapely.to_wkt(geometry, rounding_precision=-1, trim=False, output_dimension=2)
DATA
__all__ = ['from_geojson', 'from_ragged_array', 'from_wkb', 'from_wkt'...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\shapely\io.py
shapely.is_ccw
Python Library Documentation: function is_ccw in module shapely.predicates
is_ccw(geometry, **kwargs)
Return True if a linestring or linearring is counterclockwise.
Note that there are no checks on whether lines are actually closed and
not self-intersecting, while this is a requirement for is_ccw. The recommended
usage of this function for linestrings is ``is_ccw(g) & is_simple(g)`` and for
linearrings ``is_ccw(g) & is_valid(g)``.
Parameters
----------
geometry : Geometry or array_like
This function will return False for non-linear geometries and for
lines with fewer than 4 points (including the closing point).
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
is_simple : Checks if a linestring is closed and simple.
is_valid : Checks additionally if the geometry is simple.
Examples
--------
>>> import shapely
>>> from shapely import LinearRing, LineString, Point
>>> shapely.is_ccw(LinearRing([(0, 0), (0, 1), (1, 1), (0, 0)]))
False
>>> shapely.is_ccw(LinearRing([(0, 0), (1, 1), (0, 1), (0, 0)]))
True
>>> shapely.is_ccw(LineString([(0, 0), (1, 1), (0, 1)]))
False
>>> shapely.is_ccw(Point(0, 0))
False
shapely.is_closed
Python Library Documentation: function is_closed in module shapely.predicates
is_closed(geometry, **kwargs)
Return True if a linestring's first and last points are equal.
Parameters
----------
geometry : Geometry or array_like
This function will return False for non-linestrings.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
is_ring : Checks additionally if the geometry is simple.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> shapely.is_closed(LineString([(0, 0), (1, 1)]))
False
>>> shapely.is_closed(LineString([(0, 0), (0, 1), (1, 1), (0, 0)]))
True
>>> shapely.is_closed(Point(0, 0))
False
shapely.is_empty
Python Library Documentation: function is_empty in module shapely.predicates
is_empty(geometry, **kwargs)
Return True if a geometry is an empty point, polygon, etc.
Parameters
----------
geometry : Geometry or array_like
Any geometry type is accepted.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
is_missing : checks if the object is a geometry
Examples
--------
>>> import shapely
>>> from shapely import Point
>>> shapely.is_empty(Point())
True
>>> shapely.is_empty(Point(0, 0))
False
>>> shapely.is_empty(None)
False
shapely.is_geometry
Python Library Documentation: function is_geometry in module shapely.predicates
is_geometry(geometry, **kwargs)
Return True if the object is a geometry.
Parameters
----------
geometry : any object or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
is_missing : check if an object is missing (None)
is_valid_input : check if an object is a geometry or None
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, Point
>>> shapely.is_geometry(Point(0, 0))
True
>>> shapely.is_geometry(GeometryCollection())
True
>>> shapely.is_geometry(None)
False
>>> shapely.is_geometry("text")
False
shapely.is_missing
Python Library Documentation: function is_missing in module shapely.predicates
is_missing(geometry, **kwargs)
Return True if the object is not a geometry (None).
Parameters
----------
geometry : any object or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
is_geometry : check if an object is a geometry
is_valid_input : check if an object is a geometry or None
is_empty : checks if the object is an empty geometry
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, Point
>>> shapely.is_missing(Point(0, 0))
False
>>> shapely.is_missing(GeometryCollection())
False
>>> shapely.is_missing(None)
True
>>> shapely.is_missing("text")
False
shapely.is_prepared
Python Library Documentation: function is_prepared in module shapely.predicates
is_prepared(geometry, **kwargs)
Return True if a Geometry is prepared.
Note that it is not necessary to check if a geometry is already prepared
before preparing it. It is more efficient to call ``prepare`` directly
because it will skip geometries that are already prepared.
This function will return False for missing geometries (None).
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
is_valid_input : check if an object is a geometry or None
prepare : prepare a geometry
Examples
--------
>>> import shapely
>>> from shapely import Point
>>> geometry = Point(0, 0)
>>> shapely.is_prepared(Point(0, 0))
False
>>> shapely.prepare(geometry)
>>> shapely.is_prepared(geometry)
True
>>> shapely.is_prepared(None)
False
shapely.is_ring
Python Library Documentation: function is_ring in module shapely.predicates
is_ring(geometry, **kwargs)
Return True if a linestring is closed and simple.
This function will return False for non-linestrings.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
is_closed : Checks only if the geometry is closed.
is_simple : Checks only if the geometry is simple.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> shapely.is_ring(Point(0, 0))
False
>>> geom = LineString([(0, 0), (1, 1)])
>>> shapely.is_closed(geom), shapely.is_simple(geom), shapely.is_ring(geom)
(False, True, False)
>>> geom = LineString([(0, 0), (0, 1), (1, 1), (0, 0)])
>>> shapely.is_closed(geom), shapely.is_simple(geom), shapely.is_ring(geom)
(True, True, True)
>>> geom = LineString([(0, 0), (1, 1), (0, 1), (1, 0), (0, 0)])
>>> shapely.is_closed(geom), shapely.is_simple(geom), shapely.is_ring(geom)
(True, False, False)
shapely.is_simple
Python Library Documentation: function is_simple in module shapely.predicates
is_simple(geometry, **kwargs)
Return True if the geometry is simple.
A simple geometry has no anomalous geometric points, such as
self-intersections or self tangency.
Note that polygons and linearrings are assumed to be simple. Use is_valid
to check these kind of geometries for self-intersections.
This function will return False for geometrycollections.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
is_ring : Checks additionally if the geometry is closed.
is_valid : Checks whether a geometry is well formed.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Polygon
>>> shapely.is_simple(Polygon([(1, 1), (2, 1), (2, 2), (1, 1)]))
True
>>> shapely.is_simple(LineString([(0, 0), (1, 1), (0, 1), (1, 0), (0, 0)]))
False
>>> shapely.is_simple(None)
False
shapely.is_valid
Python Library Documentation: function is_valid in module shapely.predicates
is_valid(geometry, **kwargs)
Return True if a geometry is well formed.
Returns False for missing values.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to check. Any geometry type is accepted.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
is_valid_reason : Returns the reason in case of invalid.
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, LineString, Polygon
>>> shapely.is_valid(LineString([(0, 0), (1, 1)]))
True
>>> shapely.is_valid(Polygon([(0, 0), (1, 1), (1, 2), (1, 1), (0, 0)]))
False
>>> shapely.is_valid(GeometryCollection())
True
>>> shapely.is_valid(None)
False
shapely.is_valid_input
Python Library Documentation: function is_valid_input in module shapely.predicates
is_valid_input(geometry, **kwargs)
Return True if the object is a geometry or None.
Parameters
----------
geometry : any object or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
is_geometry : checks if an object is a geometry
is_missing : checks if an object is None
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, Point
>>> shapely.is_valid_input(Point(0, 0))
True
>>> shapely.is_valid_input(GeometryCollection())
True
>>> shapely.is_valid_input(None)
True
>>> shapely.is_valid_input(1.0)
False
>>> shapely.is_valid_input("text")
False
shapely.is_valid_reason
Python Library Documentation: function is_valid_reason in module shapely.predicates
is_valid_reason(geometry, **kwargs)
Return a string stating if a geometry is valid and if not, why.
Returns None for missing values.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to check. Any geometry type is accepted.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
is_valid : returns True or False
Examples
--------
>>> import shapely
>>> from shapely import LineString, Polygon
>>> shapely.is_valid_reason(LineString([(0, 0), (1, 1)]))
'Valid Geometry'
>>> shapely.is_valid_reason(Polygon([(0, 0), (1, 1), (1, 2), (1, 1), (0, 0)]))
'Self-intersection[1 2]'
>>> shapely.is_valid_reason(None) is None
True
shapely.length
Python Library Documentation: function length in module shapely.measurement
length(geometry, **kwargs)
Compute the length of a (multi)linestring or polygon perimeter.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the length.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, MultiLineString, Polygon
>>> shapely.length(LineString([(0, 0), (0, 2), (3, 2)]))
5.0
>>> shapely.length(MultiLineString([
... LineString([(0, 0), (1, 0)]),
... LineString([(1, 0), (2, 0)])
... ]))
2.0
>>> shapely.length(Polygon([(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)]))
40.0
>>> shapely.length(LineString())
0.0
>>> shapely.length(None)
nan
shapely.lib
Python Library Documentation: module shapely.lib in shapely
NAME
shapely.lib
CLASSES
builtins.object
Geometry
STRtree
class Geometry(builtins.object)
| Geometry type
|
| Methods defined here:
|
| __eq__(self, value, /)
| Return self==value.
|
| __ge__(self, value, /)
| Return self>=value.
|
| __gt__(self, value, /)
| Return self>value.
|
| __hash__(self, /)
| Return hash(self).
|
| __le__(self, value, /)
| Return self<=value.
|
| __lt__(self, value, /)
| Return self<value.
|
| __ne__(self, value, /)
| Return self!=value.
|
| __repr__(self, /)
| Return repr(self).
|
| __setstate__(...)
| For unpickling pre-shapely 2.0 pickles
|
| __str__(self, /)
| Return str(self).
class STRtree(builtins.object)
| A query-only R-tree created using the Sort-Tile-Recursive (STR) algorithm.
|
| Methods defined here:
|
| dwithin(...)
| Queries the index for all item(s) in the tree within given distance of search geometries
|
| nearest(...)
| Queries the index for the nearest item to each of the given search geometries
|
| query(...)
| Queries the index for all items whose extents intersect the given search geometries, and optionally tests them against predicate function if provided.
|
| query_nearest(...)
| Queries the index for all nearest item(s) to each of the given search geometries
|
| ----------------------------------------------------------------------
| Static methods defined here:
|
| __new__(*args, **kwargs)
| Create and return a new object. See help(type) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| count
| The number of geometries inside the tree
FUNCTIONS
count_coordinates(...)
Counts the total amount of coordinates in a array with geometry objects
get_coordinates(...)
Gets the coordinates as an (N, 2), (N, 3), or (N, 4) shaped ndarray of floats
set_coordinates(...)
Sets coordinates to a geometry array
DATA
area = <ufunc 'area'>
area(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
boundary = <ufunc 'boundary'>
boundary(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
bounds = <ufunc 'bounds'>
bounds(x, /, out=None, *, casting='same_kind', order='K', dtype=None, subok=True[, signature, axes, axis])
box = <ufunc 'box'>
box(x1, x2, x3, x4, x5, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
buffer = <ufunc 'buffer'>
buffer(x1, x2, x3, x4, x5, x6, x7, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
build_area = <ufunc 'build_area'>
build_area(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
centroid = <ufunc 'centroid'>
centroid(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
clip_by_rect = <ufunc 'clip_by_rect'>
clip_by_rect(x1, x2, x3, x4, x5, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
concave_hull = <ufunc 'concave_hull'>
concave_hull(x1, x2, x3, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
constrained_delaunay_triangles = <ufunc 'constrained_delaunay_triangle...
constrained_delaunay_triangles(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
contains = <ufunc 'contains'>
contains(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
contains_properly = <ufunc 'contains_properly'>
contains_properly(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
contains_xy = <ufunc 'contains_xy'>
contains_xy(x1, x2, x3, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
convex_hull = <ufunc 'convex_hull'>
convex_hull(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
coverage_invalid_edges = <ufunc 'coverage_invalid_edges'>
coverage_invalid_edges(x1, x2, /, out=None, *, casting='same_kind', order='K', dtype=None, subok=True[, signature, axes, axis])
coverage_is_valid = <ufunc 'coverage_is_valid'>
coverage_is_valid(x1, x2, /, out=None, *, casting='same_kind', order='K', dtype=None, subok=True[, signature, axes, axis])
coverage_simplify = <ufunc 'coverage_simplify'>
coverage_simplify(x1, x2, x3, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
coverage_union = <ufunc 'coverage_union'>
coverage_union(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
covered_by = <ufunc 'covered_by'>
covered_by(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
covers = <ufunc 'covers'>
covers(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
create_collection = <ufunc 'create_collection'>
create_collection(x1, x2, /, out=None, *, casting='same_kind', order='K', dtype=None, subok=True[, signature, axes, axis])
crosses = <ufunc 'crosses'>
crosses(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
delaunay_triangles = <ufunc 'delaunay_triangles'>
delaunay_triangles(x1, x2, x3, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
destroy_prepared = <ufunc 'destroy_prepared'>
destroy_prepared(x, /, out=(), *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
difference = <ufunc 'difference'>
difference(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
difference_prec = <ufunc 'difference_prec'>
difference_prec(x1, x2, x3, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
disjoint = <ufunc 'disjoint'>
disjoint(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
disjoint_subset_union = <ufunc 'disjoint_subset_union'>
disjoint_subset_union(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
distance = <ufunc 'distance'>
distance(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
dwithin = <ufunc 'dwithin'>
dwithin(x1, x2, x3, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
envelope = <ufunc 'envelope'>
envelope(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
equals = <ufunc 'equals'>
equals(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
equals_exact = <ufunc 'equals_exact'>
equals_exact(x1, x2, x3, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
equals_identical = <ufunc 'equals_identical'>
equals_identical(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
extract_unique_points = <ufunc 'extract_unique_points'>
extract_unique_points(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
force_2d = <ufunc 'force_2d'>
force_2d(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
force_3d = <ufunc 'force_3d'>
force_3d(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
frechet_distance = <ufunc 'frechet_distance'>
frechet_distance(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
frechet_distance_densify = <ufunc 'frechet_distance_densify'>
frechet_distance_densify(x1, x2, x3, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
from_geojson = <ufunc 'from_geojson'>
from_geojson(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
from_wkb = <ufunc 'from_wkb'>
from_wkb(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
from_wkt = <ufunc 'from_wkt'>
from_wkt(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
geos_capi_version = (1, 19, 2)
geos_capi_version_string = '3.13.1-CAPI-1.19.2'
geos_version = (3, 13, 1)
geos_version_string = '3.13.1'
get_coordinate_dimension = <ufunc 'get_coordinate_dimension'>
get_coordinate_dimension(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
get_dimensions = <ufunc 'get_dimensions'>
get_dimensions(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
get_exterior_ring = <ufunc 'get_exterior_ring'>
get_exterior_ring(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
get_geometry = <ufunc 'get_geometry'>
get_geometry(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
get_interior_ring = <ufunc 'get_interior_ring'>
get_interior_ring(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
get_m = <ufunc 'get_m'>
get_m(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
get_num_coordinates = <ufunc 'get_num_coordinates'>
get_num_coordinates(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
get_num_geometries = <ufunc 'get_num_geometries'>
get_num_geometries(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
get_num_interior_rings = <ufunc 'get_num_interior_rings'>
get_num_interior_rings(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
get_num_points = <ufunc 'get_num_points'>
get_num_points(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
get_point = <ufunc 'get_point'>
get_point(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
get_precision = <ufunc 'get_precision'>
get_precision(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
get_srid = <ufunc 'get_srid'>
get_srid(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
get_type_id = <ufunc 'get_type_id'>
get_type_id(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
get_x = <ufunc 'get_x'>
get_x(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
get_y = <ufunc 'get_y'>
get_y(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
get_z = <ufunc 'get_z'>
get_z(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
has_m = <ufunc 'has_m'>
has_m(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
has_z = <ufunc 'has_z'>
has_z(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
hausdorff_distance = <ufunc 'hausdorff_distance'>
hausdorff_distance(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
hausdorff_distance_densify = <ufunc 'hausdorff_distance_densify'>
hausdorff_distance_densify(x1, x2, x3, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
intersection = <ufunc 'intersection'>
intersection(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
intersection_all = <ufunc 'intersection_all'>
intersection_all(x, /, out=None, *, casting='same_kind', order='K', dtype=None, subok=True[, signature, axes, axis])
intersection_prec = <ufunc 'intersection_prec'>
intersection_prec(x1, x2, x3, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
intersects = <ufunc 'intersects'>
intersects(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
intersects_xy = <ufunc 'intersects_xy'>
intersects_xy(x1, x2, x3, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
is_ccw = <ufunc 'is_ccw'>
is_ccw(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
is_closed = <ufunc 'is_closed'>
is_closed(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
is_empty = <ufunc 'is_empty'>
is_empty(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
is_geometry = <ufunc 'is_geometry'>
is_geometry(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
is_missing = <ufunc 'is_missing'>
is_missing(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
is_prepared = <ufunc 'is_prepared'>
is_prepared(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
is_ring = <ufunc 'is_ring'>
is_ring(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
is_simple = <ufunc 'is_simple'>
is_simple(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
is_valid = <ufunc 'is_valid'>
is_valid(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
is_valid_input = <ufunc 'is_valid_input'>
is_valid_input(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
is_valid_reason = <ufunc 'is_valid_reason'>
is_valid_reason(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
length = <ufunc 'length'>
length(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
line_interpolate_point = <ufunc 'line_interpolate_point'>
line_interpolate_point(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
line_interpolate_point_normalized = <ufunc 'line_interpolate_point_nor...
line_interpolate_point_normalized(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
line_locate_point = <ufunc 'line_locate_point'>
line_locate_point(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
line_locate_point_normalized = <ufunc 'line_locate_point_normalized'>
line_locate_point_normalized(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
line_merge = <ufunc 'line_merge'>
line_merge(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
line_merge_directed = <ufunc 'line_merge_directed'>
line_merge_directed(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
linearrings = <ufunc 'linearrings'>
linearrings(x1, x2, /, out=None, *, casting='same_kind', order='K', dtype=None, subok=True[, signature, axes, axis])
linestrings = <ufunc 'linestrings'>
linestrings(x1, x2, /, out=None, *, casting='same_kind', order='K', dtype=None, subok=True[, signature, axes, axis])
make_valid = <ufunc 'make_valid'>
make_valid(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
make_valid_with_params = <ufunc 'make_valid_with_params'>
make_valid_with_params(x1, x2, x3, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
maximum_inscribed_circle = <ufunc 'maximum_inscribed_circle'>
maximum_inscribed_circle(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
minimum_bounding_circle = <ufunc 'minimum_bounding_circle'>
minimum_bounding_circle(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
minimum_bounding_radius = <ufunc 'minimum_bounding_radius'>
minimum_bounding_radius(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
minimum_clearance = <ufunc 'minimum_clearance'>
minimum_clearance(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
minimum_clearance_line = <ufunc 'minimum_clearance_line'>
minimum_clearance_line(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
node = <ufunc 'node'>
node(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
normalize = <ufunc 'normalize'>
normalize(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
offset_curve = <ufunc 'offset_curve'>
offset_curve(x1, x2, x3, x4, x5, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
orient_polygons = <ufunc 'orient_polygons'>
orient_polygons(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
oriented_envelope = <ufunc 'oriented_envelope'>
oriented_envelope(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
overlaps = <ufunc 'overlaps'>
overlaps(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
point_on_surface = <ufunc 'point_on_surface'>
point_on_surface(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
points = <ufunc 'points'>
points(x1, x2, /, out=None, *, casting='same_kind', order='K', dtype=None, subok=True[, signature, axes, axis])
polygonize = <ufunc 'polygonize'>
polygonize(x, /, out=None, *, casting='same_kind', order='K', dtype=None, subok=True[, signature, axes, axis])
polygonize_full = <ufunc 'polygonize_full'>
polygonize_full(x[, out1, out2, out3, out4], / [, out=(None, None, None, None)], *, casting='same_kind', order='K', dtype=None, subok=True[, signature, axes, axis])
polygons = <ufunc 'polygons'>
polygons(x1, x2, /, out=None, *, casting='same_kind', order='K', dtype=None, subok=True[, signature, axes, axis])
prepare = <ufunc 'prepare'>
prepare(x, /, out=(), *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
registry = [<class 'shapely.geometry.point.Point'>, <class 'shapely.ge...
relate = <ufunc 'relate'>
relate(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
relate_pattern = <ufunc 'relate_pattern'>
relate_pattern(x1, x2, x3, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
remove_repeated_points = <ufunc 'remove_repeated_points'>
remove_repeated_points(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
reverse = <ufunc 'reverse'>
reverse(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
segmentize = <ufunc 'segmentize'>
segmentize(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
set_precision = <ufunc 'set_precision'>
set_precision(x1, x2, x3, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
set_srid = <ufunc 'set_srid'>
set_srid(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
shared_paths = <ufunc 'shared_paths'>
shared_paths(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
shortest_line = <ufunc 'shortest_line'>
shortest_line(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
simplify = <ufunc 'simplify'>
simplify(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
simplify_preserve_topology = <ufunc 'simplify_preserve_topology'>
simplify_preserve_topology(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
snap = <ufunc 'snap'>
snap(x1, x2, x3, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
symmetric_difference = <ufunc 'symmetric_difference'>
symmetric_difference(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
symmetric_difference_all = <ufunc 'symmetric_difference_all'>
symmetric_difference_all(x, /, out=None, *, casting='same_kind', order='K', dtype=None, subok=True[, signature, axes, axis])
symmetric_difference_prec = <ufunc 'symmetric_difference_prec'>
symmetric_difference_prec(x1, x2, x3, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
to_geojson = <ufunc 'to_geojson'>
to_geojson(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
to_wkb = <ufunc 'to_wkb'>
to_wkb(x1, x2, x3, x4, x5, x6, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
to_wkt = <ufunc 'to_wkt'>
to_wkt(x1, x2, x3, x4, x5, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
touches = <ufunc 'touches'>
touches(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
unary_union = <ufunc 'unary_union'>
unary_union(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
unary_union_prec = <ufunc 'unary_union_prec'>
unary_union_prec(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
union = <ufunc 'union'>
union(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
union_prec = <ufunc 'union_prec'>
union_prec(x1, x2, x3, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
voronoi_polygons = <ufunc 'voronoi_polygons'>
voronoi_polygons(x1, x2, x3, x4, x5, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
within = <ufunc 'within'>
within(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature])
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\shapely\lib.cp312-win_amd64.pyd
shapely.line_interpolate_point
Python Library Documentation: function line_interpolate_point in module shapely.linear
line_interpolate_point(line, distance, normalized=False, **kwargs)
Return a point interpolated at given distance on a line.
Parameters
----------
line : Geometry or array_like
For multilinestrings or geometrycollections, the first geometry is taken
and the rest is ignored. This function raises a TypeError for non-linear
geometries. For empty linear geometries, empty points are returned.
distance : float or array_like
Negative values measure distance from the end of the line. Out-of-range
values will be clipped to the line endings.
normalized : bool, default False
If True, the distance is a fraction of the total
line length instead of the absolute distance.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString
>>> line = LineString([(0, 2), (0, 10)])
>>> shapely.line_interpolate_point(line, 2)
<POINT (0 4)>
>>> shapely.line_interpolate_point(line, 100)
<POINT (0 10)>
>>> shapely.line_interpolate_point(line, -2)
<POINT (0 8)>
>>> shapely.line_interpolate_point(line, [0.25, -0.25], normalized=True).tolist()
[<POINT (0 4)>, <POINT (0 8)>]
>>> shapely.line_interpolate_point(LineString(), 1)
<POINT EMPTY>
shapely.line_locate_point
Python Library Documentation: function line_locate_point in module shapely.linear
line_locate_point(line, other, normalized=False, **kwargs)
Return the distance to the line origin of given point.
If given point does not intersect with the line, the point will first be
projected onto the line after which the distance is taken.
Parameters
----------
line : Geometry or array_like
Line or lines to calculate the distance to.
other : Geometry or array_like
Point or points to calculate the distance from.
normalized : bool, default False
If True, the distance is a fraction of the total line length instead of
the absolute distance.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> line = LineString([(0, 2), (0, 10)])
>>> point = Point(4, 4)
>>> shapely.line_locate_point(line, point)
2.0
>>> shapely.line_locate_point(line, point, normalized=True)
0.25
>>> shapely.line_locate_point(line, Point(0, 18))
8.0
>>> shapely.line_locate_point(LineString(), point)
nan
shapely.line_merge
Python Library Documentation: function line_merge in module shapely.linear
line_merge(line, directed=False, **kwargs)
Return (Multi)LineStrings formed by combining the lines in a MultiLineString.
Lines are joined together at their endpoints in case two lines are
intersecting. Lines are not joined when 3 or more lines are intersecting at
the endpoints. Line elements that cannot be joined are kept as is in the
resulting MultiLineString.
The direction of each merged LineString will be that of the majority of the
LineStrings from which it was derived. Except if ``directed=True`` is
specified, then the operation will not change the order of points within
lines and so only lines which can be joined with no change in direction
are merged.
Parameters
----------
line : Geometry or array_like
Linear geometry or geometries to merge.
directed : bool, default False
Only combine lines if possible without changing point order.
Requires GEOS >= 3.11.0
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import MultiLineString
>>> shapely.line_merge(MultiLineString([[(0, 2), (0, 10)], [(0, 10), (5, 10)]]))
<LINESTRING (0 2, 0 10, 5 10)>
>>> shapely.line_merge(MultiLineString([[(0, 2), (0, 10)], [(0, 11), (5, 10)]]))
<MULTILINESTRING ((0 2, 0 10), (0 11, 5 10))>
>>> shapely.line_merge(MultiLineString())
<GEOMETRYCOLLECTION EMPTY>
>>> shapely.line_merge(MultiLineString([[(0, 0), (1, 0)], [(0, 0), (3, 0)]]))
<LINESTRING (1 0, 0 0, 3 0)>
>>> shapely.line_merge(MultiLineString([[(0, 0), (1, 0)], [(0, 0), (3, 0)]]), directed=True)
<MULTILINESTRING ((0 0, 1 0), (0 0, 3 0))>
shapely.linear
Python Library Documentation: module shapely.linear in shapely
NAME
shapely.linear - Linear geometry functions.
FUNCTIONS
line_interpolate_point(line, distance, normalized=False, **kwargs)
Return a point interpolated at given distance on a line.
Parameters
----------
line : Geometry or array_like
For multilinestrings or geometrycollections, the first geometry is taken
and the rest is ignored. This function raises a TypeError for non-linear
geometries. For empty linear geometries, empty points are returned.
distance : float or array_like
Negative values measure distance from the end of the line. Out-of-range
values will be clipped to the line endings.
normalized : bool, default False
If True, the distance is a fraction of the total
line length instead of the absolute distance.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString
>>> line = LineString([(0, 2), (0, 10)])
>>> shapely.line_interpolate_point(line, 2)
<POINT (0 4)>
>>> shapely.line_interpolate_point(line, 100)
<POINT (0 10)>
>>> shapely.line_interpolate_point(line, -2)
<POINT (0 8)>
>>> shapely.line_interpolate_point(line, [0.25, -0.25], normalized=True).tolist()
[<POINT (0 4)>, <POINT (0 8)>]
>>> shapely.line_interpolate_point(LineString(), 1)
<POINT EMPTY>
line_locate_point(line, other, normalized=False, **kwargs)
Return the distance to the line origin of given point.
If given point does not intersect with the line, the point will first be
projected onto the line after which the distance is taken.
Parameters
----------
line : Geometry or array_like
Line or lines to calculate the distance to.
other : Geometry or array_like
Point or points to calculate the distance from.
normalized : bool, default False
If True, the distance is a fraction of the total line length instead of
the absolute distance.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> line = LineString([(0, 2), (0, 10)])
>>> point = Point(4, 4)
>>> shapely.line_locate_point(line, point)
2.0
>>> shapely.line_locate_point(line, point, normalized=True)
0.25
>>> shapely.line_locate_point(line, Point(0, 18))
8.0
>>> shapely.line_locate_point(LineString(), point)
nan
line_merge(line, directed=False, **kwargs)
Return (Multi)LineStrings formed by combining the lines in a MultiLineString.
Lines are joined together at their endpoints in case two lines are
intersecting. Lines are not joined when 3 or more lines are intersecting at
the endpoints. Line elements that cannot be joined are kept as is in the
resulting MultiLineString.
The direction of each merged LineString will be that of the majority of the
LineStrings from which it was derived. Except if ``directed=True`` is
specified, then the operation will not change the order of points within
lines and so only lines which can be joined with no change in direction
are merged.
Parameters
----------
line : Geometry or array_like
Linear geometry or geometries to merge.
directed : bool, default False
Only combine lines if possible without changing point order.
Requires GEOS >= 3.11.0
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import MultiLineString
>>> shapely.line_merge(MultiLineString([[(0, 2), (0, 10)], [(0, 10), (5, 10)]]))
<LINESTRING (0 2, 0 10, 5 10)>
>>> shapely.line_merge(MultiLineString([[(0, 2), (0, 10)], [(0, 11), (5, 10)]]))
<MULTILINESTRING ((0 2, 0 10), (0 11, 5 10))>
>>> shapely.line_merge(MultiLineString())
<GEOMETRYCOLLECTION EMPTY>
>>> shapely.line_merge(MultiLineString([[(0, 0), (1, 0)], [(0, 0), (3, 0)]]))
<LINESTRING (1 0, 0 0, 3 0)>
>>> shapely.line_merge(MultiLineString([[(0, 0), (1, 0)], [(0, 0), (3, 0)]]), directed=True)
<MULTILINESTRING ((0 0, 1 0), (0 0, 3 0))>
shared_paths(a, b, **kwargs)
Return the shared paths between a and b.
Both geometries should be linestrings or arrays of linestrings.
A geometrycollection or array of geometrycollections is returned
with two elements in each geometrycollection. The first element is a
multilinestring containing shared paths with the same direction
for both inputs. The second element is a multilinestring containing
shared paths with the opposite direction for the two inputs.
Parameters
----------
a, b : Geometry or array_like
Linestring or linestrings to compare.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString
>>> line1 = LineString([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)])
>>> line2 = LineString([(1, 0), (2, 0), (2, 1), (1, 1), (1, 0)])
>>> shapely.shared_paths(line1, line2).wkt
'GEOMETRYCOLLECTION (MULTILINESTRING EMPTY, MULTILINESTRING ((1 0, 1 1)))'
>>> line3 = LineString([(1, 1), (0, 1)])
>>> shapely.shared_paths(line1, line3).wkt
'GEOMETRYCOLLECTION (MULTILINESTRING ((1 1, 0 1)), MULTILINESTRING EMPTY)'
shortest_line(a, b, **kwargs)
Return the shortest line between two geometries.
The resulting line consists of two points, representing the nearest
points between the geometry pair. The line always starts in the first
geometry `a` and ends in the second geometry `b`. The endpoints of the
line will not necessarily be existing vertices of the input geometries
`a` and `b`, but can also be a point along a line segment.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to compare.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
prepare : improve performance by preparing ``a`` (the first argument)
Examples
--------
>>> import shapely
>>> from shapely import LineString
>>> line1 = LineString([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)])
>>> line2 = LineString([(0, 3), (3, 0), (5, 3)])
>>> shapely.shortest_line(line1, line2)
<LINESTRING (1 1, 1.5 1.5)>
DATA
__all__ = ['line_interpolate_point', 'line_locate_point', 'line_merge'...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\shapely\linear.py
shapely.linearrings
Python Library Documentation: function linearrings in module shapely.creation
linearrings(coords, y=None, z=None, indices=None, *, handle_nan=<HandleNaN.allow: 0>, out=None, **kwargs)
Create an array of linearrings.
If the provided coords do not constitute a closed linestring, or if there
are only 3 provided coords, the first
coordinate is duplicated at the end to close the ring. This function will
raise an exception if a linearring contains less than three points or if
the terminal coordinates contain NaN (not-a-number).
Parameters
----------
coords : array_like
An array of lists of coordinate tuples (2- or 3-dimensional) or, if ``y``
is provided, an array of lists of x coordinates
y : array_like, optional
An array of y coordinates.
z : array_like, optional
An array of z coordinates.
indices : array_like, optional
Indices into the target array where input coordinates belong. If
provided, the coords should be 2D with shape (N, 2) or (N, 3) and
indices should be an array of shape (N,) with integers in increasing
order. Missing indices result in a ValueError unless ``out`` is
provided, in which case the original value in ``out`` is kept.
handle_nan : shapely.HandleNaN or {'allow', 'skip', 'error'}, default 'allow'
Specifies what to do when a NaN or Inf is encountered in the coordinates:
- 'allow': the geometries are created with NaN or Inf coordinates.
Note that this can result in unexpected behaviour in subsequent
operations, and generally it is discouraged to have non-finite
coordinate values. One can use this option if you know all
coordinates are finite and want to avoid the overhead of checking
for this.
- 'skip': the coordinate pairs where any of x, y or z values are
NaN or Inf are ignored. If this results in ignoring all coordinates
for one geometry, an empty geometry is created.
- 'error': if any NaN or Inf is detected in the coordinates, a ValueError
is raised. This option ensures that the created geometries have all
finite coordinate values.
.. versionadded:: 2.1.0
out : ndarray, optional
An array (with dtype object) to output the geometries into.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Ignored if ``indices`` is provided.
See Also
--------
linestrings
Examples
--------
>>> import shapely
>>> shapely.linearrings([[0, 0], [0, 1], [1, 1], [0, 0]])
<LINEARRING (0 0, 0 1, 1 1, 0 0)>
>>> shapely.linearrings([[0, 0], [0, 1], [1, 1]])
<LINEARRING (0 0, 0 1, 1 1, 0 0)>
Notes
-----
- Usage of the ``y`` and ``z`` arguments will prevents lazy evaluation in
``dask``. Instead provide the coordinates as a ``(..., 2)`` or
``(..., 3)`` array using only ``coords``.
shapely.linestrings
Python Library Documentation: function linestrings in module shapely.creation
linestrings(coords, y=None, z=None, indices=None, *, handle_nan=<HandleNaN.allow: 0>, out=None, **kwargs)
Create an array of linestrings.
This function will raise an exception if a linestring contains less than
two points.
Parameters
----------
coords : array_like
An array of lists of coordinate tuples (2- or 3-dimensional) or, if ``y``
is provided, an array of lists of x coordinates.
y : array_like, optional
An array of y coordinates.
z : array_like, optional
An array of z coordinates.
indices : array_like, optional
Indices into the target array where input coordinates belong. If
provided, the coords should be 2D with shape (N, 2) or (N, 3) and
indices should be an array of shape (N,) with integers in increasing
order. Missing indices result in a ValueError unless ``out`` is
provided, in which case the original value in ``out`` is kept.
handle_nan : shapely.HandleNaN or {'allow', 'skip', 'error'}, default 'allow'
Specifies what to do when a NaN or Inf is encountered in the coordinates:
- 'allow': the geometries are created with NaN or Inf coordinates.
Note that this can result in unexpected behaviour in subsequent
operations, and generally it is discouraged to have non-finite
coordinate values. One can use this option if you know all
coordinates are finite and want to avoid the overhead of checking
for this.
- 'skip': the coordinate pairs where any of x, y or z values are
NaN or Inf are ignored. If this results in ignoring all coordinates
for one geometry, an empty geometry is created.
- 'error': if any NaN or Inf is detected in the coordinates, a ValueError
is raised. This option ensures that the created geometries have all
finite coordinate values.
.. versionadded:: 2.1.0
out : ndarray, optional
An array (with dtype object) to output the geometries into.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Ignored if ``indices`` is provided.
Examples
--------
>>> import shapely
>>> shapely.linestrings([[[0, 1], [4, 5]], [[2, 3], [5, 6]]]).tolist()
[<LINESTRING (0 1, 4 5)>, <LINESTRING (2 3, 5 6)>]
>>> shapely.linestrings(
... [[0, 1], [4, 5], [2, 3], [5, 6], [7, 8]],
... indices=[0, 0, 1, 1, 1]
... ).tolist()
[<LINESTRING (0 1, 4 5)>, <LINESTRING (2 3, 5 6, 7 8)>]
Notes
-----
- Usage of the ``y`` and ``z`` arguments will prevents lazy evaluation in
``dask``. Instead provide the coordinates as a ``(..., 2)`` or
``(..., 3)`` array using only ``coords``.
shapely.make_valid
Python Library Documentation: function make_valid in module shapely.constructive
make_valid(geometry, *, method='linework', keep_collapsed=True, **kwargs)
Repair invalid geometries.
Two ``methods`` are available:
* the 'linework' algorithm tries to preserve every edge and vertex in the input. It
combines all rings into a set of noded lines and then extracts valid polygons from
that linework. An alternating even-odd strategy is used to assign areas as
interior or exterior. A disadvantage is that for some relatively simple invalid
geometries this produces rather complex results.
* the 'structure' algorithm tries to reason from the structure of the input to find
the 'correct' repair: exterior rings bound area, interior holes exclude area.
It first makes all rings valid, then shells are merged and holes are subtracted
from the shells to generate valid result. It assumes that holes and shells are
correctly categorized in the input geometry.
Example:
.. plot:: code/make_valid_methods.py
When using ``make_valid`` on a Polygon, the result can be a GeometryCollection. For
this example this is the case when the 'linework' ``method`` is used. LineStrings in
the result are drawn in red.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to repair.
method : {'linework', 'structure'}, default 'linework'
Algorithm to use when repairing geometry. 'structure'
requires GEOS >= 3.10.
.. versionadded:: 2.1.0
keep_collapsed : bool, default True
For the 'structure' method, True will keep components that have collapsed into a
lower dimensionality. For example, a ring collapsing to a line, or a line
collapsing to a point. Must be True for the 'linework' method.
.. versionadded:: 2.1.0
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import Polygon
>>> polygon = Polygon([(0, 0), (1, 1), (1, 2), (1, 1), (0, 0)])
>>> shapely.is_valid(polygon)
False
>>> shapely.make_valid(polygon)
<MULTILINESTRING ((0 0, 1 1), (1 1, 1 2))>
>>> shapely.make_valid(polygon, method="structure", keep_collapsed=True)
<LINESTRING (0 0, 1 1, 1 2, 1 1, 0 0)>
>>> shapely.make_valid(polygon, method="structure", keep_collapsed=False)
<POLYGON EMPTY>
shapely.maximum_inscribed_circle
Python Library Documentation: function maximum_inscribed_circle in module shapely.constructive
maximum_inscribed_circle(geometry, tolerance=None, **kwargs)
Find the largest circle that is fully contained within the input geometry.
Constructs the "maximum inscribed circle" (MIC) for a polygonal geometry,
up to a specified tolerance. The MIC is determined by a point in the
interior of the area which has the farthest distance from the area
boundary, along with a boundary point at that distance. In the context of
geography the center of the MIC is known as the "pole of inaccessibility".
A cartographic use case is to determine a suitable point to place a map
label within a polygon.
The radius length of the MIC is a measure of how "narrow" a polygon is.
It is the distance at which the negative buffer becomes empty.
The function supports polygons with holes and multipolygons.
Returns a two-point linestring, with the first point at the center of the
inscribed circle and the second on the boundary of the inscribed circle.
.. versionadded:: 2.1.0
Parameters
----------
geometry : Geometry or array_like
tolerance : float or array_like, optional
Stop the algorithm when the search area is smaller than this tolerance.
When not specified, uses `max(width, height) / 1000` per geometry as
the default.
**kwargs
For other keyword-only arguments, see the
`NumPy ufunc docs <https://numpy.org/doc/stable/reference/ufuncs.html#ufuncs-kwargs>`_.
Examples
--------
>>> import shapely
>>> from shapely import Polygon
>>> poly = Polygon([(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)])
>>> shapely.maximum_inscribed_circle(poly)
<LINESTRING (5 5, 0 5)>
See Also
--------
minimum_bounding_circle
shapely.measurement
Python Library Documentation: module shapely.measurement in shapely
NAME
shapely.measurement - Methods for measuring (between) geometries.
FUNCTIONS
area(geometry, **kwargs)
Compute the area of a (multi)polygon.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the area.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import MultiPolygon, Polygon
>>> polygon = Polygon([(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)])
>>> shapely.area(polygon)
100.0
>>> polygon2 = Polygon([(10, 10), (10, 20), (20, 20), (20, 10), (10, 10)])
>>> shapely.area(MultiPolygon([polygon, polygon2]))
200.0
>>> shapely.area(Polygon())
0.0
>>> shapely.area(None)
nan
bounds(geometry, **kwargs)
Compute the bounds (extent) of a geometry.
For each geometry these 4 numbers are returned: min x, min y, max x, max y.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the bounds.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point, Polygon
>>> shapely.bounds(Point(2, 3)).tolist()
[2.0, 3.0, 2.0, 3.0]
>>> shapely.bounds(LineString([(0, 0), (0, 2), (3, 2)])).tolist()
[0.0, 0.0, 3.0, 2.0]
>>> shapely.bounds(Polygon()).tolist()
[nan, nan, nan, nan]
>>> shapely.bounds(None).tolist()
[nan, nan, nan, nan]
distance(a, b, **kwargs)
Compute the Cartesian distance between two geometries.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to compute the distance between.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point, Polygon
>>> point = Point(0, 0)
>>> shapely.distance(Point(10, 0), point)
10.0
>>> shapely.distance(LineString([(1, 1), (1, -1)]), point)
1.0
>>> shapely.distance(Polygon([(3, 0), (5, 0), (5, 5), (3, 5), (3, 0)]), point)
3.0
>>> shapely.distance(Point(), point)
nan
>>> shapely.distance(None, point)
nan
frechet_distance(a, b, densify=None, **kwargs)
Compute the discrete Fréchet distance between two geometries.
The Fréchet distance is a measure of similarity: it is the greatest
distance between any point in A and the closest point in B. The discrete
distance is an approximation of this metric: only vertices are considered.
The parameter 'densify' makes this approximation less coarse by splitting
the line segments between vertices before computing the distance.
Fréchet distance sweep continuously along their respective curves
and the direction of curves is significant. This makes it a better measure
of similarity than Hausdorff distance for curve or surface matching.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to compute the distance between.
densify : float or array_like, optional
The value of densify is required to be between 0 and 1.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString
>>> line1 = LineString([(0, 0), (100, 0)])
>>> line2 = LineString([(0, 0), (50, 50), (100, 0)])
>>> shapely.frechet_distance(line1, line2)
70.71067811865476
>>> shapely.frechet_distance(line1, line2, densify=0.5)
50.0
>>> shapely.frechet_distance(line1, LineString())
nan
>>> shapely.frechet_distance(line1, None)
nan
hausdorff_distance(a, b, densify=None, **kwargs)
Compute the discrete Hausdorff distance between two geometries.
The Hausdorff distance is a measure of similarity: it is the greatest
distance between any point in A and the closest point in B. The discrete
distance is an approximation of this metric: only vertices are considered.
The parameter 'densify' makes this approximation less coarse by splitting
the line segments between vertices before computing the distance.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to compute the distance between.
densify : float or array_like, optional
The value of densify is required to be between 0 and 1.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString
>>> line1 = LineString([(130, 0), (0, 0), (0, 150)])
>>> line2 = LineString([(10, 10), (10, 150), (130, 10)])
>>> shapely.hausdorff_distance(line1, line2)
14.142135623730951
>>> shapely.hausdorff_distance(line1, line2, densify=0.5)
70.0
>>> shapely.hausdorff_distance(line1, LineString())
nan
>>> shapely.hausdorff_distance(line1, None)
nan
length(geometry, **kwargs)
Compute the length of a (multi)linestring or polygon perimeter.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the length.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, MultiLineString, Polygon
>>> shapely.length(LineString([(0, 0), (0, 2), (3, 2)]))
5.0
>>> shapely.length(MultiLineString([
... LineString([(0, 0), (1, 0)]),
... LineString([(1, 0), (2, 0)])
... ]))
2.0
>>> shapely.length(Polygon([(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)]))
40.0
>>> shapely.length(LineString())
0.0
>>> shapely.length(None)
nan
minimum_bounding_radius(geometry, **kwargs)
Compute the radius of the minimum bounding circle of an input geometry.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the minimum bounding radius.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, LineString, MultiPoint, Point, Polygon
>>> shapely.minimum_bounding_radius(
... Polygon([(0, 5), (5, 10), (10, 5), (5, 0), (0, 5)])
... )
5.0
>>> shapely.minimum_bounding_radius(LineString([(1, 1), (1, 10)]))
4.5
>>> shapely.minimum_bounding_radius(MultiPoint([(2, 2), (4, 2)]))
1.0
>>> shapely.minimum_bounding_radius(Point(0, 1))
0.0
>>> shapely.minimum_bounding_radius(GeometryCollection())
0.0
See Also
--------
minimum_bounding_circle
minimum_clearance(geometry, **kwargs)
Compute the Minimum Clearance distance.
A geometry's "minimum clearance" is the smallest distance by which
a vertex of the geometry could be moved to produce an invalid geometry.
If no minimum clearance exists for a geometry (for example, a single
point, or an empty geometry), infinity is returned.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the minimum clearance.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import Polygon
>>> polygon = Polygon([(0, 0), (0, 10), (5, 6), (10, 10), (10, 0), (5, 4), (0, 0)])
>>> shapely.minimum_clearance(polygon)
2.0
>>> shapely.minimum_clearance(Polygon())
inf
>>> shapely.minimum_clearance(None)
nan
See Also
--------
minimum_clearance_line
total_bounds(geometry, **kwargs)
Compute the total bounds (extent) of the geometry.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the total bounds.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Returns
-------
numpy ndarray of [xmin, ymin, xmax, ymax]
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point, Polygon
>>> shapely.total_bounds(Point(2, 3)).tolist()
[2.0, 3.0, 2.0, 3.0]
>>> shapely.total_bounds([Point(2, 3), Point(4, 5)]).tolist()
[2.0, 3.0, 4.0, 5.0]
>>> shapely.total_bounds([
... LineString([(0, 1), (0, 2), (3, 2)]),
... LineString([(4, 4), (4, 6), (6, 7)])
... ]).tolist()
[0.0, 1.0, 6.0, 7.0]
>>> shapely.total_bounds(Polygon()).tolist()
[nan, nan, nan, nan]
>>> shapely.total_bounds([Polygon(), Point(2, 3)]).tolist()
[2.0, 3.0, 2.0, 3.0]
>>> shapely.total_bounds(None).tolist()
[nan, nan, nan, nan]
DATA
__all__ = ['area', 'bounds', 'distance', 'frechet_distance', 'hausdorf...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\shapely\measurement.py
shapely.minimum_bounding_circle
Python Library Documentation: function minimum_bounding_circle in module shapely.constructive
minimum_bounding_circle(geometry, **kwargs)
Compute the minimum bounding circle that encloses an input geometry.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the minimum bounding circle.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, LineString, MultiPoint, Point, Polygon
>>> shapely.minimum_bounding_circle(
... Polygon([(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)])
... )
<POLYGON ((12.071 5, 11.935 3.621, 11.533 2.294, 10.879 1.07...>
>>> shapely.minimum_bounding_circle(LineString([(1, 1), (10, 10)]))
<POLYGON ((11.864 5.5, 11.742 4.258, 11.38 3.065, 10.791 1.9...>
>>> shapely.minimum_bounding_circle(MultiPoint([(2, 2), (4, 2)]))
<POLYGON ((4 2, 3.981 1.805, 3.924 1.617, 3.831 1.444, 3.707...>
>>> shapely.minimum_bounding_circle(Point(0, 1))
<POINT (0 1)>
>>> shapely.minimum_bounding_circle(GeometryCollection([]))
<POLYGON EMPTY>
See Also
--------
minimum_bounding_radius, maximum_inscribed_circle
shapely.minimum_bounding_radius
Python Library Documentation: function minimum_bounding_radius in module shapely.measurement
minimum_bounding_radius(geometry, **kwargs)
Compute the radius of the minimum bounding circle of an input geometry.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the minimum bounding radius.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, LineString, MultiPoint, Point, Polygon
>>> shapely.minimum_bounding_radius(
... Polygon([(0, 5), (5, 10), (10, 5), (5, 0), (0, 5)])
... )
5.0
>>> shapely.minimum_bounding_radius(LineString([(1, 1), (1, 10)]))
4.5
>>> shapely.minimum_bounding_radius(MultiPoint([(2, 2), (4, 2)]))
1.0
>>> shapely.minimum_bounding_radius(Point(0, 1))
0.0
>>> shapely.minimum_bounding_radius(GeometryCollection())
0.0
See Also
--------
minimum_bounding_circle
shapely.minimum_clearance
Python Library Documentation: function minimum_clearance in module shapely.measurement
minimum_clearance(geometry, **kwargs)
Compute the Minimum Clearance distance.
A geometry's "minimum clearance" is the smallest distance by which
a vertex of the geometry could be moved to produce an invalid geometry.
If no minimum clearance exists for a geometry (for example, a single
point, or an empty geometry), infinity is returned.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the minimum clearance.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import Polygon
>>> polygon = Polygon([(0, 0), (0, 10), (5, 6), (10, 10), (10, 0), (5, 4), (0, 0)])
>>> shapely.minimum_clearance(polygon)
2.0
>>> shapely.minimum_clearance(Polygon())
inf
>>> shapely.minimum_clearance(None)
nan
See Also
--------
minimum_clearance_line
shapely.minimum_clearance_line
Python Library Documentation: function minimum_clearance_line in module shapely.constructive
minimum_clearance_line(geometry, **kwargs)
Return a LineString whose endpoints define the minimum clearance.
A geometry's "minimum clearance" is the smallest distance by which a vertex
of the geometry could be moved to produce an invalid geometry.
If the geometry has no minimum clearance, an empty LineString will be
returned.
.. versionadded:: 2.1.0
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to determine the minimum clearance line for.
**kwargs
For other keyword-only arguments, see the
`NumPy ufunc docs <https://numpy.org/doc/stable/reference/ufuncs.html#ufuncs-kwargs>`_.
Examples
--------
>>> import shapely
>>> from shapely import Polygon
>>> poly = Polygon([(0, 0), (10, 0), (10, 10), (5, 5), (0, 10), (0, 0)])
>>> shapely.minimum_clearance_line(poly)
<LINESTRING (5 5, 5 0)>
See Also
--------
minimum_clearance
shapely.minimum_rotated_rectangle
Python Library Documentation: function oriented_envelope in module shapely.constructive
oriented_envelope(geometry, **kwargs)
Compute the oriented envelope (minimum rotated rectangle) of the input 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
:func:`~shapely.normalize` to reorganize the rectangle to
:ref:`strict canonical form <canonical-form>` so the starting point is
always the lower left point.
``minimum_rotated_rectangle`` is an alias for ``oriented_envelope``.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the oriented envelope.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, LineString, MultiPoint, Point, Polygon
>>> shapely.oriented_envelope(MultiPoint([(0, 0), (10, 0), (10, 10)])).normalize()
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))>
>>> shapely.oriented_envelope(LineString([(1, 1), (5, 1), (10, 10)])).normalize()
<POLYGON ((1 1, 10 10, 12 8, 3 -1, 1 1))>
>>> shapely.oriented_envelope(Polygon([(1, 1), (15, 1), (5, 10), (1, 1)])).normalize()
<POLYGON ((1 1, 5 10, 16.691 4.804, 12.691 -4.196, 1 1))>
>>> shapely.oriented_envelope(LineString([(1, 1), (10, 1)])).normalize()
<LINESTRING (1 1, 10 1)>
>>> shapely.oriented_envelope(Point(2, 2))
<POINT (2 2)>
>>> shapely.oriented_envelope(GeometryCollection([]))
<POLYGON EMPTY>
shapely.multilinestrings
Python Library Documentation: function multilinestrings in module shapely.creation
multilinestrings(geometries, indices=None, *, out=None, **kwargs)
Create multilinestrings from arrays of linestrings.
Parameters
----------
geometries : array_like
An array of linestrings or coordinates (see linestrings).
indices : array_like, optional
Indices into the target array where input geometries belong. If
provided, both geometries and indices should be 1D and have matching
sizes. Indices should be in increasing order. Missing indices result
in a ValueError unless ``out`` is provided, in which case the original
value in ``out`` is kept.
out : ndarray, optional
An array (with dtype object) to output the geometries into.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Ignored if ``indices`` is provided.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``indices`` is specified as a
positional argument. This will need to be specified as a keyword
argument in a future release.
See Also
--------
multipoints
shapely.multipoints
Python Library Documentation: function multipoints in module shapely.creation
multipoints(geometries, indices=None, *, out=None, **kwargs)
Create multipoints from arrays of points.
Parameters
----------
geometries : array_like
An array of points or coordinates (see points).
indices : array_like, optional
Indices into the target array where input geometries belong. If
provided, both geometries and indices should be 1D and have matching
sizes. Indices should be in increasing order. Missing indices result
in a ValueError unless ``out`` is provided, in which case the original
value in ``out`` is kept.
out : ndarray, optional
An array (with dtype object) to output the geometries into.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Ignored if ``indices`` is provided.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``indices`` is specified as a
positional argument. This will need to be specified as a keyword
argument in a future release.
Examples
--------
>>> import shapely
Multipoints are constructed from points:
>>> point_1 = shapely.points([1, 1])
>>> point_2 = shapely.points([2, 2])
>>> shapely.multipoints([point_1, point_2])
<MULTIPOINT ((1 1), (2 2))>
>>> shapely.multipoints([[point_1, point_2], [point_2, None]]).tolist()
[<MULTIPOINT ((1 1), (2 2))>, <MULTIPOINT ((2 2))>]
Or from coordinates directly:
>>> shapely.multipoints([[0, 0], [2, 2], [3, 3]])
<MULTIPOINT ((0 0), (2 2), (3 3))>
Multiple multipoints of different sizes can be constructed efficiently using the
``indices`` keyword argument:
>>> shapely.multipoints([point_1, point_2, point_2], indices=[0, 0, 1]).tolist()
[<MULTIPOINT ((1 1), (2 2))>, <MULTIPOINT ((2 2))>]
Missing input values (``None``) are skipped and may result in an
empty multipoint:
>>> shapely.multipoints([None])
<MULTIPOINT EMPTY>
>>> shapely.multipoints([point_1, None], indices=[0, 0]).tolist()
[<MULTIPOINT ((1 1))>]
>>> shapely.multipoints([point_1, None], indices=[0, 1]).tolist()
[<MULTIPOINT ((1 1))>, <MULTIPOINT EMPTY>]
shapely.multipolygons
Python Library Documentation: function multipolygons in module shapely.creation
multipolygons(geometries, indices=None, *, out=None, **kwargs)
Create multipolygons from arrays of polygons.
Parameters
----------
geometries : array_like
An array of polygons or coordinates (see polygons).
indices : array_like, optional
Indices into the target array where input geometries belong. If
provided, both geometries and indices should be 1D and have matching
sizes. Indices should be in increasing order. Missing indices result
in a ValueError unless ``out`` is provided, in which case the original
value in ``out`` is kept.
out : ndarray, optional
An array (with dtype object) to output the geometries into.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Ignored if ``indices`` is provided.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``indices`` is specified as a
positional argument. This will need to be specified as a keyword
argument in a future release.
See Also
--------
multipoints
shapely.node
Python Library Documentation: function node in module shapely.constructive
node(geometry, **kwargs)
Return the fully noded version of the linear input as MultiLineString.
Given a linear input geometry, this function returns a new MultiLineString
in which no lines cross each other but only touch at and points. To
obtain this, all intersections between segments are computed and added
to the segments, and duplicate segments are removed.
Non-linear input (points) will result in an empty MultiLineString.
This function can for example be used to create a fully-noded linework
suitable to passed as input to ``polygonize``.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the noded version.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> line = LineString([(0, 0), (1,1), (0, 1), (1, 0)])
>>> shapely.node(line)
<MULTILINESTRING ((0 0, 0.5 0.5), (0.5 0.5, 1 1, 0 1, 0.5 0.5), (0.5 0.5, 1 0))>
>>> shapely.node(Point(1, 1))
<MULTILINESTRING EMPTY>
shapely.normalize
Python Library Documentation: function normalize in module shapely.constructive
normalize(geometry, **kwargs)
Convert Geometry to strict normal form (or canonical form).
In :ref:`strict canonical form <canonical-form>`, the coordinates, rings of
a polygon and parts of multi geometries are ordered consistently. Typically
useful for testing purposes (for example in combination with
``equals_exact``).
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to normalize.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import MultiLineString
>>> line = MultiLineString([[(0, 0), (1, 1)], [(2, 2), (3, 3)]])
>>> shapely.normalize(line)
<MULTILINESTRING ((2 2, 3 3), (0 0, 1 1))>
shapely.offset_curve
Python Library Documentation: function offset_curve in module shapely.constructive
offset_curve(geometry, distance, quad_segs=8, join_style='round', mitre_limit=5.0, **kwargs)
Return a (Multi)LineString at a distance from the object.
For positive distance the offset will be at the left side of the input
line. For a negative distance it will be at the right side. In general,
this function tries to preserve the direction of the input.
Note: the behaviour regarding orientation of the resulting line depends
on the GEOS version. With GEOS < 3.11, the line retains the same
direction for a left offset (positive distance) or has opposite direction
for a right offset (negative distance), and this behaviour was documented
as such in previous Shapely versions. Starting with GEOS 3.11, the
function tries to preserve the orientation of the original line.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the offset.
distance : float or array_like
Specifies the offset distance from the input geometry. Negative
for right side offset, positive for left side offset.
quad_segs : int, default 8
Specifies the number of linear segments in a quarter circle in the
approximation of circular arcs.
join_style : {'round', 'bevel', 'mitre'}, default 'round'
Specifies the shape of outside corners. 'round' results in
rounded shapes. 'bevel' results in a beveled edge that touches the
original vertex. 'mitre' results in a single vertex that is beveled
depending on the ``mitre_limit`` parameter.
mitre_limit : float, default 5.0
Crops of 'mitre'-style joins if the point is displaced from the
buffered vertex by more than this limit.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``quad_segs``, ``join_style`` or
``mitre_limit`` are specified as positional arguments. In a future
release, these will need to be specified as keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString
>>> line = LineString([(0, 0), (0, 2)])
>>> shapely.offset_curve(line, 2)
<LINESTRING (-2 0, -2 2)>
>>> shapely.offset_curve(line, -2)
<LINESTRING (2 0, 2 2)>
shapely.orient_polygons
Python Library Documentation: function orient_polygons in module shapely.constructive
orient_polygons(geometry, *, exterior_cw=False, **kwargs)
Enforce a ring orientation on all polygonal elements in the input geometry.
Forces (Multi)Polygons to use a counter-clockwise orientation for their
exterior ring, and a clockwise orientation for their interior rings (or
the oppposite if ``exterior_cw=True``).
Also processes geometries inside a GeometryCollection in the same way.
Other geometries are returned unchanged.
.. versionadded:: 2.1.0
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to orient consistently.
exterior_cw : bool, default False
If True, exterior rings will be clockwise and interior rings
will be counter-clockwise.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
A polygon with both shell and hole having clockwise orientation:
>>> from shapely import Polygon, orient_polygons
>>> polygon = Polygon(
... [(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)],
... holes=[[(2, 2), (2, 4), (4, 4), (4, 2), (2, 2)]],
... )
>>> polygon
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0), (2 2, 2 4, 4 4, 4 2, 2 2))>
By default, the exterior ring is oriented counter-clockwise and
the holes clockwise:
>>> orient_polygons(polygon)
<POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (2 2, 2 4, 4 4, 4 2, 2 2))>
Asking for the opposite orientation:
>>> orient_polygons(polygon, exterior_cw=True)
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0), (2 2, 4 2, 4 4, 2 4, 2 2))>
shapely.oriented_envelope
Python Library Documentation: function oriented_envelope in module shapely.constructive
oriented_envelope(geometry, **kwargs)
Compute the oriented envelope (minimum rotated rectangle) of the input 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
:func:`~shapely.normalize` to reorganize the rectangle to
:ref:`strict canonical form <canonical-form>` so the starting point is
always the lower left point.
``minimum_rotated_rectangle`` is an alias for ``oriented_envelope``.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the oriented envelope.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, LineString, MultiPoint, Point, Polygon
>>> shapely.oriented_envelope(MultiPoint([(0, 0), (10, 0), (10, 10)])).normalize()
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))>
>>> shapely.oriented_envelope(LineString([(1, 1), (5, 1), (10, 10)])).normalize()
<POLYGON ((1 1, 10 10, 12 8, 3 -1, 1 1))>
>>> shapely.oriented_envelope(Polygon([(1, 1), (15, 1), (5, 10), (1, 1)])).normalize()
<POLYGON ((1 1, 5 10, 16.691 4.804, 12.691 -4.196, 1 1))>
>>> shapely.oriented_envelope(LineString([(1, 1), (10, 1)])).normalize()
<LINESTRING (1 1, 10 1)>
>>> shapely.oriented_envelope(Point(2, 2))
<POINT (2 2)>
>>> shapely.oriented_envelope(GeometryCollection([]))
<POLYGON EMPTY>
shapely.overlaps
Python Library Documentation: function overlaps in module shapely.predicates
overlaps(a, b, **kwargs)
Return True if A and B spatially overlap.
A and B overlap if they have some but not all points/space in
common, have the same dimension, and the intersection of the
interiors of the two geometries has the same dimension as the
geometries themselves. That is, only polyons can overlap other
polygons and only lines can overlap other lines. If A covers or is
within B, overlaps won't be True.
If either A or B are None, the output is always False.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword
arguments.
See Also
--------
prepare : improve performance by preparing ``a`` (the first argument)
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point, Polygon
>>> poly = Polygon([(0, 0), (0, 4), (4, 4), (4, 0), (0, 0)])
>>> # A and B share all points (are spatially equal):
>>> shapely.overlaps(poly, poly)
False
>>> # A contains B; all points of B are within A:
>>> shapely.overlaps(poly, Polygon([(0, 0), (0, 2), (2, 2), (2, 0), (0, 0)]))
False
>>> # A partially overlaps with B:
>>> shapely.overlaps(poly, Polygon([(2, 2), (2, 6), (6, 6), (6, 2), (2, 2)]))
True
>>> line = LineString([(2, 2), (6, 6)])
>>> # A and B are different dimensions; they cannot overlap:
>>> shapely.overlaps(poly, line)
False
>>> shapely.overlaps(poly, Point(2, 2))
False
>>> # A and B share some but not all points:
>>> shapely.overlaps(line, LineString([(0, 0), (4, 4)]))
True
>>> # A and B intersect only at a point (lower dimension); they do not overlap
>>> shapely.overlaps(line, LineString([(6, 0), (0, 6)]))
False
>>> shapely.overlaps(poly, None)
False
>>> shapely.overlaps(None, None)
False
shapely.point_on_surface
Python Library Documentation: function point_on_surface in module shapely.constructive
point_on_surface(geometry, **kwargs)
Return a point that intersects an input geometry.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute a point on the surface.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, MultiPoint, Polygon
>>> shapely.point_on_surface(Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)]))
<POINT (5 5)>
>>> shapely.point_on_surface(LineString([(0, 0), (2, 2), (10, 10)]))
<POINT (2 2)>
>>> shapely.point_on_surface(MultiPoint([(0, 0), (10, 10)]))
<POINT (0 0)>
>>> shapely.point_on_surface(Polygon())
<POINT EMPTY>
shapely.points
Python Library Documentation: function points in module shapely.creation
points(coords, y=None, z=None, indices=None, *, handle_nan=<HandleNaN.allow: 0>, out=None, **kwargs)
Create an array of points.
Parameters
----------
coords : array_like
An array of coordinate tuples (2- or 3-dimensional) or, if ``y`` is
provided, an array of x coordinates.
y : array_like, optional
An array of y coordinates.
z : array_like, optional
An array of z coordinates.
indices : array_like, optional
Indices into the target array where input coordinates belong. If
provided, the coords should be 2D with shape (N, 2) or (N, 3) and
indices should be an array of shape (N,) with integers in increasing
order. Missing indices result in a ValueError unless ``out`` is
provided, in which case the original value in ``out`` is kept.
handle_nan : shapely.HandleNaN or {'allow', 'skip', 'error'}, default 'allow'
Specifies what to do when a NaN or Inf is encountered in the coordinates:
- 'allow': the geometries are created with NaN or Inf coordinates.
Note that this can result in unexpected behaviour in subsequent
operations, and generally it is discouraged to have non-finite
coordinate values. One can use this option if you know all
coordinates are finite and want to avoid the overhead of checking
for this.
- 'skip': if any of x, y or z values are NaN or Inf, an empty point
will be created.
- 'error': if any NaN or Inf is detected in the coordinates, a ValueError
is raised. This option ensures that the created geometries have all
finite coordinate values.
.. versionadded:: 2.1.0
out : ndarray, optional
An array (with dtype object) to output the geometries into.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Ignored if ``indices`` is provided.
Examples
--------
>>> import shapely
>>> shapely.points([[0, 1], [4, 5]]).tolist()
[<POINT (0 1)>, <POINT (4 5)>]
>>> shapely.points([0, 1, 2])
<POINT Z (0 1 2)>
Notes
-----
- GEOS 3.10, 3.11 and 3.12 automatically converts POINT (nan nan) to POINT EMPTY.
- GEOS 3.10 and 3.11 will transform a 3D point to 2D if its Z coordinate is NaN.
- Usage of the ``y`` and ``z`` arguments will prevents lazy evaluation in
``dask``. Instead provide the coordinates as an array with shape
``(..., 2)`` or ``(..., 3)`` using only the ``coords`` argument.
shapely.polygonize
Python Library Documentation: function polygonize in module shapely.constructive
polygonize(geometries, **kwargs)
Create polygons formed from the linework of a set of Geometries.
Polygonizes an array of Geometries that contain linework which
represents the edges of a planar graph. Any type of Geometry may be
provided as input; only the constituent lines and rings will be used to
create the output polygons.
Lines or rings that when combined do not completely close a polygon
will result in an empty GeometryCollection. Duplicate segments are
ignored.
This function returns the polygons within a GeometryCollection.
Individual Polygons can be obtained using ``get_geometry`` to get
a single polygon or ``get_parts`` to get an array of polygons.
MultiPolygons can be constructed from the output using
``shapely.multipolygons(shapely.get_parts(shapely.polygonize(geometries)))``.
Parameters
----------
geometries : array_like
An array of geometries.
axis : int
Axis along which the geometries are polygonized.
The default is to perform a reduction over the last dimension
of the input array. A 1D array results in a scalar geometry.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Returns
-------
GeometryCollection or array of GeometryCollections
See Also
--------
get_parts, get_geometry
polygonize_full
node
Examples
--------
>>> import shapely
>>> from shapely import LineString
>>> lines = [
... LineString([(0, 0), (1, 1)]),
... LineString([(0, 0), (0, 1)]),
... LineString([(0, 1), (1, 1)])
... ]
>>> shapely.polygonize(lines)
<GEOMETRYCOLLECTION (POLYGON ((1 1, 0 0, 0 1, 1 1)))>
shapely.polygonize_full
Python Library Documentation: function polygonize_full in module shapely.constructive
polygonize_full(geometries, **kwargs)
Create polygons formed from the linework of a set of Geometries.
All extra outputs are returned as well.
Polygonizes an array of Geometries that contain linework which
represents the edges of a planar graph. Any type of Geometry may be
provided as input; only the constituent lines and rings will be used to
create the output polygons.
This function performs the same polygonization as ``polygonize`` but does
not only return the polygonal result but all extra outputs as well. The
return value consists of 4 elements:
* The polygonal valid output
* **Cut edges**: edges connected on both ends but not part of polygonal output
* **dangles**: edges connected on one end but not part of polygonal output
* **invalid rings**: polygons formed but which are not valid
This function returns the geometries within GeometryCollections.
Individual geometries can be obtained using ``get_geometry`` to get
a single geometry or ``get_parts`` to get an array of geometries.
Parameters
----------
geometries : array_like
An array of geometries.
axis : int
Axis along which the geometries are polygonized.
The default is to perform a reduction over the last dimension
of the input array. A 1D array results in a scalar geometry.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Returns
-------
(polygons, cuts, dangles, invalid)
tuple of 4 GeometryCollections or arrays of GeometryCollections
See Also
--------
polygonize
Examples
--------
>>> import shapely
>>> from shapely import LineString
>>> lines = [
... LineString([(0, 0), (1, 1)]),
... LineString([(0, 0), (0, 1), (1, 1)]),
... LineString([(0, 1), (1, 1)])
... ]
>>> shapely.polygonize_full(lines)
(<GEOMETRYCOLLECTION (POLYGON ((1 1, 0 0, 0 1, 1 1)))>,
<GEOMETRYCOLLECTION EMPTY>,
<GEOMETRYCOLLECTION (LINESTRING (0 1, 1 1))>,
<GEOMETRYCOLLECTION EMPTY>)
shapely.polygons
Python Library Documentation: function polygons in module shapely.creation
polygons(geometries, holes=None, indices=None, *, out=None, **kwargs)
Create an array of polygons.
Parameters
----------
geometries : array_like
An array of linearrings or coordinates (see linearrings).
Unless ``indices`` are given (see description below), this
include the outer shells only. The ``holes`` argument should be used
to create polygons with holes.
holes : array_like, optional
An array of lists of linearrings that constitute holes for each shell.
Not to be used in combination with ``indices``.
indices : array_like, optional
Indices into the target array where input geometries belong. If
provided, the holes are expected to be present inside ``geometries``;
the first geometry for each index is the outer shell
and all subsequent geometries in that index are the holes.
Both geometries and indices should be 1D and have matching sizes.
Indices should be in increasing order. Missing indices result in a
ValueError unless ``out`` is provided, in which case the original value
in ``out`` is kept.
out : ndarray, optional
An array (with dtype object) to output the geometries into.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Ignored if ``indices`` is provided.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``indices`` is specified as a
positional argument. This will need to be specified as a keyword
argument in a future release.
Examples
--------
>>> import shapely
Polygons are constructed from rings:
>>> ring_1 = shapely.linearrings([[0, 0], [0, 10], [10, 10], [10, 0]])
>>> ring_2 = shapely.linearrings([[2, 6], [2, 7], [3, 7], [3, 6]])
>>> shapely.polygons([ring_1, ring_2])[0]
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))>
>>> shapely.polygons([ring_1, ring_2])[1]
<POLYGON ((2 6, 2 7, 3 7, 3 6, 2 6))>
Or from coordinates directly:
>>> shapely.polygons([[0, 0], [0, 10], [10, 10], [10, 0]])
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))>
Adding holes can be done using the ``holes`` keyword argument:
>>> shapely.polygons(ring_1, holes=[ring_2])
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0), (2 6, 2 7, 3 7, 3 6, 2 6))>
Or using the ``indices`` argument:
>>> shapely.polygons([ring_1, ring_2], indices=[0, 1])[0]
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))>
>>> shapely.polygons([ring_1, ring_2], indices=[0, 1])[1]
<POLYGON ((2 6, 2 7, 3 7, 3 6, 2 6))>
>>> shapely.polygons([ring_1, ring_2], indices=[0, 0])[0]
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0), (2 6, 2 7, 3 7, 3 6, 2 6))>
Missing input values (``None``) are skipped and may result in an
empty polygon:
>>> shapely.polygons(None)
<POLYGON EMPTY>
>>> shapely.polygons(ring_1, holes=[None])
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))>
>>> shapely.polygons([ring_1, None], indices=[0, 0])[0]
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))>
shapely.predicates
Python Library Documentation: module shapely.predicates in shapely
NAME
shapely.predicates - Predicates for spatial analysis.
FUNCTIONS
contains(a, b, **kwargs)
Return True if geometry B is completely inside geometry A.
A contains B if no points of B lie in the exterior of A and at least one
point of the interior of B lies in the interior of A.
Note: following this definition, a geometry does not contain its boundary,
but it does contain itself. See ``contains_properly`` for a version where
a geometry does not contain itself.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
within : ``contains(A, B) == within(B, A)``
contains_properly : contains with no common boundary points
prepare : improve performance by preparing ``a`` (the first argument)
contains_xy : variant for checking against a Point with x, y coordinates
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point, Polygon
>>> line = LineString([(0, 0), (1, 1)])
>>> shapely.contains(line, Point(0, 0))
False
>>> shapely.contains(line, Point(0.5, 0.5))
True
>>> area = Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)])
>>> shapely.contains(area, Point(0, 0))
False
>>> shapely.contains(area, line)
True
>>> shapely.contains(area, LineString([(0, 0), (2, 2)]))
False
>>> polygon_with_hole = Polygon(
... [(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)],
... holes=[[(2, 2), (2, 4), (4, 4), (4, 2), (2, 2)]]
... )
>>> shapely.contains(polygon_with_hole, Point(1, 1))
True
>>> shapely.contains(polygon_with_hole, Point(2, 2))
False
>>> shapely.contains(polygon_with_hole, LineString([(1, 1), (5, 5)]))
False
>>> shapely.contains(area, area)
True
>>> shapely.contains(area, None)
False
contains_properly(a, b, **kwargs)
Return True if geometry B is completely inside geometry A, with no common
boundary points.
A contains B properly if B intersects the interior of A but not the
boundary (or exterior). This means that a geometry A does not
"contain properly" itself, which contrasts with the ``contains`` function,
where common points on the boundary are allowed.
Note: this function will prepare the geometries under the hood if needed.
You can prepare the geometries in advance to avoid repeated preparation
when calling this function multiple times.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
contains : contains which allows common boundary points
prepare : improve performance by preparing ``a`` (the first argument)
Examples
--------
>>> import shapely
>>> from shapely import Polygon
>>> area1 = Polygon([(0, 0), (3, 0), (3, 3), (0, 3), (0, 0)])
>>> area2 = Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)])
>>> area3 = Polygon([(1, 1), (2, 1), (2, 2), (1, 2), (1, 1)])
``area1`` and ``area2`` have a common border:
>>> shapely.contains(area1, area2)
True
>>> shapely.contains_properly(area1, area2)
False
``area3`` is completely inside ``area1`` with no common border:
>>> shapely.contains(area1, area3)
True
>>> shapely.contains_properly(area1, area3)
True
contains_xy(geom, x, y=None, **kwargs)
Return True if the Point (x, y) is completely inside geom.
This is a special-case (and faster) variant of the `contains` function
which avoids having to create a Point object if you start from x/y
coordinates.
Note that in the case of points, the `contains_properly` predicate is
equivalent to `contains`.
See the docstring of `contains` for more details about the predicate.
Parameters
----------
geom : Geometry or array_like
Geometry or geometries to check if they contain the point.
x, y : float or array_like
Coordinates as separate x and y arrays, or a single array of
coordinate x, y tuples.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
contains : variant taking two geometries as input
Notes
-----
If you compare a small number of polygons or lines with many points,
it can be beneficial to prepare the geometries in advance using
:func:`shapely.prepare`.
Examples
--------
>>> import shapely
>>> from shapely import Point, Polygon
>>> area = Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)])
>>> shapely.contains(area, Point(0.5, 0.5))
True
>>> shapely.contains_xy(area, 0.5, 0.5)
True
covered_by(a, b, **kwargs)
Return True if no point in geometry A is outside geometry B.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
covers : ``covered_by(A, B) == covers(B, A)``
prepare : improve performance by preparing ``a`` (the first argument)
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point, Polygon
>>> line = LineString([(0, 0), (1, 1)])
>>> shapely.covered_by(Point(0, 0), line)
True
>>> shapely.covered_by(Point(0.5, 0.5), line)
True
>>> area = Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)])
>>> shapely.covered_by(Point(0, 0), area)
True
>>> shapely.covered_by(line, area)
True
>>> shapely.covered_by(LineString([(0, 0), (2, 2)]), area)
False
>>> polygon_with_hole = Polygon(
... [(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)],
... holes=[[(2, 2), (2, 4), (4, 4), (4, 2), (2, 2)]]
... )
>>> shapely.covered_by(Point(1, 1), polygon_with_hole)
True
>>> shapely.covered_by(Point(2, 2), polygon_with_hole)
True
>>> shapely.covered_by(LineString([(1, 1), (5, 5)]), polygon_with_hole)
False
>>> shapely.covered_by(area, area)
True
>>> shapely.covered_by(None, area)
False
covers(a, b, **kwargs)
Return True if no point in geometry B is outside geometry A.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
covered_by : ``covers(A, B) == covered_by(B, A)``
prepare : improve performance by preparing ``a`` (the first argument)
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point, Polygon
>>> line = LineString([(0, 0), (1, 1)])
>>> shapely.covers(line, Point(0, 0))
True
>>> shapely.covers(line, Point(0.5, 0.5))
True
>>> area = Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)])
>>> shapely.covers(area, Point(0, 0))
True
>>> shapely.covers(area, line)
True
>>> shapely.covers(area, LineString([(0, 0), (2, 2)]))
False
>>> polygon_with_hole = Polygon(
... [(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)],
... holes=[[(2, 2), (2, 4), (4, 4), (4, 2), (2, 2)]]
... )
>>> shapely.covers(polygon_with_hole, Point(1, 1))
True
>>> shapely.covers(polygon_with_hole, Point(2, 2))
True
>>> shapely.covers(polygon_with_hole, LineString([(1, 1), (5, 5)]))
False
>>> shapely.covers(area, area)
True
>>> shapely.covers(area, None)
False
crosses(a, b, **kwargs)
Return True if A and B spatially cross.
A crosses B if they have some but not all interior points in common,
the intersection is one dimension less than the maximum dimension of A or B,
and the intersection is not equal to either A or B.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
prepare : improve performance by preparing ``a`` (the first argument)
Examples
--------
>>> import shapely
>>> from shapely import LineString, MultiPoint, Point, Polygon
>>> line = LineString([(0, 0), (1, 1)])
>>> # A contains B:
>>> shapely.crosses(line, Point(0.5, 0.5))
False
>>> # A and B intersect at a point but do not share all points:
>>> shapely.crosses(line, MultiPoint([(0, 1), (0.5, 0.5)]))
True
>>> shapely.crosses(line, LineString([(0, 1), (1, 0)]))
True
>>> # A is contained by B; their intersection is a line (same dimension):
>>> shapely.crosses(line, LineString([(0, 0), (2, 2)]))
False
>>> area = Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)])
>>> # A contains B:
>>> shapely.crosses(area, line)
False
>>> # A and B intersect with a line (lower dimension) but do not share all points:
>>> shapely.crosses(area, LineString([(0, 0), (2, 2)]))
True
>>> # A contains B:
>>> shapely.crosses(area, Point(0.5, 0.5))
False
>>> # A contains some but not all points of B; they intersect at a point:
>>> shapely.crosses(area, MultiPoint([(2, 2), (0.5, 0.5)]))
True
disjoint(a, b, **kwargs)
Return True if A and B do not share any point in space.
Disjoint implies that overlaps, touches, within, and intersects are False.
Note missing (None) values are never disjoint.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
intersects : ``disjoint(A, B) == ~intersects(A, B)``
prepare : improve performance by preparing ``a`` (the first argument)
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, LineString, Point
>>> line = LineString([(0, 0), (1, 1)])
>>> shapely.disjoint(line, Point(0, 0))
False
>>> shapely.disjoint(line, Point(0, 1))
True
>>> shapely.disjoint(line, LineString([(0, 2), (2, 0)]))
False
>>> empty = GeometryCollection()
>>> shapely.disjoint(line, empty)
True
>>> shapely.disjoint(empty, empty)
True
>>> shapely.disjoint(empty, None)
False
>>> shapely.disjoint(None, None)
False
dwithin(a, b, distance, **kwargs)
Return True if the geometries are within a given distance.
Using this function is more efficient than computing the distance and
comparing the result.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
distance : float
Negative distances always return False.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
distance : compute the actual distance between A and B
prepare : improve performance by preparing ``a`` (the first argument)
Examples
--------
>>> import shapely
>>> from shapely import Point
>>> point = Point(0.5, 0.5)
>>> shapely.dwithin(point, Point(2, 0.5), 2)
True
>>> shapely.dwithin(point, Point(2, 0.5), [2, 1.5, 1]).tolist()
[True, True, False]
>>> shapely.dwithin(point, Point(0.5, 0.5), 0)
True
>>> shapely.dwithin(point, None, 100)
False
equals(a, b, **kwargs)
Return True if A and B are spatially equal.
If A is within B and B is within A, A and B are considered equal. The
ordering of points can be different.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
equals_exact : Check if A and B are structurally equal given a specified
tolerance.
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, LineString, Polygon
>>> line = LineString([(0, 0), (5, 5), (10, 10)])
>>> shapely.equals(line, LineString([(0, 0), (10, 10)]))
True
>>> shapely.equals(Polygon(), GeometryCollection())
True
>>> shapely.equals(None, None)
False
equals_exact(a, b, tolerance=0.0, *, normalize=False, **kwargs)
Return True if the geometries are structurally equivalent within a given
tolerance.
This method uses exact coordinate equality, which requires coordinates
to be equal (within specified tolerance) and in the same order for
all components (vertices, rings, or parts) of a geometry. This is in
contrast with the :func:`equals` function which uses spatial
(topological) equality and does not require all components to be in the
same order. Because of this, it is possible for :func:`equals` to
be ``True`` while :func:`equals_exact` is ``False``.
The order of the coordinates can be normalized (by setting the `normalize`
keyword to ``True``) so that this function will return ``True`` when geometries
are structurally equivalent but differ only in the ordering of vertices.
However, this function will still return ``False`` if the order of interior
rings within a :class:`Polygon` or the order of geometries within a multi
geometry are different.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
tolerance : float or array_like (default: 0.)
The tolerance to use in the comparison.
normalize : bool, optional (default: False)
If True, normalize the two geometries so that the coordinates are
in the same order.
.. versionadded:: 2.1.0
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
equals : Check if `a` and `b` are spatially (topologically) equal.
Examples
--------
>>> import shapely
>>> from shapely import Point, Polygon
>>> point1 = Point(50, 50)
>>> point2 = Point(50.1, 50.1)
>>> shapely.equals_exact(point1, point2)
False
>>> shapely.equals_exact(point1, point2, tolerance=0.2)
True
>>> shapely.equals_exact(point1, None, tolerance=0.2)
False
Difference between structural and spatial equality:
>>> polygon1 = Polygon([(0, 0), (1, 1), (0, 1), (0, 0)])
>>> polygon2 = Polygon([(0, 0), (0, 1), (1, 1), (0, 0)])
>>> shapely.equals_exact(polygon1, polygon2)
False
>>> shapely.equals(polygon1, polygon2)
True
equals_identical(a, b, **kwargs)
Return True if the geometries are identical.
This function verifies whether geometries are pointwise equivalent by checking
that the structure, ordering, and values of all vertices are identical
in all dimensions.
Similarly to :func:`equals_exact`, this function uses exact coordinate
equality and requires coordinates to be in the same order for all
components (vertices, rings, or parts) of a geometry. However, in
contrast :func:`equals_exact`, this function does not allow to specify
a tolerance, but does require all dimensions to be the same
(:func:`equals_exact` ignores the Z and M dimensions), and NaN values
are considered to be equal to other NaN values.
This function is the vectorized equivalent of scalar equality of
geometry objects (``a == b``, i.e. ``__eq__``).
.. versionadded:: 2.1.0
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
equals_exact : Check if geometries are structurally equal given a specified
tolerance.
equals : Check if geometries are spatially (topologically) equal.
Examples
--------
>>> import shapely
>>> from shapely import Point
>>> shapely.equals_identical(Point(1, 2, 3), Point(1, 2, 3))
True
>>> shapely.equals_identical(Point(1, 2, 3), Point(1, 2, 0))
False
has_m(geometry, **kwargs)
Return True if a geometry has M coordinates.
.. versionadded:: 2.1.0
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to check for M coordinates.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
get_coordinate_dimension, has_z
Examples
--------
>>> import shapely
>>> shapely.has_m(shapely.from_wkt("POINT (0 0)"))
False
>>> shapely.has_m(shapely.from_wkt("POINT Z (0 0 0)"))
False
>>> shapely.has_m(shapely.from_wkt("POINT M (0 0 0)"))
True
>>> shapely.has_m(shapely.from_wkt("POINT ZM (0 0 0 0)"))
True
has_z(geometry, **kwargs)
Return True if a geometry has Z coordinates.
Note that for GEOS < 3.12 this function returns False if the (first) Z coordinate
equals NaN.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to check for Z coordinates.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
get_coordinate_dimension, has_m
Examples
--------
>>> import shapely
>>> from shapely import Point
>>> shapely.has_z(Point(0, 0))
False
>>> shapely.has_z(Point(0, 0, 0))
True
>>> shapely.has_z(Point())
False
intersects(a, b, **kwargs)
Return True if A and B share any portion of space.
Intersects implies that overlaps, touches, covers, or within are True.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
disjoint : ``intersects(A, B) == ~disjoint(A, B)``
prepare : improve performance by preparing ``a`` (the first argument)
intersects_xy : variant for checking against a Point with x, y coordinates
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> line = LineString([(0, 0), (1, 1)])
>>> shapely.intersects(line, Point(0, 0))
True
>>> shapely.intersects(line, Point(0, 1))
False
>>> shapely.intersects(line, LineString([(0, 2), (2, 0)]))
True
>>> shapely.intersects(None, None)
False
intersects_xy(geom, x, y=None, **kwargs)
Return True if geom and the Point (x, y) share any portion of space.
This is a special-case (and faster) variant of the `intersects` function
which avoids having to create a Point object if you start from x/y
coordinates.
See the docstring of `intersects` for more details about the predicate.
Parameters
----------
geom : Geometry or array_like
Geometry or geometries to check if they intersect with the point.
x, y : float or array_like
Coordinates as separate x and y arrays, or a single array of
coordinate x, y tuples.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
intersects : variant taking two geometries as input
Notes
-----
If you compare a single or few geometries with many points, it can be
beneficial to prepare the geometries in advance using
:func:`shapely.prepare`.
The `touches` predicate can be determined with this function by getting
the boundary of the geometries: ``intersects_xy(boundary(geom), x, y)``.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> line = LineString([(0, 0), (1, 1)])
>>> shapely.intersects(line, Point(0, 0))
True
>>> shapely.intersects_xy(line, 0, 0)
True
is_ccw(geometry, **kwargs)
Return True if a linestring or linearring is counterclockwise.
Note that there are no checks on whether lines are actually closed and
not self-intersecting, while this is a requirement for is_ccw. The recommended
usage of this function for linestrings is ``is_ccw(g) & is_simple(g)`` and for
linearrings ``is_ccw(g) & is_valid(g)``.
Parameters
----------
geometry : Geometry or array_like
This function will return False for non-linear geometries and for
lines with fewer than 4 points (including the closing point).
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
is_simple : Checks if a linestring is closed and simple.
is_valid : Checks additionally if the geometry is simple.
Examples
--------
>>> import shapely
>>> from shapely import LinearRing, LineString, Point
>>> shapely.is_ccw(LinearRing([(0, 0), (0, 1), (1, 1), (0, 0)]))
False
>>> shapely.is_ccw(LinearRing([(0, 0), (1, 1), (0, 1), (0, 0)]))
True
>>> shapely.is_ccw(LineString([(0, 0), (1, 1), (0, 1)]))
False
>>> shapely.is_ccw(Point(0, 0))
False
is_closed(geometry, **kwargs)
Return True if a linestring's first and last points are equal.
Parameters
----------
geometry : Geometry or array_like
This function will return False for non-linestrings.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
is_ring : Checks additionally if the geometry is simple.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> shapely.is_closed(LineString([(0, 0), (1, 1)]))
False
>>> shapely.is_closed(LineString([(0, 0), (0, 1), (1, 1), (0, 0)]))
True
>>> shapely.is_closed(Point(0, 0))
False
is_empty(geometry, **kwargs)
Return True if a geometry is an empty point, polygon, etc.
Parameters
----------
geometry : Geometry or array_like
Any geometry type is accepted.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
is_missing : checks if the object is a geometry
Examples
--------
>>> import shapely
>>> from shapely import Point
>>> shapely.is_empty(Point())
True
>>> shapely.is_empty(Point(0, 0))
False
>>> shapely.is_empty(None)
False
is_geometry(geometry, **kwargs)
Return True if the object is a geometry.
Parameters
----------
geometry : any object or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
is_missing : check if an object is missing (None)
is_valid_input : check if an object is a geometry or None
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, Point
>>> shapely.is_geometry(Point(0, 0))
True
>>> shapely.is_geometry(GeometryCollection())
True
>>> shapely.is_geometry(None)
False
>>> shapely.is_geometry("text")
False
is_missing(geometry, **kwargs)
Return True if the object is not a geometry (None).
Parameters
----------
geometry : any object or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
is_geometry : check if an object is a geometry
is_valid_input : check if an object is a geometry or None
is_empty : checks if the object is an empty geometry
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, Point
>>> shapely.is_missing(Point(0, 0))
False
>>> shapely.is_missing(GeometryCollection())
False
>>> shapely.is_missing(None)
True
>>> shapely.is_missing("text")
False
is_prepared(geometry, **kwargs)
Return True if a Geometry is prepared.
Note that it is not necessary to check if a geometry is already prepared
before preparing it. It is more efficient to call ``prepare`` directly
because it will skip geometries that are already prepared.
This function will return False for missing geometries (None).
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
is_valid_input : check if an object is a geometry or None
prepare : prepare a geometry
Examples
--------
>>> import shapely
>>> from shapely import Point
>>> geometry = Point(0, 0)
>>> shapely.is_prepared(Point(0, 0))
False
>>> shapely.prepare(geometry)
>>> shapely.is_prepared(geometry)
True
>>> shapely.is_prepared(None)
False
is_ring(geometry, **kwargs)
Return True if a linestring is closed and simple.
This function will return False for non-linestrings.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
is_closed : Checks only if the geometry is closed.
is_simple : Checks only if the geometry is simple.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> shapely.is_ring(Point(0, 0))
False
>>> geom = LineString([(0, 0), (1, 1)])
>>> shapely.is_closed(geom), shapely.is_simple(geom), shapely.is_ring(geom)
(False, True, False)
>>> geom = LineString([(0, 0), (0, 1), (1, 1), (0, 0)])
>>> shapely.is_closed(geom), shapely.is_simple(geom), shapely.is_ring(geom)
(True, True, True)
>>> geom = LineString([(0, 0), (1, 1), (0, 1), (1, 0), (0, 0)])
>>> shapely.is_closed(geom), shapely.is_simple(geom), shapely.is_ring(geom)
(True, False, False)
is_simple(geometry, **kwargs)
Return True if the geometry is simple.
A simple geometry has no anomalous geometric points, such as
self-intersections or self tangency.
Note that polygons and linearrings are assumed to be simple. Use is_valid
to check these kind of geometries for self-intersections.
This function will return False for geometrycollections.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
is_ring : Checks additionally if the geometry is closed.
is_valid : Checks whether a geometry is well formed.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Polygon
>>> shapely.is_simple(Polygon([(1, 1), (2, 1), (2, 2), (1, 1)]))
True
>>> shapely.is_simple(LineString([(0, 0), (1, 1), (0, 1), (1, 0), (0, 0)]))
False
>>> shapely.is_simple(None)
False
is_valid(geometry, **kwargs)
Return True if a geometry is well formed.
Returns False for missing values.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to check. Any geometry type is accepted.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
is_valid_reason : Returns the reason in case of invalid.
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, LineString, Polygon
>>> shapely.is_valid(LineString([(0, 0), (1, 1)]))
True
>>> shapely.is_valid(Polygon([(0, 0), (1, 1), (1, 2), (1, 1), (0, 0)]))
False
>>> shapely.is_valid(GeometryCollection())
True
>>> shapely.is_valid(None)
False
is_valid_input(geometry, **kwargs)
Return True if the object is a geometry or None.
Parameters
----------
geometry : any object or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
is_geometry : checks if an object is a geometry
is_missing : checks if an object is None
Examples
--------
>>> import shapely
>>> from shapely import GeometryCollection, Point
>>> shapely.is_valid_input(Point(0, 0))
True
>>> shapely.is_valid_input(GeometryCollection())
True
>>> shapely.is_valid_input(None)
True
>>> shapely.is_valid_input(1.0)
False
>>> shapely.is_valid_input("text")
False
is_valid_reason(geometry, **kwargs)
Return a string stating if a geometry is valid and if not, why.
Returns None for missing values.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to check. Any geometry type is accepted.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
is_valid : returns True or False
Examples
--------
>>> import shapely
>>> from shapely import LineString, Polygon
>>> shapely.is_valid_reason(LineString([(0, 0), (1, 1)]))
'Valid Geometry'
>>> shapely.is_valid_reason(Polygon([(0, 0), (1, 1), (1, 2), (1, 1), (0, 0)]))
'Self-intersection[1 2]'
>>> shapely.is_valid_reason(None) is None
True
overlaps(a, b, **kwargs)
Return True if A and B spatially overlap.
A and B overlap if they have some but not all points/space in
common, have the same dimension, and the intersection of the
interiors of the two geometries has the same dimension as the
geometries themselves. That is, only polyons can overlap other
polygons and only lines can overlap other lines. If A covers or is
within B, overlaps won't be True.
If either A or B are None, the output is always False.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword
arguments.
See Also
--------
prepare : improve performance by preparing ``a`` (the first argument)
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point, Polygon
>>> poly = Polygon([(0, 0), (0, 4), (4, 4), (4, 0), (0, 0)])
>>> # A and B share all points (are spatially equal):
>>> shapely.overlaps(poly, poly)
False
>>> # A contains B; all points of B are within A:
>>> shapely.overlaps(poly, Polygon([(0, 0), (0, 2), (2, 2), (2, 0), (0, 0)]))
False
>>> # A partially overlaps with B:
>>> shapely.overlaps(poly, Polygon([(2, 2), (2, 6), (6, 6), (6, 2), (2, 2)]))
True
>>> line = LineString([(2, 2), (6, 6)])
>>> # A and B are different dimensions; they cannot overlap:
>>> shapely.overlaps(poly, line)
False
>>> shapely.overlaps(poly, Point(2, 2))
False
>>> # A and B share some but not all points:
>>> shapely.overlaps(line, LineString([(0, 0), (4, 4)]))
True
>>> # A and B intersect only at a point (lower dimension); they do not overlap
>>> shapely.overlaps(line, LineString([(6, 0), (0, 6)]))
False
>>> shapely.overlaps(poly, None)
False
>>> shapely.overlaps(None, None)
False
relate(a, b, **kwargs)
Return a string representation of the DE-9IM intersection matrix.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> point = Point(0, 0)
>>> line = LineString([(0, 0), (1, 1)])
>>> shapely.relate(point, line)
'F0FFFF102'
relate_pattern(a, b, pattern, **kwargs)
Return True if the DE-9IM relationship code satisfies the pattern.
This function compares the DE-9IM code string for two geometries
against a specified pattern. If the string matches the pattern then
``True`` is returned, otherwise ``False``. The pattern specified can
be an exact match (``0``, ``1`` or ``2``), a boolean match
(uppercase ``T`` or ``F``), or a wildcard (``*``). For example,
the pattern for the ``within`` predicate is ``'T*F**F***'``.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
pattern : string
The pattern to match the DE-9IM relationship code against.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import Point, Polygon
>>> point = Point(0.5, 0.5)
>>> square = Polygon([(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)])
>>> shapely.relate(point, square)
'0FFFFF212'
>>> shapely.relate_pattern(point, square, "T*F**F***")
True
touches(a, b, **kwargs)
Return True if the only points shared between A and B are on their boundaries.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
prepare : improve performance by preparing ``a`` (the first argument)
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point, Polygon
>>> line = LineString([(0, 2), (2, 0)])
>>> shapely.touches(line, Point(0, 2))
True
>>> shapely.touches(line, Point(1, 1))
False
>>> shapely.touches(line, LineString([(0, 0), (1, 1)]))
True
>>> shapely.touches(line, LineString([(0, 0), (2, 2)]))
False
>>> area = Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)])
>>> shapely.touches(area, Point(0.5, 0))
True
>>> shapely.touches(area, Point(0.5, 0.5))
False
>>> shapely.touches(area, line)
True
>>> shapely.touches(area, Polygon([(0, 1), (1, 1), (1, 2), (0, 2), (0, 1)]))
True
within(a, b, **kwargs)
Return True if geometry A is completely inside geometry B.
A is within B if no points of A lie in the exterior of B and at least one
point of the interior of A lies in the interior of B.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
contains : ``within(A, B) == contains(B, A)``
prepare : improve performance by preparing ``a`` (the first argument)
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point, Polygon
>>> line = LineString([(0, 0), (1, 1)])
>>> shapely.within(Point(0, 0), line)
False
>>> shapely.within(Point(0.5, 0.5), line)
True
>>> area = Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)])
>>> shapely.within(Point(0, 0), area)
False
>>> shapely.within(line, area)
True
>>> shapely.within(LineString([(0, 0), (2, 2)]), area)
False
>>> polygon_with_hole = Polygon(
... [(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)],
... holes=[[(2, 2), (2, 4), (4, 4), (4, 2), (2, 2)]]
... )
>>> shapely.within(Point(1, 1), polygon_with_hole)
True
>>> shapely.within(Point(2, 2), polygon_with_hole)
False
>>> shapely.within(LineString([(1, 1), (5, 5)]), polygon_with_hole)
False
>>> shapely.within(area, area)
True
>>> shapely.within(None, area)
False
DATA
__all__ = ['contains', 'contains_properly', 'contains_xy', 'covered_by...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\shapely\predicates.py
shapely.prepare
Python Library Documentation: function prepare in module shapely.creation
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, ``prepare`` should 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 does not return any values; geometries are modified in place.
Parameters
----------
geometry : Geometry or array_like
Geometries are changed in place
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
is_prepared : Identify whether a geometry is prepared already.
destroy_prepared : Destroy 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)
>>> shapely.contains_properly(poly, [Point(0.0, 0.0), Point(0.5, 0.5)]).tolist()
[False, True]
shapely.relate
Python Library Documentation: function relate in module shapely.predicates
relate(a, b, **kwargs)
Return a string representation of the DE-9IM intersection matrix.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> point = Point(0, 0)
>>> line = LineString([(0, 0), (1, 1)])
>>> shapely.relate(point, line)
'F0FFFF102'
shapely.relate_pattern
Python Library Documentation: function relate_pattern in module shapely.predicates
relate_pattern(a, b, pattern, **kwargs)
Return True if the DE-9IM relationship code satisfies the pattern.
This function compares the DE-9IM code string for two geometries
against a specified pattern. If the string matches the pattern then
``True`` is returned, otherwise ``False``. The pattern specified can
be an exact match (``0``, ``1`` or ``2``), a boolean match
(uppercase ``T`` or ``F``), or a wildcard (``*``). For example,
the pattern for the ``within`` predicate is ``'T*F**F***'``.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
pattern : string
The pattern to match the DE-9IM relationship code against.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import Point, Polygon
>>> point = Point(0.5, 0.5)
>>> square = Polygon([(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)])
>>> shapely.relate(point, square)
'0FFFFF212'
>>> shapely.relate_pattern(point, square, "T*F**F***")
True
shapely.remove_repeated_points
Python Library Documentation: function remove_repeated_points in module shapely.constructive
remove_repeated_points(geometry, tolerance=0.0, **kwargs)
Return a copy of a Geometry with repeated points removed.
From the start of the coordinate sequence, each next point within the
tolerance is removed.
Removing repeated points with a non-zero tolerance may result in an invalid
geometry being returned.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to remove repeated points from.
tolerance : float or array_like, default=0.0
Use 0.0 to remove only exactly repeated points.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Polygon
>>> shapely.remove_repeated_points(LineString([(0,0), (0,0), (1,0)]), tolerance=0)
<LINESTRING (0 0, 1 0)>
>>> shapely.remove_repeated_points(Polygon([(0, 0), (0, .5), (0, 1), (.5, 1), (0,0)]), tolerance=.5)
<POLYGON ((0 0, 0 1, 0 0))>
shapely.reverse
Python Library Documentation: function reverse in module shapely.constructive
reverse(geometry, **kwargs)
Return a copy of a Geometry with the order of coordinates reversed.
If a Geometry is a polygon with interior rings, the interior rings are also
reversed.
Points are unchanged. None is returned where Geometry is None.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to reverse the coordinates of.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
is_ccw : Checks if a Geometry is clockwise.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Polygon
>>> shapely.reverse(LineString([(0, 0), (1, 2)]))
<LINESTRING (1 2, 0 0)>
>>> shapely.reverse(Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]))
<POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
>>> shapely.reverse(None) is None
True
shapely.segmentize
Python Library Documentation: function segmentize in module shapely.constructive
segmentize(geometry, max_segment_length, **kwargs)
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.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to segmentize.
max_segment_length : float or array_like
Additional vertices will be added so that all line segments are no
longer than this value. Must be greater than 0.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Polygon
>>> line = LineString([(0, 0), (0, 10)])
>>> shapely.segmentize(line, max_segment_length=5)
<LINESTRING (0 0, 0 5, 0 10)>
>>> polygon = Polygon([(0, 0), (10, 0), (10, 10), (0, 10), (0, 0)])
>>> shapely.segmentize(polygon, max_segment_length=5)
<POLYGON ((0 0, 5 0, 10 0, 10 5, 10 10, 5 10, 0 10, 0 5, 0 0))>
>>> shapely.segmentize(None, max_segment_length=5) is None
True
shapely.set_coordinates
Python Library Documentation: function set_coordinates in module shapely.coordinates
set_coordinates(geometry, coordinates)
Adapts the coordinates of a geometry array in-place.
If the coordinates array has shape (N, 2), all returned geometries
will be two-dimensional, and the third dimension will be discarded,
if present. If the coordinates array has shape (N, 3), the returned
geometries preserve the dimensionality of the input geometries.
.. warning::
The geometry array is modified in-place! If you do not want to
modify the original array, you can do
``set_coordinates(arr.copy(), newcoords)``.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to set the coordinates of.
coordinates: array_like
An array of coordinates to set.
See Also
--------
transform : Returns a copy of a geometry array with a function applied to its
coordinates.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> shapely.set_coordinates(Point(0, 0), [[1, 1]])
<POINT (1 1)>
>>> shapely.set_coordinates(
... [Point(0, 0), LineString([(0, 0), (0, 0)])],
... [[1, 2], [3, 4], [5, 6]]
... ).tolist()
[<POINT (1 2)>, <LINESTRING (3 4, 5 6)>]
>>> shapely.set_coordinates([None, Point(0, 0)], [[1, 2]]).tolist()
[None, <POINT (1 2)>]
Third dimension of input geometry is discarded if coordinates array does
not include one:
>>> shapely.set_coordinates(Point(0, 0, 0), [[1, 1]])
<POINT (1 1)>
>>> shapely.set_coordinates(Point(0, 0, 0), [[1, 1, 1]])
<POINT Z (1 1 1)>
shapely.set_operations
Python Library Documentation: module shapely.set_operations in shapely
NAME
shapely.set_operations - Set-theoretic operations on geometry objects.
FUNCTIONS
coverage_union(a, b, **kwargs)
Merge multiple polygons into one.
This is an optimized version of union which assumes the polygons to be
non-overlapping.
If this assumption is not met, the exact result is not guaranteed
(depending on the GEOS version, it may return the input unchanged or raise
an error).
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to merge (union).
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
coverage_union_all
Examples
--------
>>> import shapely
>>> from shapely import Polygon
>>> polygon_1 = Polygon([(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)])
>>> polygon_2 = Polygon([(1, 0), (1, 1), (2, 1), (2, 0), (1, 0)])
>>> shapely.coverage_union(polygon_1, polygon_2).normalize()
<POLYGON ((0 0, 0 1, 1 1, 2 1, 2 0, 1 0, 0 0))>
Union with None returns same polygon
>>> shapely.coverage_union(polygon_1, None).normalize()
<POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
coverage_union_all(geometries, axis=None, **kwargs)
Return the union of multiple polygons of a geometry collection.
This is an optimized version of union which assumes the polygons
to be non-overlapping.
This function ignores None values when other Geometry elements are present.
If all elements of the given axis are None, an empty GeometryCollection is
returned (before GEOS 3.12 this was an empty MultiPolygon).
Parameters
----------
geometries : array_like
Geometries to merge/union.
axis : int, optional
Axis along which the operation is performed. The default (None)
performs the operation over all axes, returning a scalar value.
Axis may be negative, in which case it counts from the last to the
first axis.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``axis`` is specified as a
positional argument. This will need to be specified as a keyword
argument in a future release.
See Also
--------
coverage_union
Examples
--------
>>> import shapely
>>> from shapely import Polygon
>>> polygon_1 = Polygon([(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)])
>>> polygon_2 = Polygon([(1, 0), (1, 1), (2, 1), (2, 0), (1, 0)])
>>> shapely.coverage_union_all([polygon_1, polygon_2]).normalize()
<POLYGON ((0 0, 0 1, 1 1, 2 1, 2 0, 1 0, 0 0))>
>>> shapely.coverage_union_all([polygon_1, None]).normalize()
<POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
>>> shapely.coverage_union_all([None, None]).normalize()
<GEOMETRYCOLLECTION EMPTY>
difference(a, b, grid_size=None, **kwargs)
Return the part of geometry A that does not intersect with geometry B.
If grid_size is nonzero, input coordinates will be snapped to a precision
grid of that size and resulting coordinates will be snapped to that same
grid. If 0, this operation will use double precision coordinates. If None,
the highest precision of the inputs will be used, which may be previously
set using set_precision. Note: returned geometry does not have precision
set unless specified previously by set_precision.
Parameters
----------
a : Geometry or array_like
Geometry or geometries to subtract b from.
b : Geometry or array_like
Geometry or geometries to subtract from a.
grid_size : float, optional
Precision grid size; will use the highest precision of the inputs by default.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``grid_size`` is specified as a
positional argument. This will need to be specified as a keyword
argument in a future release.
See Also
--------
set_precision
Examples
--------
>>> import shapely
>>> from shapely import LineString
>>> line = LineString([(0, 0), (2, 2)])
>>> shapely.difference(line, LineString([(1, 1), (3, 3)]))
<LINESTRING (0 0, 1 1)>
>>> shapely.difference(line, LineString())
<LINESTRING (0 0, 2 2)>
>>> shapely.difference(line, None) is None
True
>>> box1 = shapely.box(0, 0, 2, 2)
>>> box2 = shapely.box(1, 1, 3, 3)
>>> shapely.difference(box1, box2).normalize()
<POLYGON ((0 0, 0 2, 1 2, 1 1, 2 1, 2 0, 0 0))>
>>> box1 = shapely.box(0.1, 0.2, 2.1, 2.1)
>>> shapely.difference(box1, box2, grid_size=1)
<POLYGON ((2 0, 0 0, 0 2, 1 2, 1 1, 2 1, 2 0))>
disjoint_subset_union(a, b, **kwargs)
Merge multiple polygons into one using algorithm optimised for subsets.
This is an optimized version of union which assumes inputs can be
divided into subsets that do not intersect.
If there is only one such subset, performance can be expected to be worse than
:func:`union`. As such, it is recommeded to use ``disjoint_subset_union`` with
GeometryCollections rather than individual geometries.
.. versionadded:: 2.1.0
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to merge (union).
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
union
coverage_union
disjoint_subset_union_all
Examples
--------
>>> import shapely
>>> from shapely import Polygon
>>> polygon_1 = Polygon([(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)])
>>> polygon_2 = Polygon([(1, 0), (1, 1), (2, 1), (2, 0), (1, 0)])
>>> shapely.disjoint_subset_union(polygon_1, polygon_2).normalize()
<POLYGON ((0 0, 0 1, 1 1, 2 1, 2 0, 1 0, 0 0))>
Union with None returns same polygon:
>>> shapely.disjoint_subset_union(polygon_1, None).normalize()
<POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
disjoint_subset_union_all(geometries, *, axis=None, **kwargs)
Return the union of multiple polygons.
This is an optimized version of union which assumes inputs can be divided into
subsets that do not intersect.
If there is only one such subset, performance can be expected to be worse than
:func:`union_all`.
This function ignores None values when other Geometry elements are present.
If all elements of the given axis are None, an empty GeometryCollection is
returned.
.. versionadded:: 2.1.0
Parameters
----------
geometries : array_like
Geometries to union.
axis : int, optional
Axis along which the operation is performed. The default (None)
performs the operation over all axes, returning a scalar value.
Axis may be negative, in which case it counts from the last to the
first axis.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
coverage_union_all
union_all
disjoint_subset_union
Examples
--------
>>> import shapely
>>> from shapely import Polygon
>>> polygon_1 = Polygon([(0, 0), (0, 1), (1, 1), (1, 0), (0, 0)])
>>> polygon_2 = Polygon([(1, 0), (1, 1), (2, 1), (2, 0), (1, 0)])
>>> shapely.disjoint_subset_union_all([polygon_1, polygon_2]).normalize()
<POLYGON ((0 0, 0 1, 1 1, 2 1, 2 0, 1 0, 0 0))>
>>> shapely.disjoint_subset_union_all([polygon_1, None]).normalize()
<POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))>
>>> shapely.disjoint_subset_union_all([None, None]).normalize()
<GEOMETRYCOLLECTION EMPTY>
intersection(a, b, grid_size=None, **kwargs)
Return the geometry that is shared between input geometries.
If grid_size is nonzero, input coordinates will be snapped to a precision
grid of that size and resulting coordinates will be snapped to that same
grid. If 0, this operation will use double precision coordinates. If None,
the highest precision of the inputs will be used, which may be previously
set using set_precision. Note: returned geometry does not have precision
set unless specified previously by set_precision.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to intersect with.
grid_size : float, optional
Precision grid size; will use the highest precision of the inputs by default.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``grid_size`` is specified as a
positional argument. This will need to be specified as a keyword
argument in a future release.
See Also
--------
intersection_all
set_precision
Examples
--------
>>> import shapely
>>> from shapely import LineString
>>> line = LineString([(0, 0), (2, 2)])
>>> shapely.intersection(line, LineString([(1, 1), (3, 3)]))
<LINESTRING (1 1, 2 2)>
>>> box1 = shapely.box(0, 0, 2, 2)
>>> box2 = shapely.box(1, 1, 3, 3)
>>> shapely.intersection(box1, box2).normalize()
<POLYGON ((1 1, 1 2, 2 2, 2 1, 1 1))>
>>> box1 = shapely.box(0.1, 0.2, 2.1, 2.1)
>>> shapely.intersection(box1, box2, grid_size=1)
<POLYGON ((2 2, 2 1, 1 1, 1 2, 2 2))>
intersection_all(geometries, axis=None, **kwargs)
Return the intersection of multiple geometries.
This function ignores None values when other Geometry elements are present.
If all elements of the given axis are None, an empty GeometryCollection is
returned.
Parameters
----------
geometries : array_like
Geometries to calculate the intersection of.
axis : int, optional
Axis along which the operation is performed. The default (None)
performs the operation over all axes, returning a scalar value.
Axis may be negative, in which case it counts from the last to the
first axis.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``axis`` is specified as a
positional argument. This will need to be specified as a keyword
argument in a future release.
See Also
--------
intersection
Examples
--------
>>> import shapely
>>> from shapely import LineString
>>> line1 = LineString([(0, 0), (2, 2)])
>>> line2 = LineString([(1, 1), (3, 3)])
>>> shapely.intersection_all([line1, line2])
<LINESTRING (1 1, 2 2)>
>>> shapely.intersection_all([[line1, line2, None]], axis=1).tolist()
[<LINESTRING (1 1, 2 2)>]
>>> shapely.intersection_all([line1, None])
<LINESTRING (0 0, 2 2)>
symmetric_difference(a, b, grid_size=None, **kwargs)
Return the geometry with the portions of input geometries that do not intersect.
If grid_size is nonzero, input coordinates will be snapped to a precision
grid of that size and resulting coordinates will be snapped to that same
grid. If 0, this operation will use double precision coordinates. If None,
the highest precision of the inputs will be used, which may be previously
set using set_precision. Note: returned geometry does not have precision
set unless specified previously by set_precision.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to evaluate symmetric difference with.
grid_size : float, optional
Precision grid size; will use the highest precision of the inputs by default.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``grid_size`` is specified as a
positional argument. This will need to be specified as a keyword
argument in a future release.
See Also
--------
symmetric_difference_all
set_precision
Examples
--------
>>> import shapely
>>> from shapely import LineString
>>> line = LineString([(0, 0), (2, 2)])
>>> shapely.symmetric_difference(line, LineString([(1, 1), (3, 3)]))
<MULTILINESTRING ((0 0, 1 1), (2 2, 3 3))>
>>> box1 = shapely.box(0, 0, 2, 2)
>>> box2 = shapely.box(1, 1, 3, 3)
>>> shapely.symmetric_difference(box1, box2).normalize()
<MULTIPOLYGON (((1 2, 1 3, 3 3, 3 1, 2 1, 2 2, 1 2)), ((0 0, 0 2, 1 2, 1 1, ...>
>>> box1 = shapely.box(0.1, 0.2, 2.1, 2.1)
>>> shapely.symmetric_difference(box1, box2, grid_size=1)
<MULTIPOLYGON (((2 0, 0 0, 0 2, 1 2, 1 1, 2 1, 2 0)), ((2 2, 1 2, 1 3, 3 3, ...>
symmetric_difference_all(geometries, axis=None, **kwargs)
Return the symmetric difference of multiple geometries.
This function ignores None values when other Geometry elements are present.
If all elements of the given axis are None an empty GeometryCollection is
returned.
.. deprecated:: 2.1.0
This function behaves incorrectly and will be removed in a future
version. See https://github.com/shapely/shapely/issues/2027 for more
details.
Parameters
----------
geometries : array_like
Geometries to calculate the combined symmetric difference of.
axis : int, optional
Axis along which the operation is performed. The default (None)
performs the operation over all axes, returning a scalar value.
Axis may be negative, in which case it counts from the last to the
first axis.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``axis`` is specified as a
positional argument. This will need to be specified as a keyword
argument in a future release.
See Also
--------
symmetric_difference
Examples
--------
>>> import shapely
>>> from shapely import LineString
>>> line1 = LineString([(0, 0), (2, 2)])
>>> line2 = LineString([(1, 1), (3, 3)])
>>> shapely.symmetric_difference_all([line1, line2])
<MULTILINESTRING ((0 0, 1 1), (2 2, 3 3))>
>>> shapely.symmetric_difference_all([[line1, line2, None]], axis=1).tolist()
[<MULTILINESTRING ((0 0, 1 1), (2 2, 3 3))>]
>>> shapely.symmetric_difference_all([line1, None])
<LINESTRING (0 0, 2 2)>
>>> shapely.symmetric_difference_all([None, None])
<GEOMETRYCOLLECTION EMPTY>
unary_union = union_all(geometries, grid_size=None, axis=None, **kwargs)
Return the union of multiple geometries.
This function ignores None values when other Geometry elements are present.
If all elements of the given axis are None an empty GeometryCollection is
returned.
If grid_size is nonzero, input coordinates will be snapped to a precision
grid of that size and resulting coordinates will be snapped to that same
grid. If 0, this operation will use double precision coordinates. If None,
the highest precision of the inputs will be used, which may be previously
set using set_precision. Note: returned geometry does not have precision
set unless specified previously by set_precision.
`unary_union` is an alias of `union_all`.
Parameters
----------
geometries : array_like
Geometries to merge/union.
grid_size : float, optional
Precision grid size; will use the highest precision of the inputs by default.
axis : int, optional
Axis along which the operation is performed. The default (None)
performs the operation over all axes, returning a scalar value.
Axis may be negative, in which case it counts from the last to the
first axis.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``grid_size`` or ``axis`` are
specified as positional arguments. In a future release, these will
need to be specified as keyword arguments.
See Also
--------
union
set_precision
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> line1 = LineString([(0, 0), (2, 2)])
>>> line2 = LineString([(2, 2), (3, 3)])
>>> shapely.union_all([line1, line2])
<MULTILINESTRING ((0 0, 2 2), (2 2, 3 3))>
>>> shapely.union_all([[line1, line2, None]], axis=1).tolist()
[<MULTILINESTRING ((0 0, 2 2), (2 2, 3 3))>]
>>> box1 = shapely.box(0, 0, 2, 2)
>>> box2 = shapely.box(1, 1, 3, 3)
>>> shapely.union_all([box1, box2]).normalize()
<POLYGON ((0 0, 0 2, 1 2, 1 3, 3 3, 3 1, 2 1, 2 0, 0 0))>
>>> box1 = shapely.box(0.1, 0.2, 2.1, 2.1)
>>> shapely.union_all([box1, box2], grid_size=1)
<POLYGON ((2 0, 0 0, 0 2, 1 2, 1 3, 3 3, 3 1, 2 1, 2 0))>
>>> shapely.union_all([None, Point(0, 1)])
<POINT (0 1)>
>>> shapely.union_all([None, None])
<GEOMETRYCOLLECTION EMPTY>
>>> shapely.union_all([])
<GEOMETRYCOLLECTION EMPTY>
union(a, b, grid_size=None, **kwargs)
Merge geometries into one.
If grid_size is nonzero, input coordinates will be snapped to a precision
grid of that size and resulting coordinates will be snapped to that same
grid. If 0, this operation will use double precision coordinates. If None,
the highest precision of the inputs will be used, which may be previously
set using set_precision. Note: returned geometry does not have precision
set unless specified previously by set_precision.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to merge (union).
grid_size : float, optional
Precision grid size; will use the highest precision of the inputs by default.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``grid_size`` is specified as a
positional argument. This will need to be specified as a keyword
argument in a future release.
See Also
--------
union_all
set_precision
Examples
--------
>>> import shapely
>>> from shapely import LineString
>>> line = LineString([(0, 0), (2, 2)])
>>> shapely.union(line, LineString([(2, 2), (3, 3)]))
<MULTILINESTRING ((0 0, 2 2), (2 2, 3 3))>
>>> shapely.union(line, None) is None
True
>>> box1 = shapely.box(0, 0, 2, 2)
>>> box2 = shapely.box(1, 1, 3, 3)
>>> shapely.union(box1, box2).normalize()
<POLYGON ((0 0, 0 2, 1 2, 1 3, 3 3, 3 1, 2 1, 2 0, 0 0))>
>>> box1 = shapely.box(0.1, 0.2, 2.1, 2.1)
>>> shapely.union(box1, box2, grid_size=1)
<POLYGON ((2 0, 0 0, 0 2, 1 2, 1 3, 3 3, 3 1, 2 1, 2 0))>
union_all(geometries, grid_size=None, axis=None, **kwargs)
Return the union of multiple geometries.
This function ignores None values when other Geometry elements are present.
If all elements of the given axis are None an empty GeometryCollection is
returned.
If grid_size is nonzero, input coordinates will be snapped to a precision
grid of that size and resulting coordinates will be snapped to that same
grid. If 0, this operation will use double precision coordinates. If None,
the highest precision of the inputs will be used, which may be previously
set using set_precision. Note: returned geometry does not have precision
set unless specified previously by set_precision.
`unary_union` is an alias of `union_all`.
Parameters
----------
geometries : array_like
Geometries to merge/union.
grid_size : float, optional
Precision grid size; will use the highest precision of the inputs by default.
axis : int, optional
Axis along which the operation is performed. The default (None)
performs the operation over all axes, returning a scalar value.
Axis may be negative, in which case it counts from the last to the
first axis.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``grid_size`` or ``axis`` are
specified as positional arguments. In a future release, these will
need to be specified as keyword arguments.
See Also
--------
union
set_precision
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> line1 = LineString([(0, 0), (2, 2)])
>>> line2 = LineString([(2, 2), (3, 3)])
>>> shapely.union_all([line1, line2])
<MULTILINESTRING ((0 0, 2 2), (2 2, 3 3))>
>>> shapely.union_all([[line1, line2, None]], axis=1).tolist()
[<MULTILINESTRING ((0 0, 2 2), (2 2, 3 3))>]
>>> box1 = shapely.box(0, 0, 2, 2)
>>> box2 = shapely.box(1, 1, 3, 3)
>>> shapely.union_all([box1, box2]).normalize()
<POLYGON ((0 0, 0 2, 1 2, 1 3, 3 3, 3 1, 2 1, 2 0, 0 0))>
>>> box1 = shapely.box(0.1, 0.2, 2.1, 2.1)
>>> shapely.union_all([box1, box2], grid_size=1)
<POLYGON ((2 0, 0 0, 0 2, 1 2, 1 3, 3 3, 3 1, 2 1, 2 0))>
>>> shapely.union_all([None, Point(0, 1)])
<POINT (0 1)>
>>> shapely.union_all([None, None])
<GEOMETRYCOLLECTION EMPTY>
>>> shapely.union_all([])
<GEOMETRYCOLLECTION EMPTY>
DATA
__all__ = ['coverage_union', 'coverage_union_all', 'difference', 'disj...
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\shapely\set_operations.py
shapely.set_precision
Python Library Documentation: function set_precision in module shapely._geometry
set_precision(geometry, grid_size, mode='valid_output', **kwargs)
Return geometry with the precision set to a precision grid size.
By default, geometries use double precision coordinates (grid_size = 0).
Coordinates will be rounded if the precision grid specified is less precise
than the input geometry. Duplicated vertices will be dropped from lines and
polygons for grid sizes greater than 0. Line and polygon geometries may
collapse to empty geometries if all vertices are closer together than
``grid_size`` or if a polygon becomes significantly narrower than
``grid_size``. Spikes or sections in polygons narrower than ``grid_size``
after rounding the vertices will be removed, which can lead to multipolygons
or empty geometries. Z values, if present, will not be modified.
Notes
-----
* subsequent operations will always be performed in the precision of the
geometry with higher precision (smaller "grid_size"). That same precision
will be attached to the operation outputs.
* input geometries should be geometrically valid; unexpected results may
occur if input geometries are not.
* the geometry returned will be in
:ref:`mild canonical form <canonical-form>`, and the order of vertices can
change and should not be relied upon.
* returns None if geometry is None.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to set the precision of.
grid_size : float
Precision grid size. If 0, will use double precision (will not modify
geometry if precision grid size was not previously set). If this
value is more precise than input geometry, the input geometry will
not be modified.
mode : {'valid_output', 'pointwise', 'keep_collapsed'}, default 'valid_output'
This parameter determines the way a precision reduction is applied on
the geometry. There are three modes:
1. `'valid_output'` (default): The output is always valid. Collapsed
geometry elements (including both polygons and lines) are removed.
Duplicate vertices are removed.
2. `'pointwise'`: Precision reduction is performed pointwise. Output
geometry may be invalid due to collapse or self-intersection.
Duplicate vertices are not removed. In GEOS this option is called
NO_TOPO.
.. note::
'pointwise' mode requires at least GEOS 3.10. It is accepted in
earlier versions, but the results may be unexpected.
3. `'keep_collapsed'`: Like the default mode, except that collapsed
linear geometry elements are preserved. Collapsed polygonal input
elements are removed. Duplicate vertices are removed.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
get_precision
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> shapely.set_precision(Point(0.9, 0.9), 1.0)
<POINT (1 1)>
>>> shapely.set_precision(Point(0.9, 0.9, 0.9), 1.0)
<POINT Z (1 1 0.9)>
>>> shapely.set_precision(LineString([(0, 0), (0, 0.1), (0, 1), (1, 1)]), 1.0)
<LINESTRING (0 0, 0 1, 1 1)>
>>> shapely.set_precision(LineString([(0, 0), (0, 0.1), (0.1, 0.1)]), 1.0, mode="valid_output")
<LINESTRING EMPTY>
>>> shapely.set_precision(LineString([(0, 0), (0, 0.1), (0.1, 0.1)]), 1.0, mode="pointwise")
<LINESTRING (0 0, 0 0, 0 0)>
>>> shapely.set_precision(LineString([(0, 0), (0, 0.1), (0.1, 0.1)]), 1.0, mode="keep_collapsed")
<LINESTRING (0 0, 0 0)>
>>> shapely.set_precision(None, 1.0) is None
True
shapely.set_srid
Python Library Documentation: function set_srid in module shapely._geometry
set_srid(geometry, srid, **kwargs)
Return a geometry with its SRID set.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to set the SRID of.
srid : int
The SRID to set on the geometry.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
get_srid
Examples
--------
>>> import shapely
>>> from shapely import Point
>>> point = Point(0, 0)
>>> shapely.get_srid(point)
0
>>> with_srid = shapely.set_srid(point, 4326)
>>> shapely.get_srid(with_srid)
4326
shapely.setup_signal_checks
Python Library Documentation: function setup_signal_checks in module shapely.errors
setup_signal_checks(interval=10000)
Enable Python signal checks in the ufunc inner loops.
Doing so allows termination (using CTRL+C) of operations on large arrays of
vectors.
Parameters
----------
interval : int, default 10000
Check for interrupts every x iterations. The higher the number, the
slower shapely will respond to a signal. However, at low values there
will be a negative effect on performance. The default of 10000 does not
have any measureable effects on performance.
Notes
-----
For more information on signals consult the Python docs:
https://docs.python.org/3/library/signal.html
shapely.shortest_line
Python Library Documentation: function shortest_line in module shapely.linear
shortest_line(a, b, **kwargs)
Return the shortest line between two geometries.
The resulting line consists of two points, representing the nearest
points between the geometry pair. The line always starts in the first
geometry `a` and ends in the second geometry `b`. The endpoints of the
line will not necessarily be existing vertices of the input geometries
`a` and `b`, but can also be a point along a line segment.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to compare.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
prepare : improve performance by preparing ``a`` (the first argument)
Examples
--------
>>> import shapely
>>> from shapely import LineString
>>> line1 = LineString([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)])
>>> line2 = LineString([(0, 3), (3, 0), (5, 3)])
>>> shapely.shortest_line(line1, line2)
<LINESTRING (1 1, 1.5 1.5)>
shapely.simplify
Python Library Documentation: function simplify in module shapely.constructive
simplify(geometry, tolerance, preserve_topology=True, **kwargs)
Return a simplified version of an input geometry.
The Douglas-Peucker algorithm is used to simplify the geometry.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to simplify.
tolerance : float or array_like
The maximum allowed geometry displacement. The higher this value, the
smaller the number of vertices in the resulting geometry.
preserve_topology : bool, default True
By default (True), the operation will avoid creating invalid
geometries (checking for collapses, ring-intersections, etc), but
this is computationally more expensive.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``preserve_topology`` is specified as
a positional argument. This will need to be specified as a keyword
argument in a future release.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Polygon
>>> line = LineString([(0, 0), (1, 10), (0, 20)])
>>> shapely.simplify(line, tolerance=0.9)
<LINESTRING (0 0, 1 10, 0 20)>
>>> shapely.simplify(line, tolerance=1)
<LINESTRING (0 0, 0 20)>
>>> polygon_with_hole = Polygon(
... [(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)],
... holes=[[(2, 2), (2, 4), (4, 4), (4, 2), (2, 2)]]
... )
>>> shapely.simplify(polygon_with_hole, tolerance=4, preserve_topology=True)
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0), (4 2, 2 4, 4 4, 4 2))>
>>> shapely.simplify(polygon_with_hole, tolerance=4, preserve_topology=False)
<POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))>
shapely.snap
Python Library Documentation: function snap in module shapely.constructive
snap(geometry, reference, tolerance, **kwargs)
Snap the vertices and segments of the geometry to vertices of the reference.
Vertices and segments of the input geometry are snapped to vertices of the
reference geometry, returning a new geometry; the input geometries are not
modified. The result geometry is the input geometry with the vertices and
segments snapped. If no snapping occurs then the input geometry is returned
unchanged. The tolerance is used to control where snapping is performed.
Where possible, this operation tries to avoid creating invalid geometries;
however, it does not guarantee that output geometries will be valid. It is
the responsibility of the caller to check for and handle invalid geometries.
Because too much snapping can result in invalid geometries being created,
heuristics are used to determine the number and location of snapped
vertices that are likely safe to snap. These heuristics may omit
some potential snaps that are otherwise within the tolerance.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to snap.
reference : Geometry or array_like
Geometry or geometries to snap to.
tolerance : float or array_like
The maximum distance between the input and reference geometries for
snapping to occur. A value of 0 will snap only identical points.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point, Polygon, MultiPoint
>>> point = Point(0.5, 2.5)
>>> target_point = Point(0, 2)
>>> shapely.snap(point, target_point, tolerance=1)
<POINT (0 2)>
>>> shapely.snap(point, target_point, tolerance=0.49)
<POINT (0.5 2.5)>
>>> polygon = Polygon([(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)])
>>> shapely.snap(polygon, Point(8, 10), tolerance=5)
<POLYGON ((0 0, 0 10, 8 10, 10 0, 0 0))>
>>> shapely.snap(polygon, LineString([(8, 10), (8, 0)]), tolerance=5)
<POLYGON ((0 0, 0 10, 8 10, 8 0, 0 0))>
You can snap one line to another, for example to clean imprecise coordinates:
>>> line1 = LineString([(0.1, 0.1), (0.49, 0.51), (1.01, 0.89)])
>>> line2 = LineString([(0, 0), (0.5, 0.5), (1.0, 1.0)])
>>> shapely.snap(line1, line2, 0.25)
<LINESTRING (0 0, 0.5 0.5, 1 1)>
Snapping also supports Z coordinates:
>>> point1 = Point(0.1, 0.1, 0.5)
>>> multipoint = MultiPoint([(0, 0, 1), (0, 0, 0)])
>>> shapely.snap(point1, multipoint, 1)
<POINT Z (0 0 1)>
Snapping to an empty geometry has no effect:
>>> shapely.snap(line1, LineString([]), 0.25)
<LINESTRING (0.1 0.1, 0.49 0.51, 1.01 0.89)>
Snapping to a non-geometry (None) will always return None:
>>> shapely.snap(line1, None, 0.25) is None
True
Only one vertex of a polygon is snapped to a target point,
even if all vertices are equidistant to it,
in order to prevent collapse of the polygon:
>>> poly = shapely.box(0, 0, 1, 1)
>>> poly
<POLYGON ((1 0, 1 1, 0 1, 0 0, 1 0))>
>>> shapely.snap(poly, Point(0.5, 0.5), 1)
<POLYGON ((0.5 0.5, 1 1, 0 1, 0 0, 0.5 0.5))>
shapely.strtree
Python Library Documentation: module shapely.strtree in shapely
NAME
shapely.strtree - STRtree spatial index for efficient spatial queries.
CLASSES
builtins.object
STRtree
class STRtree(builtins.object)
| STRtree(geoms: collections.abc.Iterable[shapely.geometry.base.BaseGeometry], node_capacity: int = 10)
|
| A query-only R-tree spatial index.
|
| It is created using the Sort-Tile-Recursive (STR) [1]_ algorithm.
|
| The tree indexes the bounding boxes of each geometry. The tree is
| constructed directly at initialization and nodes cannot be added or
| removed after it has been created.
|
| All operations return indices of the input geometries. These indices
| can be used to index into anything associated with the input geometries,
| including the input geometries themselves, or custom items stored in
| another object of the same length as the geometries.
|
| Bounding boxes limited to two dimensions and are axis-aligned (equivalent to
| the ``bounds`` property of a geometry); any Z values present in geometries
| are ignored for purposes of indexing within the tree.
|
| Any mixture of geometry types may be stored in the tree.
|
| Note: the tree is more efficient for querying when there are fewer
| geometries that have overlapping bounding boxes and where there is greater
| similarity between the outer boundary of a geometry and its bounding box.
| For example, a MultiPolygon composed of widely-spaced individual Polygons
| will have a large overall bounding box compared to the boundaries of its
| individual Polygons, and the bounding box may also potentially overlap many
| other geometries within the tree. This means that the resulting tree may be
| less efficient to query than a tree constructed from individual Polygons.
|
| Parameters
| ----------
| geoms : sequence
| A sequence of geometry objects.
| node_capacity : int, default 10
| The maximum number of child nodes per parent node in the tree.
|
| References
| ----------
| .. [1] Leutenegger, Scott T.; Edgington, Jeffrey M.; Lopez, Mario A.
| (February 1997). "STR: A Simple and Efficient Algorithm for
| R-Tree Packing".
| https://ia600900.us.archive.org/27/items/nasa_techdoc_19970016975/19970016975.pdf
|
| Methods defined here:
|
| __init__(self, geoms: collections.abc.Iterable[shapely.geometry.base.BaseGeometry], node_capacity: int = 10)
| Create a new STRtree spatial index.
|
| __len__(self)
| Return the number of geometries in the tree.
|
| __reduce__(self)
| Pickle support.
|
| nearest(self, geometry) -> typing.Any | None
| Return the index of the nearest geometry in the tree.
|
| This is determined for each input geometry based on distance within
| two-dimensional Cartesian space.
|
| This distance will be 0 when input geometries intersect tree geometries.
|
| If there are multiple equidistant or intersected geometries in the tree,
| only a single result is returned for each input geometry, based on the
| order that tree geometries are visited; this order may be
| nondeterministic.
|
| If any input geometry is None or empty, an error is raised. Any Z
| values present in input geometries are ignored when finding nearest
| tree geometries.
|
| Parameters
| ----------
| geometry : Geometry or array_like
| Input geometries to query the tree.
|
| Returns
| -------
| scalar or ndarray
| Indices of geometries in tree. Return value will have the same shape
| as the input.
|
| None is returned if this index is empty. This may change in
| version 2.0.
|
| See Also
| --------
| query_nearest: returns all equidistant geometries, exclusive geometries, and optional distances
|
| Examples
| --------
| >>> from shapely import Point, STRtree
| >>> tree = STRtree([Point(i, i) for i in range(10)])
|
| Query the tree for nearest using a scalar geometry:
|
| >>> index = tree.nearest(Point(2.2, 2.2))
| >>> index
| 2
| >>> tree.geometries.take(index)
| <POINT (2 2)>
|
| Query the tree for nearest using an array of geometries:
|
| >>> indices = tree.nearest([Point(2.2, 2.2), Point(4.4, 4.4)])
| >>> indices.tolist()
| [2, 4]
| >>> tree.geometries.take(indices).tolist()
| [<POINT (2 2)>, <POINT (4 4)>]
|
| Nearest only return one object if there are multiple equidistant results:
|
| >>> tree = STRtree ([Point(0, 0), Point(0, 0)])
| >>> tree.nearest(Point(0, 0))
| 0
|
| query(self, geometry, predicate=None, distance=None)
| Get the index combinations of all possibly intersecting geometries.
|
| Returns the integer indices of all combinations of each input geometry
| and tree geometries where the bounding box of each input geometry
| intersects the bounding box of a tree geometry.
|
| If the input geometry is a scalar, this returns an array of shape (n, ) with
| the indices of the matching tree geometries. If the input geometry is an
| array_like, this returns an array with shape (2,n) where the subarrays
| correspond to the indices of the input geometries and indices of the
| tree geometries associated with each. To generate an array of pairs of
| input geometry index and tree geometry index, simply transpose the
| result.
|
| If a predicate is provided, the tree geometries are first queried based
| on the bounding box of the input geometry and then are further filtered
| to those that meet the predicate when comparing the input geometry to
| the tree geometry:
| predicate(geometry, tree_geometry)
|
| The 'dwithin' predicate requires GEOS >= 3.10.
|
| Bounding boxes are limited to two dimensions and are axis-aligned
| (equivalent to the ``bounds`` property of a geometry); any Z values
| present in input geometries are ignored when querying the tree.
|
| Any input geometry that is None or empty will never match geometries in
| the tree.
|
| Parameters
| ----------
| geometry : Geometry or array_like
| Input geometries to query the tree and filter results using the
| optional predicate.
| predicate : {None, 'intersects', 'within', 'contains', 'overlaps', 'crosses','touches', 'covers', 'covered_by', 'contains_properly', 'dwithin'}, optional
| The predicate to use for testing geometries from the tree
| that are within the input geometry's bounding box.
| distance : number or array_like, optional
| Distances around each input geometry within which to query the tree
| for the 'dwithin' predicate. If array_like, shape must be
| broadcastable to shape of geometry. Required if predicate='dwithin'.
|
| Returns
| -------
| ndarray with shape (n,) if geometry is a scalar
| Contains tree geometry indices.
|
| OR
|
| ndarray with shape (2, n) if geometry is an array_like
| The first subarray contains input geometry indices.
| The second subarray contains tree geometry indices.
|
| Examples
| --------
| >>> from shapely import box, Point, STRtree
| >>> import numpy as np
| >>> points = [Point(0, 0), Point(1, 1), Point(2,2), Point(3, 3)]
| >>> tree = STRtree(points)
|
| Query the tree using a scalar geometry:
|
| >>> indices = tree.query(box(0, 0, 1, 1))
| >>> indices.tolist()
| [0, 1]
|
| Query using an array of geometries:
|
| >>> boxes = np.array([box(0, 0, 1, 1), box(2, 2, 3, 3)])
| >>> arr_indices = tree.query(boxes)
| >>> arr_indices.tolist()
| [[0, 0, 1, 1], [0, 1, 2, 3]]
|
| Or transpose to get all pairs of input and tree indices:
|
| >>> arr_indices.T.tolist()
| [[0, 0], [0, 1], [1, 2], [1, 3]]
|
| Retrieve the tree geometries by results of query:
|
| >>> tree.geometries.take(indices).tolist()
| [<POINT (0 0)>, <POINT (1 1)>]
|
| Retrieve all pairs of input and tree geometries:
|
| >>> np.array([boxes.take(arr_indices[0]),tree.geometries.take(arr_indices[1])]).T.tolist()
| [[<POLYGON ((1 0, 1 1, 0 1, 0 0, 1 0))>, <POINT (0 0)>],
| [<POLYGON ((1 0, 1 1, 0 1, 0 0, 1 0))>, <POINT (1 1)>],
| [<POLYGON ((3 2, 3 3, 2 3, 2 2, 3 2))>, <POINT (2 2)>],
| [<POLYGON ((3 2, 3 3, 2 3, 2 2, 3 2))>, <POINT (3 3)>]]
|
| Query using a predicate:
|
| >>> tree = STRtree([box(0, 0, 0.5, 0.5), box(0.5, 0.5, 1, 1), box(1, 1, 2, 2)])
| >>> tree.query(box(0, 0, 1, 1), predicate="contains").tolist()
| [0, 1]
| >>> tree.query(Point(0.75, 0.75), predicate="dwithin", distance=0.5).tolist()
| [0, 1, 2]
|
| >>> tree.query(boxes, predicate="contains").tolist()
| [[0, 0], [0, 1]]
| >>> tree.query(boxes, predicate="dwithin", distance=0.5).tolist()
| [[0, 0, 0, 1], [0, 1, 2, 2]]
|
| Retrieve custom items associated with tree geometries (records can
| be in whatever data structure so long as geometries and custom data
| can be extracted into arrays of the same length and order):
|
| >>> records = [
| ... {"geometry": Point(0, 0), "value": "A"},
| ... {"geometry": Point(2, 2), "value": "B"}
| ... ]
| >>> tree = STRtree([record["geometry"] for record in records])
| >>> items = np.array([record["value"] for record in records])
| >>> items.take(tree.query(box(0, 0, 1, 1))).tolist()
| ['A']
|
|
| Notes
| -----
| In the context of a spatial join, input geometries are the "left"
| geometries that determine the order of the results, and tree geometries
| are "right" geometries that are joined against the left geometries. This
| effectively performs an inner join, where only those combinations of
| geometries that can be joined based on overlapping bounding boxes or
| optional predicate are returned.
|
| query_nearest(self, geometry, max_distance=None, return_distance=False, exclusive=False, all_matches=True)
| Return the index of the nearest geometries in the tree.
|
| This is determined for each input geometry based on distance within
| two-dimensional Cartesian space.
|
| This distance will be 0 when input geometries intersect tree geometries.
|
| If there are multiple equidistant or intersected geometries in tree and
| `all_matches` is True (the default), all matching tree geometries are
| returned; otherwise only the first matching tree geometry is returned.
| Tree indices are returned in the order they are visited for each input
| geometry and may not be in ascending index order; no meaningful order is
| implied.
|
| The max_distance used to search for nearest items in the tree may have a
| significant impact on performance by reducing the number of input
| geometries that are evaluated for nearest items in the tree. Only those
| input geometries with at least one tree geometry within +/- max_distance
| beyond their envelope will be evaluated. However, using a large
| max_distance may have a negative performance impact because many tree
| geometries will be queried for each input geometry.
|
| The distance, if returned, will be 0 for any intersected geometries in
| the tree.
|
| Any geometry that is None or empty in the input geometries is omitted
| from the output. Any Z values present in input geometries are ignored
| when finding nearest tree geometries.
|
| Parameters
| ----------
| geometry : Geometry or array_like
| Input geometries to query the tree.
| max_distance : float, optional
| Maximum distance within which to query for nearest items in tree.
| Must be greater than 0.
| return_distance : bool, default False
| If True, will return distances in addition to indices.
| exclusive : bool, default False
| If True, the nearest tree geometries that are equal to the input
| geometry will not be returned.
| all_matches : bool, default True
| If True, all equidistant and intersected geometries will be returned
| for each input geometry.
| If False, only the first nearest geometry will be returned.
|
| Returns
| -------
| tree indices or tuple of (tree indices, distances) if geometry is a scalar
| indices is an ndarray of shape (n, ) and distances (if present) an
| ndarray of shape (n, )
|
| OR
|
| indices or tuple of (indices, distances)
| indices is an ndarray of shape (2,n) and distances (if present) an
| ndarray of shape (n).
| The first subarray of indices contains input geometry indices.
| The second subarray of indices contains tree geometry indices.
|
| See Also
| --------
| nearest: returns singular nearest geometry for each input
|
| Examples
| --------
| >>> import numpy as np
| >>> from shapely import box, Point, STRtree
| >>> points = [Point(0, 0), Point(1, 1), Point(2,2), Point(3, 3)]
| >>> tree = STRtree(points)
|
| Find the nearest tree geometries to a scalar geometry:
|
| >>> indices = tree.query_nearest(Point(0.25, 0.25))
| >>> indices.tolist()
| [0]
|
| Retrieve the tree geometries by results of query:
|
| >>> tree.geometries.take(indices).tolist()
| [<POINT (0 0)>]
|
| Find the nearest tree geometries to an array of geometries:
|
| >>> query_points = np.array([Point(2.25, 2.25), Point(1, 1)])
| >>> arr_indices = tree.query_nearest(query_points)
| >>> arr_indices.tolist()
| [[0, 1], [2, 1]]
|
| Or transpose to get all pairs of input and tree indices:
|
| >>> arr_indices.T.tolist()
| [[0, 2], [1, 1]]
|
| Retrieve all pairs of input and tree geometries:
|
| >>> list(zip(query_points.take(arr_indices[0]), tree.geometries.take(arr_indices[1])))
| [(<POINT (2.25 2.25)>, <POINT (2 2)>), (<POINT (1 1)>, <POINT (1 1)>)]
|
| All intersecting geometries in the tree are returned by default:
|
| >>> tree.query_nearest(box(1,1,3,3)).tolist()
| [1, 2, 3]
|
| Set all_matches to False to to return a single match per input geometry:
|
| >>> tree.query_nearest(box(1,1,3,3), all_matches=False).tolist()
| [1]
|
| Return the distance to each nearest tree geometry:
|
| >>> index, distance = tree.query_nearest(Point(0.5, 0.5), return_distance=True)
| >>> index.tolist()
| [0, 1]
| >>> distance.round(4).tolist()
| [0.7071, 0.7071]
|
| Return the distance for each input and nearest tree geometry for an array
| of geometries:
|
| >>> indices, distance = tree.query_nearest([Point(0.5, 0.5), Point(1, 1)], return_distance=True)
| >>> indices.tolist()
| [[0, 0, 1], [0, 1, 1]]
| >>> distance.round(4).tolist()
| [0.7071, 0.7071, 0.0]
|
| Retrieve custom items associated with tree geometries (records can
| be in whatever data structure so long as geometries and custom data
| can be extracted into arrays of the same length and order):
|
| >>> records = [
| ... {"geometry": Point(0, 0), "value": "A"},
| ... {"geometry": Point(2, 2), "value": "B"}
| ... ]
| >>> tree = STRtree([record["geometry"] for record in records])
| >>> items = np.array([record["value"] for record in records])
| >>> items.take(tree.query_nearest(Point(0.5, 0.5))).tolist()
| ['A']
|
| ----------------------------------------------------------------------
| Readonly properties defined here:
|
| geometries
| Geometries stored in the tree in the order used to construct the tree.
|
| The order of this array corresponds to the tree indices returned by
| other STRtree methods.
|
| Do not attempt to modify items in the returned array.
|
| Returns
| -------
| ndarray of Geometry objects
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables
|
| __weakref__
| list of weak references to the object
DATA
__all__ = ['STRtree']
FILE
c:\users\youse\appdata\local\programs\python\python312\lib\site-packages\shapely\strtree.py
shapely.symmetric_difference
Python Library Documentation: function symmetric_difference in module shapely.set_operations
symmetric_difference(a, b, grid_size=None, **kwargs)
Return the geometry with the portions of input geometries that do not intersect.
If grid_size is nonzero, input coordinates will be snapped to a precision
grid of that size and resulting coordinates will be snapped to that same
grid. If 0, this operation will use double precision coordinates. If None,
the highest precision of the inputs will be used, which may be previously
set using set_precision. Note: returned geometry does not have precision
set unless specified previously by set_precision.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to evaluate symmetric difference with.
grid_size : float, optional
Precision grid size; will use the highest precision of the inputs by default.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``grid_size`` is specified as a
positional argument. This will need to be specified as a keyword
argument in a future release.
See Also
--------
symmetric_difference_all
set_precision
Examples
--------
>>> import shapely
>>> from shapely import LineString
>>> line = LineString([(0, 0), (2, 2)])
>>> shapely.symmetric_difference(line, LineString([(1, 1), (3, 3)]))
<MULTILINESTRING ((0 0, 1 1), (2 2, 3 3))>
>>> box1 = shapely.box(0, 0, 2, 2)
>>> box2 = shapely.box(1, 1, 3, 3)
>>> shapely.symmetric_difference(box1, box2).normalize()
<MULTIPOLYGON (((1 2, 1 3, 3 3, 3 1, 2 1, 2 2, 1 2)), ((0 0, 0 2, 1 2, 1 1, ...>
>>> box1 = shapely.box(0.1, 0.2, 2.1, 2.1)
>>> shapely.symmetric_difference(box1, box2, grid_size=1)
<MULTIPOLYGON (((2 0, 0 0, 0 2, 1 2, 1 1, 2 1, 2 0)), ((2 2, 1 2, 1 3, 3 3, ...>
shapely.symmetric_difference_all
Python Library Documentation: function symmetric_difference_all in module shapely.set_operations
symmetric_difference_all(geometries, axis=None, **kwargs)
Return the symmetric difference of multiple geometries.
This function ignores None values when other Geometry elements are present.
If all elements of the given axis are None an empty GeometryCollection is
returned.
.. deprecated:: 2.1.0
This function behaves incorrectly and will be removed in a future
version. See https://github.com/shapely/shapely/issues/2027 for more
details.
Parameters
----------
geometries : array_like
Geometries to calculate the combined symmetric difference of.
axis : int, optional
Axis along which the operation is performed. The default (None)
performs the operation over all axes, returning a scalar value.
Axis may be negative, in which case it counts from the last to the
first axis.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``axis`` is specified as a
positional argument. This will need to be specified as a keyword
argument in a future release.
See Also
--------
symmetric_difference
Examples
--------
>>> import shapely
>>> from shapely import LineString
>>> line1 = LineString([(0, 0), (2, 2)])
>>> line2 = LineString([(1, 1), (3, 3)])
>>> shapely.symmetric_difference_all([line1, line2])
<MULTILINESTRING ((0 0, 1 1), (2 2, 3 3))>
>>> shapely.symmetric_difference_all([[line1, line2, None]], axis=1).tolist()
[<MULTILINESTRING ((0 0, 1 1), (2 2, 3 3))>]
>>> shapely.symmetric_difference_all([line1, None])
<LINESTRING (0 0, 2 2)>
>>> shapely.symmetric_difference_all([None, None])
<GEOMETRYCOLLECTION EMPTY>
shapely.to_geojson
Python Library Documentation: function to_geojson in module shapely.io
to_geojson(geometry, indent=None, **kwargs)
Convert to the GeoJSON representation of a Geometry.
The GeoJSON format is defined in the `RFC 7946 <https://geojson.org/>`__.
NaN (not-a-number) coordinates will be written as 'null'.
The following are currently unsupported:
- Geometries of type LINEARRING: these are output as 'null'.
- Three-dimensional geometries: the third dimension is ignored.
Parameters
----------
geometry : str, bytes or array_like
Geometry or geometries to convert to GeoJSON.
indent : int, optional
If indent is a non-negative integer, then GeoJSON will be formatted.
An indent level of 0 will only insert newlines. None (the default)
selects the most compact representation.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import Point
>>> point = Point(1, 1)
>>> shapely.to_geojson(point)
'{"type":"Point","coordinates":[1.0,1.0]}'
>>> print(shapely.to_geojson(point, indent=2))
{
"type": "Point",
"coordinates": [
1.0,
1.0
]
}
shapely.to_ragged_array
Python Library Documentation: function to_ragged_array in module shapely._ragged_array
to_ragged_array(geometries, include_z=None, include_m=None)
Convert geometries to a ragged array representation.
This function converts an array of geometries to a ragged array
(i.e. irregular array of arrays) of coordinates, represented in memory
using a single contiguous array of the coordinates, and
up to 3 offset arrays that keep track where each sub-array
starts and ends.
This follows the in-memory layout of the variable size list arrays defined
by Apache Arrow, as specified for geometries by the GeoArrow project:
https://github.com/geoarrow/geoarrow.
Parameters
----------
geometries : array_like
Array of geometries (1-dimensional).
include_z, include_m : bool, default None
If both are False, return XY (2D) geometries.
If both are True, return XYZM (4D) geometries.
If either is True, return either XYZ or XYM (3D) geometries.
If a geometry has no Z or M dimension, extra coordinate data will be NaN.
By default, will infer the dimensionality from the
input geometries. Note that this inference can be unreliable with
empty geometries (for a guaranteed result, it is recommended to
specify the keyword).
.. versionadded:: 2.1.0
The ``include_m`` parameter was added to support XYM (3D) and
XYZM (4D) geometries available with GEOS 3.12.0 or later.
With older GEOS versions, M dimension coordinates will be NaN.
Returns
-------
tuple of (geometry_type, coords, offsets)
geometry_type : GeometryType
The type of the input geometries (required information for
roundtrip).
coords : np.ndarray
Contiguous array of shape (n, 2), (n, 3), or (n, 4) of all
coordinates of all input geometries.
offsets: tuple of np.ndarray
Offset arrays that make it possible to reconstruct the
geometries from the flat coordinates array. The number of
offset arrays depends on the geometry type. See
https://github.com/geoarrow/geoarrow/blob/main/format.md
for details.
Uses int32 dtype offsets if possible, otherwise int64 for
large inputs (coordinates > 32GB).
Notes
-----
Mixed singular and multi geometry types of the same basic type are
allowed (e.g., Point and MultiPoint) and all singular types will be
treated as multi types.
GeometryCollections and other mixed geometry types are not supported.
See Also
--------
from_ragged_array
Examples
--------
Consider a Polygon with one hole (interior ring):
>>> import shapely
>>> from shapely import Polygon
>>> polygon = Polygon(
... [(0, 0), (10, 0), (10, 10), (0, 10)],
... holes=[[(2, 2), (3, 2), (2, 3)]]
... )
>>> polygon
<POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0), (2 2, 3 2, 2 3, 2 2))>
This polygon can be thought of as a list of rings (first ring is the
exterior ring, subsequent rings are the interior rings), and each ring
as a list of coordinate pairs. This is very similar to how GeoJSON
represents the coordinates:
>>> import json
>>> json.loads(shapely.to_geojson(polygon))["coordinates"]
[[[0.0, 0.0], [10.0, 0.0], [10.0, 10.0], [0.0, 10.0], [0.0, 0.0]],
[[2.0, 2.0], [3.0, 2.0], [2.0, 3.0], [2.0, 2.0]]]
This function will return a similar list of lists of lists, but
using a single contiguous array of coordinates, and multiple arrays of
offsets:
>>> geometry_type, coords, offsets = shapely.to_ragged_array([polygon])
>>> geometry_type
<GeometryType.POLYGON: 3>
>>> coords
array([[ 0., 0.],
[10., 0.],
[10., 10.],
[ 0., 10.],
[ 0., 0.],
[ 2., 2.],
[ 3., 2.],
[ 2., 3.],
[ 2., 2.]])
>>> offsets
(array([0, 5, 9], dtype=int32), array([0, 2], dtype=int32))
As an example how to interpret the offsets: the i-th ring in the
coordinates is represented by ``offsets[0][i]`` to ``offsets[0][i+1]``:
>>> exterior_ring_start, exterior_ring_end = offsets[0][0], offsets[0][1]
>>> coords[exterior_ring_start:exterior_ring_end]
array([[ 0., 0.],
[10., 0.],
[10., 10.],
[ 0., 10.],
[ 0., 0.]])
shapely.to_wkb
Python Library Documentation: function to_wkb in module shapely.io
to_wkb(geometry, hex=False, output_dimension=None, byte_order=-1, include_srid=False, flavor='extended', **kwargs)
Convert to the Well-Known Binary (WKB) representation of a Geometry.
The Well-Known Binary format is defined in the `OGC Simple Features
Specification for SQL <https://www.opengeospatial.org/standards/sfs>`__.
The following limitations apply to WKB serialization:
- linearrings will be converted to linestrings
- a point with only NaN coordinates is converted to an empty point
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to convert to WKB.
hex : bool, default False
If true, export the WKB as a hexadecimal string. The default is to
return a binary bytes object.
output_dimension : int, default None
The output dimension for the WKB. Supported values are 2, 3 and 4 for
GEOS 3.12+. Default None will automatically choose 3 or 4, depending on
the version of GEOS.
Specifying 3 means that up to 3 dimensions will be written but 2D
geometries will still be represented as 2D in the WKB representation.
byte_order : int, default -1
Defaults to native machine byte order (-1). Use 0 to force big endian
and 1 for little endian.
include_srid : bool, default False
If True, the SRID is be included in WKB (this is an extension
to the OGC WKB specification). Not allowed when flavor is "iso".
flavor : {"iso", "extended"}, default "extended"
Which flavor of WKB will be returned. The flavor determines how
extra dimensionality is encoded with the type number, and whether
SRID can be included in the WKB. ISO flavor is "more standard" for
3D output, and does not support SRID embedding.
Both flavors are equivalent when ``output_dimension=2`` (or with 2D
geometries) and ``include_srid=False``.
The `from_wkb` function can read both flavors.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import Point
>>> point = Point(1, 1)
>>> shapely.to_wkb(point, byte_order=1)
b'\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\xf0?\x00\x00\x00\x00\x00\x00\xf0?'
>>> shapely.to_wkb(point, hex=True, byte_order=1)
'0101000000000000000000F03F000000000000F03F'
shapely.to_wkt
Python Library Documentation: function to_wkt in module shapely.io
to_wkt(geometry, rounding_precision=6, trim=True, output_dimension=None, old_3d=False, **kwargs)
Convert to the Well-Known Text (WKT) representation of a Geometry.
The Well-known Text format is defined in the `OGC Simple Features
Specification for SQL <https://www.opengeospatial.org/standards/sfs>`__.
The following limitations apply to WKT serialization:
- only simple empty geometries can be 3D, empty collections are always 2D
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to convert to WKT.
rounding_precision : int, default 6
The rounding precision when writing the WKT string. Set to a value of
-1 to indicate the full precision.
trim : bool, default True
If True, trim unnecessary decimals (trailing zeros). If False,
use fixed-precision number formatting.
output_dimension : int, default None
The output dimension for the WKT string. Supported values are 2, 3 and
4 for GEOS 3.12+. Default None will automatically choose 3 or 4,
depending on the version of GEOS.
Specifying 3 means that up to 3 dimensions will be written but 2D
geometries will still be represented as 2D in the WKT string.
old_3d : bool, default False
Enable old style 3D/4D WKT generation. By default, new style 3D/4D WKT
(ie. "POINT Z (10 20 30)") is returned, but with ``old_3d=True``
the WKT will be formatted in the style "POINT (10 20 30)".
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import Point
>>> shapely.to_wkt(Point(0, 0))
'POINT (0 0)'
>>> shapely.to_wkt(Point(0, 0), rounding_precision=3, trim=False)
'POINT (0.000 0.000)'
>>> shapely.to_wkt(Point(0, 0), rounding_precision=-1, trim=False)
'POINT (0.0000000000000000 0.0000000000000000)'
>>> shapely.to_wkt(Point(1, 2, 3), trim=True)
'POINT Z (1 2 3)'
>>> shapely.to_wkt(Point(1, 2, 3), trim=True, output_dimension=2)
'POINT (1 2)'
>>> shapely.to_wkt(Point(1, 2, 3), trim=True, old_3d=True)
'POINT (1 2 3)'
Notes
-----
The defaults differ from the default of some GEOS versions. To mimic this for
versions before GEOS 3.12, use::
shapely.to_wkt(geometry, rounding_precision=-1, trim=False, output_dimension=2)
shapely.total_bounds
Python Library Documentation: function total_bounds in module shapely.measurement
total_bounds(geometry, **kwargs)
Compute the total bounds (extent) of the geometry.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the total bounds.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Returns
-------
numpy ndarray of [xmin, ymin, xmax, ymax]
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point, Polygon
>>> shapely.total_bounds(Point(2, 3)).tolist()
[2.0, 3.0, 2.0, 3.0]
>>> shapely.total_bounds([Point(2, 3), Point(4, 5)]).tolist()
[2.0, 3.0, 4.0, 5.0]
>>> shapely.total_bounds([
... LineString([(0, 1), (0, 2), (3, 2)]),
... LineString([(4, 4), (4, 6), (6, 7)])
... ]).tolist()
[0.0, 1.0, 6.0, 7.0]
>>> shapely.total_bounds(Polygon()).tolist()
[nan, nan, nan, nan]
>>> shapely.total_bounds([Polygon(), Point(2, 3)]).tolist()
[2.0, 3.0, 2.0, 3.0]
>>> shapely.total_bounds(None).tolist()
[nan, nan, nan, nan]
shapely.touches
Python Library Documentation: function touches in module shapely.predicates
touches(a, b, **kwargs)
Return True if the only points shared between A and B are on their boundaries.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
prepare : improve performance by preparing ``a`` (the first argument)
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point, Polygon
>>> line = LineString([(0, 2), (2, 0)])
>>> shapely.touches(line, Point(0, 2))
True
>>> shapely.touches(line, Point(1, 1))
False
>>> shapely.touches(line, LineString([(0, 0), (1, 1)]))
True
>>> shapely.touches(line, LineString([(0, 0), (2, 2)]))
False
>>> area = Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)])
>>> shapely.touches(area, Point(0.5, 0))
True
>>> shapely.touches(area, Point(0.5, 0.5))
False
>>> shapely.touches(area, line)
True
>>> shapely.touches(area, Polygon([(0, 1), (1, 1), (1, 2), (0, 2), (0, 1)]))
True
shapely.transform
Python Library Documentation: function transform in module shapely.coordinates
transform(geometry, transformation, include_z: bool | None = False, *, interleaved: bool = True)
Apply a function to the coordinates of a geometry.
With the default of ``include_z=False``, all returned geometries will be
two-dimensional; the third dimension will be discarded, if present.
When specifying ``include_z=True``, the returned geometries preserve
the dimensionality of the respective input geometries.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries to transform.
transformation : function
A function that transforms a (N, 2) or (N, 3) ndarray of float64 to
another (N, 2) or (N, 3) ndarray of float64.
The function may not change N.
include_z : bool, optional, default False
If False, always return 2D geometries.
If True, the data being passed to the
transformation function will include the third dimension
(if a geometry has no third dimension, the z-coordinates
will be NaN). If None, will infer the dimensionality per
input geometry using ``has_z``, which may result in 2 calls to
the transformation function. Note that this inference
can be unreliable with empty geometries or NaN coordinates: for a
guaranteed result, it is recommended to specify ``include_z`` explicitly.
interleaved : bool, default True
If set to False, the transformation function should accept 2 or 3 separate
one-dimensional arrays (x, y and optional z) instead of a single
two-dimensional array.
.. versionadded:: 2.1.0
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``include_z`` is specified as a
positional argument. This will need to be specified as a keyword
argument in a future release.
See Also
--------
has_z
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> shapely.transform(Point(0, 0), lambda x: x + 1)
<POINT (1 1)>
>>> shapely.transform(LineString([(2, 2), (4, 4)]), lambda x: x * [2, 3])
<LINESTRING (4 6, 8 12)>
>>> shapely.transform(None, lambda x: x) is None
True
>>> shapely.transform([Point(0, 0), None], lambda x: x).tolist()
[<POINT (0 0)>, None]
The presence of a third dimension can be automatically detected, or
controlled explicitly:
>>> shapely.transform(Point(0, 0, 0), lambda x: x + 1)
<POINT (1 1)>
>>> shapely.transform(Point(0, 0, 0), lambda x: x + 1, include_z=True)
<POINT Z (1 1 1)>
>>> shapely.transform(Point(0, 0, 0), lambda x: x + 1, include_z=None)
<POINT Z (1 1 1)>
With interleaved=False, the call signature of the transformation is different:
>>> shapely.transform(LineString([(1, 2), (3, 4)]), lambda x, y: (x + 1, y), interleaved=False)
<LINESTRING (2 2, 4 4)>
Or with a z coordinate:
>>> shapely.transform(Point(0, 0, 0), lambda x, y, z: (x + 1, y, z + 2), interleaved=False, include_z=True)
<POINT Z (1 0 2)>
Using pyproj >= 2.1, the following example will reproject Shapely geometries
from EPSG 4326 to EPSG 32618:
>>> from pyproj import Transformer
>>> transformer = Transformer.from_crs(4326, 32618, always_xy=True)
>>> shapely.transform(Point(-75, 50), transformer.transform, interleaved=False)
<POINT (500000 5538630.703)>
shapely.unary_union
Python Library Documentation: function union_all in module shapely.set_operations
union_all(geometries, grid_size=None, axis=None, **kwargs)
Return the union of multiple geometries.
This function ignores None values when other Geometry elements are present.
If all elements of the given axis are None an empty GeometryCollection is
returned.
If grid_size is nonzero, input coordinates will be snapped to a precision
grid of that size and resulting coordinates will be snapped to that same
grid. If 0, this operation will use double precision coordinates. If None,
the highest precision of the inputs will be used, which may be previously
set using set_precision. Note: returned geometry does not have precision
set unless specified previously by set_precision.
`unary_union` is an alias of `union_all`.
Parameters
----------
geometries : array_like
Geometries to merge/union.
grid_size : float, optional
Precision grid size; will use the highest precision of the inputs by default.
axis : int, optional
Axis along which the operation is performed. The default (None)
performs the operation over all axes, returning a scalar value.
Axis may be negative, in which case it counts from the last to the
first axis.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``grid_size`` or ``axis`` are
specified as positional arguments. In a future release, these will
need to be specified as keyword arguments.
See Also
--------
union
set_precision
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> line1 = LineString([(0, 0), (2, 2)])
>>> line2 = LineString([(2, 2), (3, 3)])
>>> shapely.union_all([line1, line2])
<MULTILINESTRING ((0 0, 2 2), (2 2, 3 3))>
>>> shapely.union_all([[line1, line2, None]], axis=1).tolist()
[<MULTILINESTRING ((0 0, 2 2), (2 2, 3 3))>]
>>> box1 = shapely.box(0, 0, 2, 2)
>>> box2 = shapely.box(1, 1, 3, 3)
>>> shapely.union_all([box1, box2]).normalize()
<POLYGON ((0 0, 0 2, 1 2, 1 3, 3 3, 3 1, 2 1, 2 0, 0 0))>
>>> box1 = shapely.box(0.1, 0.2, 2.1, 2.1)
>>> shapely.union_all([box1, box2], grid_size=1)
<POLYGON ((2 0, 0 0, 0 2, 1 2, 1 3, 3 3, 3 1, 2 1, 2 0))>
>>> shapely.union_all([None, Point(0, 1)])
<POINT (0 1)>
>>> shapely.union_all([None, None])
<GEOMETRYCOLLECTION EMPTY>
>>> shapely.union_all([])
<GEOMETRYCOLLECTION EMPTY>
shapely.union
Python Library Documentation: function union in module shapely.set_operations
union(a, b, grid_size=None, **kwargs)
Merge geometries into one.
If grid_size is nonzero, input coordinates will be snapped to a precision
grid of that size and resulting coordinates will be snapped to that same
grid. If 0, this operation will use double precision coordinates. If None,
the highest precision of the inputs will be used, which may be previously
set using set_precision. Note: returned geometry does not have precision
set unless specified previously by set_precision.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to merge (union).
grid_size : float, optional
Precision grid size; will use the highest precision of the inputs by default.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``grid_size`` is specified as a
positional argument. This will need to be specified as a keyword
argument in a future release.
See Also
--------
union_all
set_precision
Examples
--------
>>> import shapely
>>> from shapely import LineString
>>> line = LineString([(0, 0), (2, 2)])
>>> shapely.union(line, LineString([(2, 2), (3, 3)]))
<MULTILINESTRING ((0 0, 2 2), (2 2, 3 3))>
>>> shapely.union(line, None) is None
True
>>> box1 = shapely.box(0, 0, 2, 2)
>>> box2 = shapely.box(1, 1, 3, 3)
>>> shapely.union(box1, box2).normalize()
<POLYGON ((0 0, 0 2, 1 2, 1 3, 3 3, 3 1, 2 1, 2 0, 0 0))>
>>> box1 = shapely.box(0.1, 0.2, 2.1, 2.1)
>>> shapely.union(box1, box2, grid_size=1)
<POLYGON ((2 0, 0 0, 0 2, 1 2, 1 3, 3 3, 3 1, 2 1, 2 0))>
shapely.union_all
Python Library Documentation: function union_all in module shapely.set_operations
union_all(geometries, grid_size=None, axis=None, **kwargs)
Return the union of multiple geometries.
This function ignores None values when other Geometry elements are present.
If all elements of the given axis are None an empty GeometryCollection is
returned.
If grid_size is nonzero, input coordinates will be snapped to a precision
grid of that size and resulting coordinates will be snapped to that same
grid. If 0, this operation will use double precision coordinates. If None,
the highest precision of the inputs will be used, which may be previously
set using set_precision. Note: returned geometry does not have precision
set unless specified previously by set_precision.
`unary_union` is an alias of `union_all`.
Parameters
----------
geometries : array_like
Geometries to merge/union.
grid_size : float, optional
Precision grid size; will use the highest precision of the inputs by default.
axis : int, optional
Axis along which the operation is performed. The default (None)
performs the operation over all axes, returning a scalar value.
Axis may be negative, in which case it counts from the last to the
first axis.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``grid_size`` or ``axis`` are
specified as positional arguments. In a future release, these will
need to be specified as keyword arguments.
See Also
--------
union
set_precision
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point
>>> line1 = LineString([(0, 0), (2, 2)])
>>> line2 = LineString([(2, 2), (3, 3)])
>>> shapely.union_all([line1, line2])
<MULTILINESTRING ((0 0, 2 2), (2 2, 3 3))>
>>> shapely.union_all([[line1, line2, None]], axis=1).tolist()
[<MULTILINESTRING ((0 0, 2 2), (2 2, 3 3))>]
>>> box1 = shapely.box(0, 0, 2, 2)
>>> box2 = shapely.box(1, 1, 3, 3)
>>> shapely.union_all([box1, box2]).normalize()
<POLYGON ((0 0, 0 2, 1 2, 1 3, 3 3, 3 1, 2 1, 2 0, 0 0))>
>>> box1 = shapely.box(0.1, 0.2, 2.1, 2.1)
>>> shapely.union_all([box1, box2], grid_size=1)
<POLYGON ((2 0, 0 0, 0 2, 1 2, 1 3, 3 3, 3 1, 2 1, 2 0))>
>>> shapely.union_all([None, Point(0, 1)])
<POINT (0 1)>
>>> shapely.union_all([None, None])
<GEOMETRYCOLLECTION EMPTY>
>>> shapely.union_all([])
<GEOMETRYCOLLECTION EMPTY>
shapely.voronoi_polygons
Python Library Documentation: function voronoi_polygons in module shapely.constructive
voronoi_polygons(geometry, tolerance=0.0, extend_to=None, only_edges=False, ordered=False, **kwargs)
Compute a Voronoi diagram from the vertices of an input geometry.
The output is a geometrycollection containing polygons (default)
or linestrings (see only_edges). Returns empty if an input geometry
contains less than 2 vertices or if the provided extent has zero area.
Parameters
----------
geometry : Geometry or array_like
Geometry or geometries for which to compute the Voronoi diagram.
tolerance : float or array_like, default 0.0
Snap input vertices together if their distance is less than this value.
extend_to : Geometry or array_like, optional
If provided, the diagram will be extended to cover the envelope of this
geometry (unless this envelope is smaller than the input geometry).
only_edges : bool or array_like, default False
If set to True, the triangulation will return a collection of
linestrings instead of polygons.
ordered : bool or array_like, default False
If set to True, polygons within the GeometryCollection will be ordered
according to the order of the input vertices. Note that this may slow
down the computation. Requires GEOS >= 3.12.0.
.. versionadded:: 2.1.0
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
Notes
-----
.. deprecated:: 2.1.0
A deprecation warning is shown if ``extend_to``, ``only_edges`` or
``ordered`` are specified as positional arguments. In a future
release, these will need to be specified as keyword arguments.
Examples
--------
>>> import shapely
>>> from shapely import LineString, MultiPoint, Point
>>> points = MultiPoint([(2, 2), (4, 2)])
>>> shapely.voronoi_polygons(points).normalize()
<GEOMETRYCOLLECTION (POLYGON ((3 0, 3 4, 6 4, 6 0, 3 0)), POLYGON ((0 0, 0 4...>
>>> shapely.voronoi_polygons(points, only_edges=True)
<MULTILINESTRING ((3 4, 3 0))>
>>> shapely.voronoi_polygons(MultiPoint([(2, 2), (4, 2), (4.2, 2)]), 0.5, only_edges=True)
<MULTILINESTRING ((3 4.2, 3 -0.2))>
>>> shapely.voronoi_polygons(points, extend_to=LineString([(0, 0), (10, 10)]), only_edges=True)
<MULTILINESTRING ((3 10, 3 0))>
>>> shapely.voronoi_polygons(LineString([(2, 2), (4, 2)]), only_edges=True)
<MULTILINESTRING ((3 4, 3 0))>
>>> shapely.voronoi_polygons(Point(2, 2))
<GEOMETRYCOLLECTION EMPTY>
>>> shapely.voronoi_polygons(points, ordered=True)
<GEOMETRYCOLLECTION (POLYGON ((0 0, 0 4, 3 4, 3 0, 0 0)), POLYGON ((6 4, 6 0...>
shapely.within
Python Library Documentation: function within in module shapely.predicates
within(a, b, **kwargs)
Return True if geometry A is completely inside geometry B.
A is within B if no points of A lie in the exterior of B and at least one
point of the interior of A lies in the interior of B.
Parameters
----------
a, b : Geometry or array_like
Geometry or geometries to check.
**kwargs
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
See Also
--------
contains : ``within(A, B) == contains(B, A)``
prepare : improve performance by preparing ``a`` (the first argument)
Examples
--------
>>> import shapely
>>> from shapely import LineString, Point, Polygon
>>> line = LineString([(0, 0), (1, 1)])
>>> shapely.within(Point(0, 0), line)
False
>>> shapely.within(Point(0.5, 0.5), line)
True
>>> area = Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)])
>>> shapely.within(Point(0, 0), area)
False
>>> shapely.within(line, area)
True
>>> shapely.within(LineString([(0, 0), (2, 2)]), area)
False
>>> polygon_with_hole = Polygon(
... [(0, 0), (0, 10), (10, 10), (10, 0), (0, 0)],
... holes=[[(2, 2), (2, 4), (4, 4), (4, 2), (2, 2)]]
... )
>>> shapely.within(Point(1, 1), polygon_with_hole)
True
>>> shapely.within(Point(2, 2), polygon_with_hole)
False
>>> shapely.within(LineString([(1, 1), (5, 5)]), polygon_with_hole)
False
>>> shapely.within(area, area)
True
>>> shapely.within(None, area)
False