__mul__#

GeosArray.__mul__(other)#

Performs a multiplication between the coordinates array and other.

Parameters:

other (array-like) – Item to multiply with the coordinates (max 2-dimensional).

Note

When multiplying the coordinates array and 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 ((0 0, 20 30, 0 50, 0 0, 0 0))>,
 <shapely.Geometry POLYGON ((0 0, 22 30, 4 50, 6 0, 0 0))>,
 <shapely.Geometry POLYGON ((0 0, 24 30, 8 50, 12 0, 0 0))>,
 <shapely.Geometry POLYGON ((0 0, 26 30, 12 50, 18 0, 0 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 ((0 0, 0 10, 0 10, 0 0, 0 0))>,

<shapely.Geometry POLYGON ((22 0, 22 30, 2 30, 2 0, 22 0))>, <shapely.Geometry POLYGON ((48 0, 48 50, 8 50, 8 0, 48 0))>, <shapely.Geometry POLYGON ((78 0, 78 70, 18 70, 18 0, 78 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 ((22 0, 22 20, 2 20, 2 0, 22 0))>, <shapely.Geometry POLYGON ((36 0, 36 30, 6 30, 6 0, 36 0))>, <shapely.Geometry POLYGON ((52 0, 52 40, 12 40, 12 0, 52 0))>]

Length: 4, dtype: geos >>> # Broadcast coordinates >>> other = np.array([10,10]) >>> other.shape (2,) >>> data * other <GeosArray> [<shapely.Geometry POLYGON ((100 0, 100 100, 0 100, 0 0, 100 0))>,

<shapely.Geometry POLYGON ((110 0, 110 100, 10 100, 10 0, 110 0))>, <shapely.Geometry POLYGON ((120 0, 120 100, 20 100, 20 0, 120 0))>, <shapely.Geometry POLYGON ((130 0, 130 100, 30 100, 30 0, 130 0))>]

Length: 4, dtype: geos