Assume I have an array of rings, and an array of indices mapping each ring to the polygon they belong:
import pygeos
# 1D array of rings with shape (10, )
rings = pygeos.linearrings(np.random.randn(10, 3, 2))
polygon_indices = np.array([0,1,1,2,2,2,3,4,4,5])
with some manipulation of the indices, I can get split the rings into shells and holes, and get the hole indices:
polygon_indices_shell = np.insert(np.diff(polygon_indices), 0, 1)
shells_mask = polygon_indices == 1
holes_mask = polygon_indices == 0
shells = rings[shells_mask].copy()
holes = rings[holes_mask].copy()
hole_indices = polygon_indices[holes_mask].copy()
but passing those arguments (I even added copy() to be sure) gives the following error:
In [5]: pygeos.polygons(shells, holes, indices=hole_indices)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-5-76bad8a0d07f> in <module>
----> 1 pygeos.polygons(rings[shells_mask].copy(), rings[holes_mask].copy(), indices=polygon_indices[holes_mask].copy())
~/scipy/repos/pygeos/pygeos/decorators.py in wrapped(*args, **kwargs)
54 for arr in array_args:
55 arr.flags.writeable = False
---> 56 return func(*args, **kwargs)
57 finally:
58 for arr, old_flag in zip(array_args, old_flags):
~/scipy/repos/pygeos/pygeos/creation.py in polygons(shells, holes, indices, **kwargs)
164 return lib.polygons(shells, holes, **kwargs)
165 else:
--> 166 return polygons_1d(shells, holes, indices)
167
168
~/scipy/repos/pygeos/pygeos/_geometry.pyx in pygeos._geometry.polygons_1d()
~/scipy/repos/pygeos/pygeos/_geometry.cpython-38-x86_64-linux-gnu.so in View.MemoryView.memoryview_cwrapper()
~/scipy/repos/pygeos/pygeos/_geometry.cpython-38-x86_64-linux-gnu.so in View.MemoryView.memoryview.__cinit__()
ValueError: buffer source array is read-only
Is there something that I am missing that I am doing wrong?
Assume I have an array of rings, and an array of indices mapping each ring to the polygon they belong:
with some manipulation of the indices, I can get split the rings into shells and holes, and get the hole indices:
but passing those arguments (I even added
copy()to be sure) gives the following error:Is there something that I am missing that I am doing wrong?