Skip to main content

generate

generate(
    domain,
    *,
    cell_size,
    refinement_areas=(),
    transition_rows=1,
    water_areas=(),
    water_removal='centre',
    crs=None,
    origin=None,
    progress=None,
)

Generate a refined quad mesh over a domain.

Parameters

Name Type Description Default
domain (shapely.Polygon, shapely.MultiPolygon, Areas or GeoDataFrame) The area the mesh covers; its CRS is the CRS of the mesh and must be projected. A lattice square is kept whole when it overlaps the domain, so cells along the outer edge may reach slightly outside it. Holes in the domain are clipped like water areas, cell by cell, with the water removal rule. required
cell_size float Side length of the base cell; any positive length. required
refinement_areas iterable of (shapely geometry, int), or Areas Polygons (pairs, or :func:read_refinement_areas) paired with the refinement level their cells must reach (1 or higher); level L gives cells of cell_size / 2**L. The highest level among the areas is the highest level of the mesh. ()
transition_rows int or sequence of int Rows of finer cells kept around a finer area before the mesh coarsens, per step from coarse to fine: the first value is for the step from level 0 to 1. One value per level step, or a single value for every step; each at least 0. With 0 only the cells touching a finer area get its level and the 2:1 balance makes the transition. 1
water_areas iterable of shapely geometry, Areas or GeoDataFrame Polygons where no cells are kept, because the 1D network carries the flow there. Giving water areas applies them. ()
water_removal ('centre', 'inside', 'touches') Water removal rule, applied cell by cell to the finished mesh, as clipping with MeshKernel does: a cell is removed when its circumcentre (triangle) or centroid lies in water ("centre", default, MeshKernel’s FACES_WITH_INCLUDED_CIRCUMCENTERS), only when it lies completely in water ("inside"), or as soon as it touches water ("touches"). The remaining small cells follow the water’s edge. "centre"
crs pyproj.CRS or str or int CRS of input that carries none (shapely geometries). Input without CRS raises an error unless it is given; input with its own CRS is transformed to the CRS of the domain. None
origin tuple of float A point of the lattice, so that the mesh lines up with an existing mesh or raster. By default the lower-left corner of the domain rounded down to a multiple of cell_size. None
progress callable Called as progress(fraction, message) while the mesh is generated, with a fraction that rises from 0 to 1 and an English message. Returning True cancels the run. None

Returns

Name Type Description
Mesh The mesh in the CRS of the domain, its faces counterclockwise, on the lattice through origin.

Raises

Name Type Description
InputError If input has no CRS and crs is not given, the CRS of the domain is geographic, the domain is empty or not polygonal, the cell size is not a positive length, a refinement area is empty or not polygonal, a level is not an integer of at least 1, the transition rows are not one integer of at least 0 per level step, a water area is empty or not polygonal, the water removal rule is unknown, the origin is not two finite numbers, or no cells are left inside the domain.
OrthogonalityRepairError If the orthogonality repair cannot make every internal edge FM-orthogonal; it carries the raw mesh (mesh) and the problem locations (bad_points).
Cancelled If the progress callback returned True.

Examples

>>> from shapely import Point, box
>>> mesh = generate(
...     box(0, 0, 400, 300),
...     cell_size=25.0,
...     refinement_areas=[(Point(200, 150).buffer(40), 2)],
...     transition_rows=[1, 1],
...     crs="EPSG:28992",
... )
>>> mesh.lattice.unit
6.25