GIS methods#

Raster methods#

High level methods#

raster.full(coords, *[, nodata, dtype, ...])

Return a full DataArray based on a geospatial coords dictionary.

raster.full_like(other, *[, nodata, lazy])

Return a full object with the same grid and geospatial attributes as other.

raster.full_from_transform(transform, shape, *)

Return a full DataArray based on a geospatial transform and shape.

raster_merge.merge(data_arrays[, dst_crs, ...])

Merge multiple tiles to a single DataArray.

DataArray.raster.from_numpy(data, transform)

Transform a 2D/3D numpy array into a DataArray with geospatial attributes.

Dataset.raster.from_numpy(data_vars, transform)

Transform multiple numpy arrays to a Dataset object.

Attributes#

DataArray.raster.attrs

Return dictionary of spatial attributes.

DataArray.raster.crs

Return horizontal Coordinate Reference System.

DataArray.raster.bounds

Return the bounds (xmin, ymin, xmax, ymax) of the object.

DataArray.raster.transform

Return the affine transform of the object.

DataArray.raster.res

Return resolution (x, y) tuple.

DataArray.raster.rotation

Return rotation of grid (degrees).

DataArray.raster.origin

Return origin of grid (x0, y0) tuple.

DataArray.raster.nodata

Nodata value of the DataArray.

DataArray.raster.dims

Return tuple of geospatial dimensions names.

DataArray.raster.coords

Return dict of geospatial dimensions coordinates.

DataArray.raster.dim0

Return the non geospatial dimension name.

DataArray.raster.y_dim

Return the y dimension name.

DataArray.raster.x_dim

Return the x dimension name.

DataArray.raster.xcoords

Return the x coordinates.

DataArray.raster.ycoords

Return the y coordinates.

DataArray.raster.shape

Return shape of geospatial dimension (height, width).

DataArray.raster.size

Return size of geospatial grid.

DataArray.raster.width

Return the width of the object (x dimension size).

DataArray.raster.height

Return the height of the object (y dimension size).

DataArray.raster.internal_bounds

Return the internal bounds (left, bottom, right, top) the object.

DataArray.raster.box

Return GeoDataFrame() of bounding box.

General methods#

DataArray.raster.set_crs([input_crs, write_crs])

Set the Coordinate Reference System.

DataArray.raster.set_spatial_dims([x_dim, y_dim])

Set the geospatial dimensions of the object.

DataArray.raster.reset_spatial_dims_attrs([...])

Reset spatial dimension names and attributes.

DataArray.raster.identical_grid(other)

Return True if other has an same grid as object (crs, transform, shape).

DataArray.raster.aligned_grid(other)

Check if other grid aligns with object grid (crs, resolution, origin).

DataArray.raster.gdal_compliant([...])

Update attributes to get GDAL compliant NetCDF files.

DataArray.raster.idx_to_xy(idx[, mask, ...])

Return x,y coordinates at linear index.

DataArray.raster.xy_to_idx(xs, ys[, mask, ...])

Return linear index of x, y coordinates.

DataArray.raster.rowcol(xs, ys[, mask, ...])

Return row, col indices of x, y coordinates.

DataArray.raster.xy(r, c[, mask, ...])

Return x,y coordinates at cell center of row, col indices.

DataArray.raster.flipud()

Return raster flipped along y dimension.

DataArray.raster.area_grid([dtype])

Return the grid cell area [m2].

DataArray.raster.density_grid()

Return the density in [unit/m2] of raster(s).

DataArray.raster.reclassify(reclass_table[, ...])

Reclass columns in df from raster map (DataArray).

Nodata handling and interpolation#

DataArray.raster.set_nodata([nodata])

Set the nodata value as CF compliant attribute of the DataArray.

DataArray.raster.mask_nodata([fill_value])

Mask nodata values with fill_value (default np.nan).

DataArray.raster.interpolate_na([method, ...])

Interpolate missing data.

Clip#

DataArray.raster.clip(xslice, yslice)

Clip object based on slices.

DataArray.raster.clip_bbox(bbox[, align, ...])

Clip object based on a bounding box.

DataArray.raster.clip_mask(da_mask[, mask])

Clip object to region with mask values greater than zero.

DataArray.raster.clip_geom(geom[, align, ...])

