Skip to content

write_geopackage

write_geopackage(
    path: str | PathLike[str],
    data: PointSet | Polylines,
    *,
    layer: str | None = None,
) -> None

Writes a PointSet or Polylines as a GeoPackage feature layer.

Parameters:

Name Type Description Default
path str or Path

The .gpkg file; created when missing, otherwise its other layers are kept.

required
data PointSet or Polylines

Points are written as POINT Z, one row each. Polylines are written one row per feature: as MULTILINESTRING Z when all parts are open, as MULTIPOLYGON Z when all are closed, rings grouped into polygons by nesting, exteriors counter-clockwise and holes clockwise; split mixed ones by closed. A feature without parts is a NULL geometry. Numeric columns are written as DOUBLE, text as TEXT, nulls as NULL.

required
layer str

Feature table name, the file stem by default. A layer of that name is replaced.

None
Notes

An "EPSG:<code>" CRS is stored as that EPSG spatial reference, any other as a custom one whose definition is the CRS text, which GIS software expects as WKT. Without a CRS the layer uses the undefined Cartesian reference (-1).

Raises:

Type Description
InvalidInput

When data is neither container, parts mix open and closed, an attribute is named fid or geom, layer starts with gpkg_, or the file exists and is not a GeoPackage.

used in