shapely 2.2.0rc1__cp315-cp315-win32.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- shapely/__init__.py +66 -0
- shapely/_coverage.py +275 -0
- shapely/_enum.py +32 -0
- shapely/_geometry.py +1121 -0
- shapely/_geometry_helpers.cp315-win32.lib +0 -0
- shapely/_geometry_helpers.cp315-win32.pyd +0 -0
- shapely/_geos.cp315-win32.lib +0 -0
- shapely/_geos.cp315-win32.pyd +0 -0
- shapely/_geos.pxd +56 -0
- shapely/_pygeos_api.pxd +60 -0
- shapely/_ragged_array.py +475 -0
- shapely/_version.py +4 -0
- shapely/affinity.py +266 -0
- shapely/algorithms/__init__.py +1 -0
- shapely/algorithms/_oriented_envelope.py +56 -0
- shapely/algorithms/cga.py +50 -0
- shapely/algorithms/polylabel.py +43 -0
- shapely/conftest.py +70 -0
- shapely/constructive.py +1614 -0
- shapely/coordinates.py +463 -0
- shapely/coords.py +119 -0
- shapely/creation.py +854 -0
- shapely/decorators.py +194 -0
- shapely/errors.py +79 -0
- shapely/geometry/__init__.py +27 -0
- shapely/geometry/base.py +1252 -0
- shapely/geometry/collection.py +63 -0
- shapely/geometry/geo.py +154 -0
- shapely/geometry/linestring.py +216 -0
- shapely/geometry/multilinestring.py +100 -0
- shapely/geometry/multipoint.py +109 -0
- shapely/geometry/multipolygon.py +135 -0
- shapely/geometry/point.py +171 -0
- shapely/geometry/polygon.py +364 -0
- shapely/geos.py +17 -0
- shapely/io.py +413 -0
- shapely/lib.cp315-win32.lib +0 -0
- shapely/lib.cp315-win32.pyd +0 -0
- shapely/linear.py +233 -0
- shapely/measurement.py +350 -0
- shapely/ops.py +712 -0
- shapely/plotting.py +222 -0
- shapely/predicates.py +1391 -0
- shapely/prepared.py +74 -0
- shapely/set_operations.py +775 -0
- shapely/speedups.py +39 -0
- shapely/strtree.py +542 -0
- shapely/testing.py +208 -0
- shapely/tests/__init__.py +0 -0
- shapely/tests/common.py +283 -0
- shapely/tests/geometry/__init__.py +0 -0
- shapely/tests/geometry/test_collection.py +90 -0
- shapely/tests/geometry/test_coords.py +127 -0
- shapely/tests/geometry/test_decimal.py +117 -0
- shapely/tests/geometry/test_emptiness.py +98 -0
- shapely/tests/geometry/test_equality.py +273 -0
- shapely/tests/geometry/test_format.py +98 -0
- shapely/tests/geometry/test_geometry_base.py +431 -0
- shapely/tests/geometry/test_hash.py +28 -0
- shapely/tests/geometry/test_linestring.py +232 -0
- shapely/tests/geometry/test_multi.py +11 -0
- shapely/tests/geometry/test_multilinestring.py +77 -0
- shapely/tests/geometry/test_multipoint.py +97 -0
- shapely/tests/geometry/test_multipolygon.py +189 -0
- shapely/tests/geometry/test_point.py +201 -0
- shapely/tests/geometry/test_polygon.py +467 -0
- shapely/tests/legacy/__init__.py +0 -0
- shapely/tests/legacy/conftest.py +12 -0
- shapely/tests/legacy/data/emptypoint_1.8.5.post1.pickle +0 -0
- shapely/tests/legacy/data/emptypolygon_1.8.5.post1.pickle +0 -0
- shapely/tests/legacy/data/geometrycollection_1.8.5.post1.pickle +0 -0
- shapely/tests/legacy/data/linearring_1.8.5.post1.pickle +0 -0
- shapely/tests/legacy/data/linestring_1.8.5.post1.pickle +0 -0
- shapely/tests/legacy/data/multilinestring_1.8.5.post1.pickle +0 -0
- shapely/tests/legacy/data/multipoint_1.8.5.post1.pickle +0 -0
- shapely/tests/legacy/data/multipolygon_1.8.5.post1.pickle +0 -0
- shapely/tests/legacy/data/point2d_1.8.5.post1.pickle +0 -0
- shapely/tests/legacy/data/point3d_1.8.5.post1.pickle +0 -0
- shapely/tests/legacy/data/polygon_1.8.5.post1.pickle +0 -0
- shapely/tests/legacy/test_affinity.py +308 -0
- shapely/tests/legacy/test_box.py +20 -0
- shapely/tests/legacy/test_buffer.py +173 -0
- shapely/tests/legacy/test_cga.py +51 -0
- shapely/tests/legacy/test_clip_by_rect.py +119 -0
- shapely/tests/legacy/test_create_inconsistent_dimensionality.py +217 -0
- shapely/tests/legacy/test_delaunay.py +32 -0
- shapely/tests/legacy/test_empty_polygons.py +22 -0
- shapely/tests/legacy/test_equality.py +24 -0
- shapely/tests/legacy/test_geointerface.py +118 -0
- shapely/tests/legacy/test_invalid_geometries.py +26 -0
- shapely/tests/legacy/test_linear_referencing.py +72 -0
- shapely/tests/legacy/test_linemerge.py +43 -0
- shapely/tests/legacy/test_locale.py +52 -0
- shapely/tests/legacy/test_make_valid.py +15 -0
- shapely/tests/legacy/test_mapping.py +14 -0
- shapely/tests/legacy/test_minimum_clearance.py +30 -0
- shapely/tests/legacy/test_ndarrays.py +42 -0
- shapely/tests/legacy/test_nearest.py +18 -0
- shapely/tests/legacy/test_operations.py +124 -0
- shapely/tests/legacy/test_operators.py +60 -0
- shapely/tests/legacy/test_orient.py +92 -0
- shapely/tests/legacy/test_parallel_offset.py +60 -0
- shapely/tests/legacy/test_persist.py +48 -0
- shapely/tests/legacy/test_pickle.py +81 -0
- shapely/tests/legacy/test_polygonize.py +43 -0
- shapely/tests/legacy/test_polylabel.py +85 -0
- shapely/tests/legacy/test_predicates.py +95 -0
- shapely/tests/legacy/test_prepared.py +65 -0
- shapely/tests/legacy/test_products_z.py +13 -0
- shapely/tests/legacy/test_shape.py +63 -0
- shapely/tests/legacy/test_shared_paths.py +45 -0
- shapely/tests/legacy/test_singularity.py +15 -0
- shapely/tests/legacy/test_snap.py +24 -0
- shapely/tests/legacy/test_split.py +331 -0
- shapely/tests/legacy/test_substring.py +220 -0
- shapely/tests/legacy/test_svg.py +213 -0
- shapely/tests/legacy/test_transform.py +116 -0
- shapely/tests/legacy/test_union.py +67 -0
- shapely/tests/legacy/test_validation.py +9 -0
- shapely/tests/legacy/test_vectorized.py +108 -0
- shapely/tests/legacy/test_voronoi_diagram.py +129 -0
- shapely/tests/legacy/test_wkb.py +171 -0
- shapely/tests/legacy/test_wkt.py +61 -0
- shapely/tests/legacy/threading_test.py +44 -0
- shapely/tests/test_constructive.py +1869 -0
- shapely/tests/test_coordinates.py +488 -0
- shapely/tests/test_coverage.py +520 -0
- shapely/tests/test_creation.py +771 -0
- shapely/tests/test_creation_indices.py +585 -0
- shapely/tests/test_decorators.py +138 -0
- shapely/tests/test_geometry.py +845 -0
- shapely/tests/test_io.py +1347 -0
- shapely/tests/test_linear.py +237 -0
- shapely/tests/test_measurement.py +368 -0
- shapely/tests/test_misc.py +224 -0
- shapely/tests/test_plotting.py +121 -0
- shapely/tests/test_predicates.py +490 -0
- shapely/tests/test_ragged_array.py +667 -0
- shapely/tests/test_set_operations.py +503 -0
- shapely/tests/test_strtree.py +1950 -0
- shapely/tests/test_testing.py +97 -0
- shapely/validation.py +55 -0
- shapely/vectorized/__init__.py +91 -0
- shapely/wkb.py +70 -0
- shapely/wkt.py +82 -0
- shapely-2.2.0rc1.dist-info/DELVEWHEEL +2 -0
- shapely-2.2.0rc1.dist-info/METADATA +202 -0
- shapely-2.2.0rc1.dist-info/RECORD +155 -0
- shapely-2.2.0rc1.dist-info/WHEEL +4 -0
- shapely-2.2.0rc1.dist-info/licenses/LICENSE.txt +29 -0
- shapely-2.2.0rc1.dist-info/licenses/LICENSE_GEOS +509 -0
- shapely-2.2.0rc1.dist-info/licenses/LICENSE_win32 +26 -0
- shapely.libs/geos-339a068fc2c3b3a5e6da825afd035c86.dll +0 -0
- shapely.libs/geos_c-d9b161c46a86afa9b6930f79df581208.dll +0 -0
- shapely.libs/msvcp140-09f509019518248d5e55824310a27f3e.dll +0 -0
shapely/__init__.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""Manipulation and analysis of geometric objects in the Cartesian plane."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
# start delvewheel patch
|
|
5
|
+
def _delvewheel_patch_1_13_1():
|
|
6
|
+
import os
|
|
7
|
+
if os.path.isdir(libs_dir := os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, 'shapely.libs'))):
|
|
8
|
+
os.add_dll_directory(libs_dir)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
_delvewheel_patch_1_13_1()
|
|
12
|
+
del _delvewheel_patch_1_13_1
|
|
13
|
+
# end delvewheel patch
|
|
14
|
+
|
|
15
|
+
import os
|
|
16
|
+
import platform
|
|
17
|
+
|
|
18
|
+
if platform.system() == "Windows":
|
|
19
|
+
try:
|
|
20
|
+
from shapely.lib import GEOSException
|
|
21
|
+
except ImportError: # DLL load failed while importing lib...
|
|
22
|
+
# This is possibly a local build, which requires an
|
|
23
|
+
# environment variable GEOS_LIBDIR to be specified at runtime
|
|
24
|
+
# e.g.: set GEOS_LIBDIR=C:\OSGeo4W\bin
|
|
25
|
+
if "GEOS_LIBDIR" in os.environ:
|
|
26
|
+
os.add_dll_directory(os.environ["GEOS_LIBDIR"])
|
|
27
|
+
else:
|
|
28
|
+
raise
|
|
29
|
+
|
|
30
|
+
del os, platform
|
|
31
|
+
|
|
32
|
+
from shapely.lib import GEOSException
|
|
33
|
+
from shapely.lib import Geometry
|
|
34
|
+
from shapely.lib import geos_version, geos_version_string
|
|
35
|
+
from shapely.lib import geos_capi_version, geos_capi_version_string
|
|
36
|
+
from shapely.errors import setup_signal_checks
|
|
37
|
+
from shapely._geometry import *
|
|
38
|
+
from shapely.creation import *
|
|
39
|
+
from shapely.constructive import *
|
|
40
|
+
from shapely.predicates import *
|
|
41
|
+
from shapely.measurement import *
|
|
42
|
+
from shapely.set_operations import *
|
|
43
|
+
from shapely.linear import *
|
|
44
|
+
from shapely.coordinates import *
|
|
45
|
+
from shapely.strtree import *
|
|
46
|
+
from shapely.io import *
|
|
47
|
+
from shapely._coverage import *
|
|
48
|
+
|
|
49
|
+
# Submodule always needs to be imported to ensure Geometry subclasses are registered
|
|
50
|
+
from shapely.geometry import (
|
|
51
|
+
Point,
|
|
52
|
+
LineString,
|
|
53
|
+
Polygon,
|
|
54
|
+
MultiPoint,
|
|
55
|
+
MultiLineString,
|
|
56
|
+
MultiPolygon,
|
|
57
|
+
GeometryCollection,
|
|
58
|
+
LinearRing,
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
from shapely._version import (
|
|
62
|
+
__version__,
|
|
63
|
+
__git_version__,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
setup_signal_checks()
|
shapely/_coverage.py
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
from shapely import Geometry, GeometryType, lib
|
|
4
|
+
from shapely._enum import ParamEnum
|
|
5
|
+
from shapely._geometry import get_parts
|
|
6
|
+
from shapely.decorators import requires_geos
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"coverage_clean",
|
|
10
|
+
"coverage_invalid_edges",
|
|
11
|
+
"coverage_is_valid",
|
|
12
|
+
"coverage_simplify",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class CoverageCleanMergeStrategy(ParamEnum):
|
|
17
|
+
"""Enumeration of coverage clean merge strategies.
|
|
18
|
+
|
|
19
|
+
Determines which neighboring polygon to merge overlapping areas into.
|
|
20
|
+
|
|
21
|
+
Attributes
|
|
22
|
+
----------
|
|
23
|
+
longest_border : int
|
|
24
|
+
Polygon with longest common border is chosen.
|
|
25
|
+
max_area : int
|
|
26
|
+
Polygon with largest area is chosen.
|
|
27
|
+
min_area : int
|
|
28
|
+
Polygon with smallest area is chosen.
|
|
29
|
+
min_index : int
|
|
30
|
+
Polygon with smallest input index is chosen.
|
|
31
|
+
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
longest_border = 0
|
|
35
|
+
max_area = 1
|
|
36
|
+
min_area = 2
|
|
37
|
+
min_index = 3
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@requires_geos("3.12.0")
|
|
41
|
+
def coverage_is_valid(geometry, gap_width=0.0, **kwargs):
|
|
42
|
+
"""Verify if a coverage is valid.
|
|
43
|
+
|
|
44
|
+
The coverage is represented by an array of polygonal geometries with
|
|
45
|
+
exactly matching edges and no overlap.
|
|
46
|
+
|
|
47
|
+
A valid coverage may contain holes (regions of no coverage). However,
|
|
48
|
+
sometimes it might be desirable to detect narrow gaps as invalidities in
|
|
49
|
+
the coverage. The `gap_width` parameter allows to specify the maximum
|
|
50
|
+
width of gaps to detect. When gaps are detected, this function will
|
|
51
|
+
return False and the `coverage_invalid_edges` function can be used to
|
|
52
|
+
find the edges of those gaps.
|
|
53
|
+
|
|
54
|
+
Geometries that are not Polygon or MultiPolygon are ignored.
|
|
55
|
+
|
|
56
|
+
.. versionadded:: 2.1.0
|
|
57
|
+
|
|
58
|
+
Parameters
|
|
59
|
+
----------
|
|
60
|
+
geometry : array_like
|
|
61
|
+
Array of geometries to verify.
|
|
62
|
+
gap_width : float, default 0.0
|
|
63
|
+
The maximum width of gaps to detect.
|
|
64
|
+
**kwargs
|
|
65
|
+
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
|
|
66
|
+
|
|
67
|
+
Returns
|
|
68
|
+
-------
|
|
69
|
+
bool
|
|
70
|
+
|
|
71
|
+
See Also
|
|
72
|
+
--------
|
|
73
|
+
coverage_invalid_edges, coverage_simplify
|
|
74
|
+
|
|
75
|
+
"""
|
|
76
|
+
geometries = np.asarray(geometry)
|
|
77
|
+
# we always consider the full array as a single coverage -> ravel the input
|
|
78
|
+
# to pass a 1D array
|
|
79
|
+
return lib.coverage_is_valid(geometries.ravel(order="K"), gap_width, **kwargs)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@requires_geos("3.12.0")
|
|
83
|
+
def coverage_invalid_edges(geometry, gap_width=0.0, **kwargs):
|
|
84
|
+
"""Verify if a coverage is valid and return invalid edges.
|
|
85
|
+
|
|
86
|
+
This functions returns linear indicators showing the location of invalid
|
|
87
|
+
edges (if any) in each polygon in the input array.
|
|
88
|
+
|
|
89
|
+
The coverage is represented by an array of polygonal geometries with
|
|
90
|
+
exactly matching edges and no overlap.
|
|
91
|
+
|
|
92
|
+
A valid coverage may contain holes (regions of no coverage). However,
|
|
93
|
+
sometimes it might be desirable to detect narrow gaps as invalidities in
|
|
94
|
+
the coverage. The `gap_width` parameter allows to specify the maximum
|
|
95
|
+
width of gaps to detect. When gaps are detected, the `coverage_is_valid`
|
|
96
|
+
function will return False and this function can be used to find the
|
|
97
|
+
edges of those gaps.
|
|
98
|
+
|
|
99
|
+
Geometries that are not Polygon or MultiPolygon are ignored.
|
|
100
|
+
|
|
101
|
+
.. versionadded:: 2.1.0
|
|
102
|
+
|
|
103
|
+
Parameters
|
|
104
|
+
----------
|
|
105
|
+
geometry : array_like
|
|
106
|
+
Array of geometries to verify.
|
|
107
|
+
gap_width : float, default 0.0
|
|
108
|
+
The maximum width of gaps to detect.
|
|
109
|
+
**kwargs
|
|
110
|
+
See :ref:`NumPy ufunc docs <ufuncs.kwargs>` for other keyword arguments.
|
|
111
|
+
|
|
112
|
+
Returns
|
|
113
|
+
-------
|
|
114
|
+
numpy.ndarray | shapely.Geometry
|
|
115
|
+
|
|
116
|
+
See Also
|
|
117
|
+
--------
|
|
118
|
+
coverage_is_valid, coverage_simplify
|
|
119
|
+
|
|
120
|
+
"""
|
|
121
|
+
geometries = np.asarray(geometry)
|
|
122
|
+
# we always consider the full array as a single coverage -> ravel the input
|
|
123
|
+
# to pass a 1D array
|
|
124
|
+
return lib.coverage_invalid_edges(geometries.ravel(order="K"), gap_width, **kwargs)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
@requires_geos("3.12.0")
|
|
128
|
+
def coverage_simplify(geometry, tolerance, *, simplify_boundary=True):
|
|
129
|
+
"""Return a simplified version of an input geometry using coverage simplification.
|
|
130
|
+
|
|
131
|
+
Assumes that the geometry forms a polygonal coverage. Under this assumption, the
|
|
132
|
+
function simplifies the edges using the Visvalingam-Whyatt algorithm, while
|
|
133
|
+
preserving a valid coverage. In the most simplified case, polygons are reduced to
|
|
134
|
+
triangles.
|
|
135
|
+
|
|
136
|
+
A collection of valid polygons is considered a coverage if the polygons are:
|
|
137
|
+
|
|
138
|
+
* **Non-overlapping** - polygons do not overlap (their interiors do not intersect)
|
|
139
|
+
* **Edge-Matched** - vertices along shared edges are identical
|
|
140
|
+
|
|
141
|
+
The function allows simplification of all edges including the outer boundaries of
|
|
142
|
+
the coverage or simplification of only the inner (shared) edges.
|
|
143
|
+
|
|
144
|
+
If there are other geometry types than Polygons or MultiPolygons present,
|
|
145
|
+
the function will raise an error.
|
|
146
|
+
|
|
147
|
+
If the geometry is polygonal but does not form a valid coverage due to overlaps,
|
|
148
|
+
it will be simplified but it may result in invalid topology.
|
|
149
|
+
|
|
150
|
+
.. versionadded:: 2.1.0
|
|
151
|
+
|
|
152
|
+
Parameters
|
|
153
|
+
----------
|
|
154
|
+
geometry : Geometry or array_like
|
|
155
|
+
tolerance : float or array_like
|
|
156
|
+
The degree of simplification roughly equal to the square root of the area
|
|
157
|
+
of triangles that will be removed.
|
|
158
|
+
simplify_boundary : bool, optional
|
|
159
|
+
By default (True), simplifies both internal edges of the coverage as well
|
|
160
|
+
as its boundary. If set to False, only simplifies internal edges.
|
|
161
|
+
|
|
162
|
+
Returns
|
|
163
|
+
-------
|
|
164
|
+
numpy.ndarray | shapely.Geometry
|
|
165
|
+
|
|
166
|
+
See Also
|
|
167
|
+
--------
|
|
168
|
+
coverage_is_valid, coverage_invalid_edges
|
|
169
|
+
|
|
170
|
+
Examples
|
|
171
|
+
--------
|
|
172
|
+
>>> import shapely
|
|
173
|
+
>>> from shapely import Polygon
|
|
174
|
+
>>> poly = Polygon([(0, 0), (20, 0), (20, 10), (10, 5), (0, 10), (0, 0)])
|
|
175
|
+
>>> shapely.coverage_simplify(poly, tolerance=2)
|
|
176
|
+
<POLYGON ((0 0, 20 0, 20 10, 10 5, 0 10, 0 0))>
|
|
177
|
+
"""
|
|
178
|
+
scalar = False
|
|
179
|
+
if isinstance(geometry, Geometry):
|
|
180
|
+
scalar = True
|
|
181
|
+
|
|
182
|
+
geometries = np.asarray(geometry)
|
|
183
|
+
shape = geometries.shape
|
|
184
|
+
geometries = geometries.ravel()
|
|
185
|
+
|
|
186
|
+
# create_collection acts on the inner axis
|
|
187
|
+
collections = lib.create_collection(
|
|
188
|
+
geometries, np.intc(GeometryType.GEOMETRYCOLLECTION)
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
simplified = lib.coverage_simplify(collections, tolerance, simplify_boundary)
|
|
192
|
+
parts = get_parts(simplified).reshape(shape)
|
|
193
|
+
if scalar:
|
|
194
|
+
return parts.item()
|
|
195
|
+
return parts
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
@requires_geos("3.14.0")
|
|
199
|
+
def coverage_clean(
|
|
200
|
+
geometry,
|
|
201
|
+
*,
|
|
202
|
+
gap_width=0.0,
|
|
203
|
+
snapping_distance=-1,
|
|
204
|
+
merge_strategy="longest_border",
|
|
205
|
+
):
|
|
206
|
+
"""Return a cleaned version of an input geometry.
|
|
207
|
+
|
|
208
|
+
Assumes that the geometry forms a polygonal coverage. Ensures that no polygons
|
|
209
|
+
overlap, small gaps are removed, and all shared edges are exactly identical.
|
|
210
|
+
|
|
211
|
+
A collection of valid polygons is considered a coverage if the polygons are:
|
|
212
|
+
|
|
213
|
+
* **Non-overlapping** - polygons do not overlap (their interiors do not intersect)
|
|
214
|
+
* **Edge-Matched** - vertices along shared edges are identical
|
|
215
|
+
|
|
216
|
+
If there are other geometry types than Polygons or MultiPolygons present,
|
|
217
|
+
the function will raise an error.
|
|
218
|
+
|
|
219
|
+
.. versionadded:: 2.2.0
|
|
220
|
+
|
|
221
|
+
Parameters
|
|
222
|
+
----------
|
|
223
|
+
geometry : Geometry or array_like
|
|
224
|
+
gap_width : float, default 0.0
|
|
225
|
+
Gaps smaller than this value are merged with the adjacent polygon with
|
|
226
|
+
longest shared shared border. Set to 0.0 to (default) for no removal
|
|
227
|
+
of gaps.
|
|
228
|
+
snapping_distance : float
|
|
229
|
+
Determines the node snapping step when nearby vertices are snapped
|
|
230
|
+
together. Set to -1 by default, which automatically finds a small snapping
|
|
231
|
+
distance based on the extend of the input. Set to 0.0 to disable snapping.
|
|
232
|
+
merge_strategy : {'longest_border', 'max_area', 'min_area', 'min_index'}, default 'longest_border'
|
|
233
|
+
Determines how overlapping areas are handled by choosing which polygons to merge
|
|
234
|
+
them into. CoverageCleanMergeStrategy.longest_border ('longest_border') chooses
|
|
235
|
+
polygon with longest common border. CoverageCleanMergeStrategy.max_area
|
|
236
|
+
('max_area') chooses polygon with largest area.
|
|
237
|
+
CoverageCleanMergeStrategy.min_area ('min_area') chooses polygon with smallest
|
|
238
|
+
area. CoverageCleanMergeStartegy.min_index ('min_index') chooses the first
|
|
239
|
+
encountered polygon.
|
|
240
|
+
|
|
241
|
+
Returns
|
|
242
|
+
-------
|
|
243
|
+
numpy.ndarray
|
|
244
|
+
|
|
245
|
+
See Also
|
|
246
|
+
--------
|
|
247
|
+
coverage_is_valid, coverage_invalid_edges, coverage_simplify
|
|
248
|
+
|
|
249
|
+
Examples
|
|
250
|
+
--------
|
|
251
|
+
>>> import shapely
|
|
252
|
+
>>> from shapely import box
|
|
253
|
+
>>> polygons = [box(0, 0, 1, 1), box(0.9, 0, 2, 1)]
|
|
254
|
+
>>> shapely.coverage_clean(polygons)
|
|
255
|
+
array([<POLYGON ((0 0, 0 1, 0.9 1, 1 1, 1 0, 0.9 0, 0 0))>,
|
|
256
|
+
<POLYGON ((1 1, 2 1, 2 0, 1 0, 1 1))>], dtype=object)
|
|
257
|
+
""" # noqa: E501
|
|
258
|
+
if not np.isscalar(merge_strategy):
|
|
259
|
+
raise TypeError("merge_strategy only accepts scalar values")
|
|
260
|
+
if isinstance(merge_strategy, str):
|
|
261
|
+
merge_strategy = CoverageCleanMergeStrategy.get_value(merge_strategy)
|
|
262
|
+
if isinstance(merge_strategy, int) and not CoverageCleanMergeStrategy.has_value(
|
|
263
|
+
merge_strategy
|
|
264
|
+
):
|
|
265
|
+
raise ValueError(f"not a valid merge strategy value: {merge_strategy}.")
|
|
266
|
+
|
|
267
|
+
geometries = np.asarray(geometry)
|
|
268
|
+
# we always consider the full array as a single coverage -> ravel the input
|
|
269
|
+
# to pass a 1D array
|
|
270
|
+
return lib.coverage_clean(
|
|
271
|
+
geometries.ravel(order="K"),
|
|
272
|
+
gap_width,
|
|
273
|
+
snapping_distance,
|
|
274
|
+
np.intc(merge_strategy),
|
|
275
|
+
)
|
shapely/_enum.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from enum import IntEnum
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class ParamEnum(IntEnum):
|
|
5
|
+
"""Wraps IntEnum to provide validation of a requested item.
|
|
6
|
+
|
|
7
|
+
Intended for enums used for function parameters.
|
|
8
|
+
|
|
9
|
+
Use enum.get_value(item) for this behavior instead of builtin enum[item].
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
@classmethod
|
|
13
|
+
def get_value(cls, item):
|
|
14
|
+
"""Validate item and raise a ValueError with valid options if not present."""
|
|
15
|
+
try:
|
|
16
|
+
return cls[item].value
|
|
17
|
+
except KeyError:
|
|
18
|
+
valid_options = {e.name for e in cls}
|
|
19
|
+
raise ValueError(
|
|
20
|
+
"'{}' is not a valid option, must be one of '{}'".format(
|
|
21
|
+
item, "', '".join(valid_options)
|
|
22
|
+
)
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
@classmethod
|
|
26
|
+
def has_value(cls, value):
|
|
27
|
+
"""Return whether integer value is a valid value in the enum."""
|
|
28
|
+
try:
|
|
29
|
+
cls(value)
|
|
30
|
+
return True
|
|
31
|
+
except ValueError:
|
|
32
|
+
return False
|