Clip object to bounding box of the geometry.

Reproject#

DataArray.raster.reproject([dst_crs, ...])

Reproject a DataArray with geospatial coordinates.

DataArray.raster.reindex2d(index[, dst_nodata])

Return reprojected DataArray object based on simple reindexing.

DataArray.raster.reproject_like(other[, method])

Reproject a object to match the grid of other.

DataArray.raster.transform_bounds(dst_crs[, ...])

Transform bounds from object to destination CRS.

DataArray.raster.nearest_index([dst_crs, ...])

Prepare nearest index mapping for reprojection of a gridded timeseries file.

Transform#

DataArray.raster.rasterize(gdf[, col_name, ...])

Return an object with input geometry values burned in.

DataArray.raster.rasterize_geometry(gdf[, ...])

Return an object with the fraction of the grid cells covered by geometry.

DataArray.raster.geometry_mask(gdf[, ...])

Return a grid with True values where shapes overlap pixels.

DataArray.raster.vectorize([connectivity])

Return geometry of grouped pixels with the same value in a DataArray object.

DataArray.raster.vector_grid([geom_type])

Return a vector representation of the grid.

Sampling and zonal stats#

DataArray.raster.sample(gdf[, wdw])

Sample from map at point locations with optional window around the points.

DataArray.raster.zonal_stats(gdf, stats[, ...])

Calculate zonal statistics of raster samples aggregated for geometries.

Writing methods#

DataArray.raster.to_xyz_tiles(root, ...[, ...])

Export rasterdataset to tiles in a xyz structure.

DataArray.raster.to_slippy_tiles(root[, ...])

Produce tiles in /zoom/x/y.<ext> structure (EPSG:3857).

DataArray.raster.to_raster(raster_path[, ...])

Write DataArray object to a gdal-writable raster file.

Dataset.raster.to_mapstack(root[, driver, ...])

Write the Dataset object to one gdal-writable raster files per variable.

GeoDataset methods#

High level methods#

DataArray.vector.from_gdf(gdf, data[, ...])

Parse GeoDataFrame object with point geometries to DataArray.

DataArray.vector.to_gdf([reducer])

Return geopandas GeoDataFrame with Point geometry.

DataArray.vector.from_netcdf(path[, ...])

Read netcdf file or convert xr.DataArray as GeoDataArray.

DataArray.vector.to_netcdf(path[, ...])

Export geodataset vectordata to an ogr compliant netCDF4 file.

Dataset.vector.from_gdf(gdf[, data_vars, ...])

Create Dataset with geospatial coordinates.

Dataset.vector.to_gdf([reducer])

Return geopandas GeoDataFrame with Point geometry.

Dataset.vector.from_netcdf(path[, ...])

Create GeoDataset from ogr compliant netCDF4 file or xr.Dataset.

Dataset.vector.to_netcdf(path[, ...])

Export geodataset vectordata to an ogr compliant netCDF4 file.

Attributes#

DataArray.vector.attrs

Return dictionary of spatial attributes.

DataArray.vector.crs

Return horizontal Coordinate Reference System.

DataArray.vector.index_dim

Index dimension name.

DataArray.vector.time_dim

Time dimension name.

DataArray.vector.x_name

Name of x coordinate; only for point geometries in xy format.

DataArray.vector.y_name

Name of y coordinate; only for point geometries in xy format.

DataArray.vector.geom_name

Name of geometry coordinate; only for 'wkt' and 'geom' formats.

DataArray.vector.geom_type

Return geometry type.

DataArray.vector.geom_format

Name of geometry coordinate; only for 'wkt' and 'geom' formats.

DataArray.vector.index

Return the index values.

DataArray.vector.bounds

Return the bounds (xmin, ymin, xmax, ymax) of the object.

DataArray.vector.size

Return the length of the index array.

DataArray.vector.sindex

Return the spatial index of the geometry.

DataArray.vector.geometry

Return the geometry of the dataset or array as GeoSeries.

Dataset.vector.attrs

Return dictionary of spatial attributes.

Dataset.vector.crs

Return horizontal Coordinate Reference System.

Dataset.vector.index_dim

Index dimension name.

Dataset.vector.time_dim

Time dimension name.

Dataset.vector.x_name

Name of x coordinate; only for point geometries in xy format.

