def set_raster_origin(data, coords, direction):
""" Converts Data and Coordinates Origin
.. versionadded 0.10.0
Parameters
----------
data : :class:`numpy:numpy.ndarray`
Array of shape (rows, cols) or (bands, rows, cols) containing
the data values.
coords : :class:`numpy:numpy.ndarray`
Array of shape (rows, cols, 2) containing xy-coordinates.
direction : str
'lower' or 'upper', direction in which to convert data and coordinates.
Returns
-------
data : :class:`numpy:numpy.ndarray`
Array of shape (rows, cols) or (bands, rows, cols) containing
the data values.
coords : :class:`numpy:numpy.ndarray`
Array of shape (rows, cols, 2) containing xy-coordinates.
"""
x_sp, y_sp = coords[1, 1] - coords[0, 0]
origin = ('lower' if y_sp > 0 else 'upper')
same = (origin == direction)
if not same:
data = np.flip(data, axis=-2)
coords = np.flip(coords, axis=-3)
# we need to shift y-coordinate if data and coordinates have the same
# number of rows and cols
if data.shape[-2:] == coords.shape[:2]:
coords += [0, y_sp]
return data, coords
评论列表
文章目录