Skip to main content

Read layers from a GeoPackage

Most model input lives in GIS layers. read_domain, read_refinement_areas and read_water_areas read a layer of a GeoPackage or shapefile (with pyogrio; geopandas is not needed) and keep its CRS.

The example GeoPackage model.gpkg has three layers:

modelgebied  Polygon
verfijning   Polygon
water        Polygon

Read and generate

from refined_quads import (
    generate,
    read_domain,
    read_refinement_areas,
    read_water_areas,
)

domain = read_domain(gpkg, "modelgebied")
areas = read_refinement_areas(gpkg, "verfijning", level="refinement")
water = read_water_areas(gpkg, "water")

quad_mesh = generate(
    domain,
    cell_size=32.0,
    refinement_areas=areas,
    transition_rows=1,
    water_areas=water,
)
print(quad_mesh)
Mesh(nodes=843, faces=912, cell_size=32, levels=2, crs=EPSG:28992)
2026-11-26T12:17:40.018960 image/svg+xml Matplotlib v3.11.2, https://matplotlib.org/

Rules

  • A file with one layer needs no layer name. With several layers the name is required; without it you get an error that lists the layers.
  • level is the name of a column with the refinement level per polygon, or one integer for the whole layer (level=3). A missing or invalid level (0, a negative number, 2.5, empty) raises an error that names the feature.
  • All polygons of the domain layer are merged into one (multi)polygon.
  • The mesh gets the CRS of the domain, and other layers are transformed to it. A layer without CRS raises an error unless you pass crs= for it. A geographic CRS (degrees) for the domain raises an error, as cell sizes must be in metres.
  • Instead of a path you may pass a GeoDataFrame, or any object with geometry and crs attributes: read_refinement_areas(frame, level="refinement").
  • Plain shapely geometries have no CRS: pass crs= to generate (see the tutorial).