Dataset.vector.y_name

Name of y coordinate; only for point geometries in xy format.

Dataset.vector.geom_name

Name of geometry coordinate; only for 'wkt' and 'geom' formats.

Dataset.vector.geom_type

Return geometry type.

Dataset.vector.geom_format

Name of geometry coordinate; only for 'wkt' and 'geom' formats.

Dataset.vector.index

Return the index values.

Dataset.vector.bounds

Return the bounds (xmin, ymin, xmax, ymax) of the object.

Dataset.vector.size

Return the length of the index array.

Dataset.vector.sindex

Return the spatial index of the geometry.

Dataset.vector.geometry

Return the geometry of the dataset or array as GeoSeries.

Conversion#

DataArray.vector.ogr_compliant([reducer])

Create a Dataset/Array which is understood by OGR.

DataArray.vector.update_geometry([geometry, ...])

Update the geometry in the Dataset/Array with a new geometry.

DataArray.vector.to_geom([geom_name])

Convert Dataset/ DataArray with xy or wkt geometries to shapely Geometries.

DataArray.vector.to_xy([x_name, y_name])

Convert Dataset/ DataArray with Point geometries to x,y structure.

DataArray.vector.to_wkt([ogr_compliant, reducer])

Convert geometries in Dataset/DataArray to wkt strings.

Dataset.vector.ogr_compliant([reducer])

Create a Dataset/Array which is understood by OGR.

Dataset.vector.update_geometry([geometry, ...])

Update the geometry in the Dataset/Array with a new geometry.

Dataset.vector.to_geom([geom_name])

Convert Dataset/ DataArray with xy or wkt geometries to shapely Geometries.

Dataset.vector.to_xy([x_name, y_name])

Convert Dataset/ DataArray with Point geometries to x,y structure.

Dataset.vector.to_wkt([ogr_compliant, reducer])

Convert geometries in Dataset/DataArray to wkt strings.

General methods#

DataArray.vector.set_crs([input_crs, write_crs])

Set the Coordinate Reference System.

DataArray.vector.set_spatial_dims([...])

Set the spatial and index dimensions of the object.

Dataset.vector.set_crs([input_crs, write_crs])

Set the Coordinate Reference System.

Dataset.vector.set_spatial_dims([geom_name, ...])

Set the spatial and index dimensions of the object.

Clip#

DataArray.vector.clip_bbox(bbox[, crs, buffer])

Select point locations to bounding box.

DataArray.vector.clip_geom(geom[, predicate])

Select all geometries that intersect with the input geometry.

Dataset.vector.clip_bbox(bbox[, crs, buffer])

Select point locations to bounding box.

Dataset.vector.clip_geom(geom[, predicate])

Select all geometries that intersect with the input geometry.

Reproject#

DataArray.vector.to_crs(dst_crs)

Transform spatial coordinates to a new coordinate reference system.

Dataset.vector.to_crs(dst_crs)

Transform spatial coordinates to a new coordinate reference system.

Flow direction methods#

These methods are based on the pyflwdir library. For more flow direction based methods visit the pyflwdir docs.

flw.flwdir_from_da(da, *[, ftype, ...])

Parse dataarray to flow direction raster object.

flw.d8_from_dem(da_elv, *[, max_depth, ...])

Derive D8 flow directions grid from an elevation grid.

flw.reproject_hydrography_like(ds_hydro, ...)

Reproject flow direction and upstream area data to the da_elv crs and grid.

flw.upscale_flwdir(ds, *, flwdir, scale_ratio)

Upscale flow direction network to lower resolution.

flw.stream_map(ds, *[, stream])

Return a stream mask DataArray.

flw.basin_map(ds, flwdir, *[, xy, idxs, ...])

Return a (sub)basin map, with unique non-zero IDs for each subbasin.

flw.gauge_map(ds, *[, idxs, xy, ids, ...])

Return map with unique gauge IDs.

flw.outlet_map(da_flw, *[, ftype])

Return a mask of basin outlets/pits from a flow direction raster.

flw.clip_basins(ds, flwdir, *, xy[, flwdir_name])

Clip a dataset to a subbasin.

flw.dem_adjust(da_elevtn, da_flwdir, *[, ...])

Return hydrologically conditioned elevation.