__floordiv__#
- GeosArray.__floordiv__(other)#
Performs a division between the coordinates array and other.
- Parameters:
other (array-like) – Item to divide the coordinates with (max 2-dimensional).
Note
When dividing the coordinates array by other, standard NumPy broadcasting rules apply. In order to reduce the friction for users, we perform two checks before adding the arrays.
Firstly, we decide whether to use the Z-dimension for the computation, depending on the shape of other:
other.ndim >= 2 and other.shape[1] == 2: Do not use Z-dimension.
other.ndim >= 2 and other.shape[1] == 3: Do use Z-dimension.
else: Use Z-dimension if there are any.
Secondly, if other.shape[0] == self.data.shape[0], we automatically repeat each coordinate pair to the number of coordinates of its corresponding polygon. This allows you to easily add different coordinate pairs to each polygon.
Example
>>> import shapely >>> import pgpd >>> data = pgpd.GeosArray(shapely.box(range(4), 0, range(10,14), 10)) >>> data <GeosArray> [<shapely.Geometry POLYGON ((10 0, 10 10, 0 10, 0 0, 10 0))>, <shapely.Geometry POLYGON ((11 0, 11 10, 1 10, 1 0, 11 0))>, <shapely.Geometry POLYGON ((12 0, 12 10, 2 10, 2 0, 12 0))>, <shapely.Geometry POLYGON ((13 0, 13 10, 3 10, 3 0, 13 0))>] Length: 4, dtype: geos
Providing values for each coordinate: >>> other = np.tile([0, 1, 2, 3, 4, 5, 6, 7, 0, 1], 4).reshape(20, 2) >>> other array([[0, 1],
[2, 3], [4, 5], [6, 7], [0, 1], [0, 1], [2, 3], [4, 5], [6, 7], [0, 1], [0, 1], [2, 3], [4, 5], [6, 7], [0, 1], [0, 1], [2, 3], [4, 5], [6, 7], [0, 1]])
>>> data // other <GeosArray> [<shapely.Geometry POLYGON ((inf 0, 5 3, 0 2, 0 0, inf 0))>, <shapely.Geometry POLYGON ((inf 0, 5 3, 0 2, 0 0, inf 0))>, <shapely.Geometry POLYGON ((inf 0, 6 3, 0 2, 0 0, inf 0))>, <shapely.Geometry POLYGON ((inf 0, 6 3, 0 2, 0 0, inf 0))>] Length: 4, dtype: geos
Provide coordinates for each polygon: >>> other = np.array([[0, 1], [2, 3], [4, 5], [6, 7]]) >>> data // other <GeosArray> [<shapely.Geometry POLYGON ((inf 0, inf 10, -nan 10, -nan 0, inf 0))>,
<shapely.Geometry POLYGON ((5 0, 5 3, 0 3, 0 0, 5 0))>, <shapely.Geometry POLYGON ((3 0, 3 2, 0 2, 0 0, 3 0))>, <shapely.Geometry POLYGON ((2 0, 2 1, 0 1, 0 0, 2 0))>]
Length: 4, dtype: geos
NumPy broadcasting still works: >>> # Broadcast X,Y(,Z) >>> other = np.array([1,2,3,4])[…, None] >>> other.shape (4, 1) >>> data // other <GeosArray> [<shapely.Geometry POLYGON ((10 0, 10 10, 0 10, 0 0, 10 0))>,
<shapely.Geometry POLYGON ((5 0, 5 5, 0 5, 0 0, 5 0))>, <shapely.Geometry POLYGON ((4 0, 4 3, 0 3, 0 0, 4 0))>, <shapely.Geometry POLYGON ((3 0, 3 2, 0 2, 0 0, 3 0))>]
Length: 4, dtype: geos >>> # Broadcast coordinates >>> other = np.array([10,10]) >>> other.shape (2,) >>> data // other <GeosArray> [<shapely.Geometry POLYGON ((1 0, 1 1, 0 1, 0 0, 1 0))>,
<shapely.Geometry POLYGON ((1 0, 1 1, 0 1, 0 0, 1 0))>, <shapely.Geometry POLYGON ((1 0, 1 1, 0 1, 0 0, 1 0))>, <shapely.Geometry POLYGON ((1 0, 1 1, 0 1, 0 0, 1 0))>]
Length: 4, dtype: geos