wradlib.zonalstats.ZonalDataBase#

class wradlib.zonalstats.ZonalDataBase(src, *, trg=None, buf=0.0, crs=None, **kwargs)[source]#

Bases: object

Base class for managing 2-dimensional zonal data.

For target polygons from either source points or source polygons. Provides the basic design for all other classes.

If no source points or polygons can be associated to a target polygon (e.g. no intersection), the created destination layer will be empty.

Data Model is built upon OGR Implementation of ESRI Shapefile

  • one src DataSource (named ‘src’) holding source polygons or points

  • one trg DataSource (named ‘trg’) holding target polygons

  • one dst DataSource (named ‘dst’) holding intersection polygons/points related to target polygons with attached index and weights fields

By using OGR there are no restrictions for the used source grids.

Warning

Writing shapefiles with the wrong locale settings can have impact on the type of the decimal. If problem arise use LC_NUMERIC=C in your environment.

Parameters:
  • src (sequence or str) – sequence of source points (shape Nx2) or polygons (shape NxMx2) or ESRI Shapefile filename containing source points/polygons or DataSource object

  • trg (sequence or str) – sequence of target polygons (shape Nx2, num vertices x 2) or ESRI Shapefile filename containing target polygons or DataSource object

Keyword Arguments:
  • buf (float) – (same unit as coordinates) Points/Polygons will be considered inside the target if they are contained in the buffer.

  • crs (osgeo.osr.SpatialReference) – OGR.SpatialReference will be used for DataSource object. src and trg data have to be in the same crs-format

  • silent (bool) – If True no ProgressBar is shown. Defaults to False.

Examples

See ZonalData.

property count_intersections#

Returns number of intersections

property crs#

Returns SpatialReferenceSystem object

property isecs#

Returns intersections

Returns:

array (numpy.ndarray) – Array of Nx2 point coordinate arrays

get_isec(idx)[source]#

Returns intersections

Parameters:

idx (int) – index of target polygon

Returns:

array (numpy.ndarray) – Array of Nx2 point coordinate arrays

get_source_index(idx)[source]#

Returns source indices referring to target polygon idx

Parameters:

idx (int) – index of target polygon

Returns:

array (numpy.ndarray) – indices

dump_vector(filename, *, driver='ESRI Shapefile', remove=True)[source]#

Output source/target grid points/polygons to ESRI_Shapefile

target layer features are attributed with source index and weight

Parameters:
  • filename (str) – path to shape-filename

  • driver (str) – OGR Vector Driver String, defaults to ‘ESRI Shapefile’

  • remove (bool) – if True, existing file will be removed before creation

load_vector(filename)[source]#

Load source/target grid points/polygons into in-memory Shapefile

Parameters:

filename (str) – path to vector file

dump_vector(filename, *[, driver, remove])

Output source/target grid points/polygons to ESRI_Shapefile

get_isec(idx)

Returns intersections

get_source_index(idx)

Returns source indices referring to target polygon idx

load_vector(filename)

Load source/target grid points/polygons into in-memory Shapefile

count_intersections

Returns number of intersections

crs

Returns SpatialReferenceSystem object

isecs

Returns intersections