__add__#

GeosArray.__add__(other)#

Performs an addition between the coordinates array and other.

Parameters:

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

Note

When adding 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 ((10 1, 12 13, 4 15, 6 7, 10 1))>,
 <shapely.Geometry POLYGON ((11 1, 13 13, 5 15, 7 7, 11 1))>,
 <shapely.Geometry POLYGON ((12 1, 14 13, 6 15, 8 7, 12 1))>,
 <shapely.Geometry POLYGON ((13 1, 15 13, 7 15, 9 7, 13 1))>]
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 ((10 1, 10 11, 0 11, 0 1, 10 1))>,

<shapely.Geometry POLYGON ((13 3, 13 13, 3 13, 3 3, 13 3))>, <shapely.Geometry POLYGON ((16 5, 16 15, 6 15, 6 5, 16 5))>, <shapely.Geometry POLYGON ((19 7, 19 17, 9 17, 9 7, 19 7))>]

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 ((11 1, 11 11, 1 11, 1 1, 11 1))>,

<shapely.Geometry POLYGON ((13 2, 13 12, 3 12, 3 2, 13 2))>, <shapely.Geometry POLYGON ((15 3, 15 13, 5 13, 5 3, 15 3))>, <shapely.Geometry POLYGON ((17 4, 17 14, 7 14, 7 4, 17 4))>]

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

<shapely.Geometry POLYGON ((21 10, 21 20, 11 20, 11 10, 21 10))>, <shapely.Geometry POLYGON ((22 10, 22 20, 12 20, 12 10, 22 10))>, <shapely.Geometry POLYGON ((23 10, 23 20, 13 20, 13 10, 23 10))>]

Length: 4, dtype: geos