emsarray.operations.geometry#
Export the geometry of a dataset to a number of formats. The geometry is represented as a collection of Polygons.
- to_geojson(dataset)#
Make a
geojson.FeatureCollectionout of the cells in this dataset, one feature per cell.Each feature will include the linear index and the native index of the corresponding cell in its properties.
Note
The features list on the returned FeatureCollection is a generator. It can only be iterated over once. It is designed to work with
json.dumps()directly.- Parameters:
dataset (
xarray.Dataset) – The dataset to export as GeoJSON geometry.- Returns:
geojson.FeatureCollection– The geometry of this dataset as a FeatureCollection.
See also
- write_geojson(dataset, path)#
Export the geometry of this dataset to a GeoJSON file as a
geojson.FeatureCollectionwith one feature per cell.Each feature will include the linear index and the native index of the corresponding cell in its properties.
- Parameters:
dataset (
xarray.Dataset) – The dataset to export as GeoJSON geometry.path (
strorpathlib.Path) – The path where the geometry should be written to.
See also
- write_shapefile(dataset, target=None, *, shp=None, shx=None, dbf=None, prj=None, **kwargs)#
Write the geometry of this dataset to a Shapefile. Each polygon is saved as an individual record with
name,linear_index, andindexfields.- Parameters:
dataset (
xarray.Dataset) – The dataset to export the geometry for.target (
strorpathlib.Path, optional) – Where to save the shapefile. The names for the .shp, .shx, .dbf, and .prj files are derived from this. Optional, you can instead provide arguments for each individual file.shp, shx, dbf, prj (
strorpathlib.Pathoropened file handle) – Where to write the individual shapefile components to. Optional, you can instead provide the base path astarget.**kwargs – An extra keyword arguments are passed on to the shapefile.Writer instance.
- write_wkt(dataset, path)#
Export the geometry of this dataset as a
MultiPolygonto a Well Known Text file.- Parameters:
dataset (
xarray.Dataset) – The dataset to export as Well Known Text.path (
strorpathlib.Path) – The path where the geometry should be written to.
- write_wkb(dataset, path)#
Export the geometry of this dataset as a
MultiPolygonto a Well Known Binary file.- Parameters:
dataset (
xarray.Dataset) – The dataset to export as Well Known Binary.path (
strorpathlib.Path) – The path where the geometry should be written to.