xrspatial.terrain.generate_terrain

xrspatial.terrain.generate_terrain(agg: xarray.core.dataarray.DataArray, x_range: tuple = (0, 500), y_range: tuple = (0, 500), seed: int = 10, zfactor: int = 4000, full_extent: Optional[Union[Tuple, List]] = None, name: str = 'terrain') xarray.core.dataarray.DataArray[source]

Generates a pseudo-random terrain which can be helpful for testing raster functions.

Parameters
  • x_range (tuple, default=(0, 500)) – Range of x values.

  • x_range – Range of y values.

  • seed (int, default=10) – Seed for random number generator.

  • zfactor (int, default=4000) – Multipler for z values.

  • full_extent (str, default=None) – bbox<xmin, ymin, xmax, ymax>. Full extent of coordinate system.

Returns

terrain – 2D array of generated terrain values.

Return type

xr.DataArray

References

Examples

import numpy as np
import xarray as xr
from xrspatial import generate_terrain

W = 4
H = 3
data = np.zeros((H, W), dtype=np.float32)
raster = xr.DataArray(data, dims=['y', 'x'])

xrange = (-20e6, 20e6)
yrange = (-20e6, 20e6)
seed = 2
zfactor = 10

terrain = generate_terrain(raster, xrange, yrange, seed, zfactor)
>>> print(terrain)
<xarray.DataArray 'terrain' (y: 3, x: 4)>
array([[ 6.8067746,  5.263137 ,  4.664292 ,  6.821344 ],
       [ 7.4834156,  6.9849734,  4.3545456,  0.       ],
       [ 6.7674546, 10.       ,  7.0946655,  7.015267 ]], dtype=float32)  # noqa
Coordinates:
  * x        (x) float64 -1.5e+07 -5e+06 5e+06 1.5e+07
  * y        (y) float64 -1.333e+07 0.0 1.333e+07
Attributes:
    res:      (10000000.0, -13333333.333333334)