wradlib.georef.polar.centroid_to_polyvert

wradlib.georef.polar.centroid_to_polyvert(centroid, delta)

Calculates the 2-D Polygon vertices necessary to form a rectangular polygon around the centroid’s coordinates.

The vertices order will be clockwise, as this is the convention used by ESRI’s shapefile format for a polygon.

Parameters:
  • centroid (array_like) – List of 2-D coordinates of the center point of the rectangle.
  • delta (scalar or numpy.ndarray) – Symmetric distances of the vertices from the centroid in each direction. If delta is scalar, it is assumed to apply to both dimensions.
Returns:

vertices (numpy.ndarray) – An array with 5 vertices per centroid.

Note

The function can currently only deal with 2-D data (If you come up with a higher dimensional version of ‘clockwise’ you’re welcome to add it). The data is then assumed to be organized within the centroid array with the last dimension being the 2-D coordinates of each point.

Examples

>>> centroid_to_polyvert([0., 1.], [0.5, 1.5])
array([[-0.5, -0.5],
       [-0.5,  2.5],
       [ 0.5,  2.5],
       [ 0.5, -0.5],
       [-0.5, -0.5]])
>>> centroid_to_polyvert(np.arange(4).reshape((2,2)), 0.5)
array([[[-0.5,  0.5],
        [-0.5,  1.5],
        [ 0.5,  1.5],
        [ 0.5,  0.5],
        [-0.5,  0.5]],
<BLANKLINE>
       [[ 1.5,  2.5],
        [ 1.5,  3.5],
        [ 2.5,  3.5],
        [ 2.5,  2.5],
        [ 1.5,  2.5]]])