sgsPy
structurally guided sampling
Loading...
Searching...
No Matches

Functions

 sgspy.stratify.poly.poly.poly (SpatialRaster rast, SpatialVector vect, str layer_name, str attribute, list[str|list[str]] features, str filename='', dict driver_options=None)
 This function conducts stratification on a vector dataset by rasterizing a polygon layer, and using its attribute values to determine stratifications.

Detailed Description

Function Documentation

◆ poly()

sgspy.stratify.poly.poly.poly ( SpatialRaster rast,
SpatialVector vect,
str layer_name,
str attribute,
list[str|list[str]] features,
str filename = '',
dict driver_options = None )

This function conducts stratification on a vector dataset by rasterizing a polygon layer, and using its attribute values to determine stratifications.

the layer_name parameter is the layer to be rasterized, and the attribute is the attribute within the layer to check. The features parameter specifies the which feature value corresponds to which stratification.

The features parameter is a list containing strings and lists of strings. The index within this list determines the stratification value. For example:

features = ["low", "medium", "high"]
would result in 3 stratifications (0, 1, 2) where 'low' would correspond to stratification 0, medium to 1, and hight to 2.

features = ["low", ["medium", "high"]]
would result in 2 stratifications (0, 1) where 'low' would correspond to stratification 0, and both medium and high to stratification 1.

Examples

rast = sgspy.SpatialRaster('rast.tif')
vect = sgspy.SpatialVector('inventory_polygons.shp')
srast = sgspy.stratify.poly(rast, vect, attribute='NUTRIENTS', layer_name='inventory_polygons', features=['poor', 'medium', 'rich'])

rast = sgspy.SpatialRaster('rast.tif')
vect = sgspy.SpatialVector('inventory_polygons.shp')
srast = sgspy.stratify.poly(rast, vect, attribute='NUTRIENTS', layer_name='inventory_polygons', 'features=['poor', ['medium', 'rich']], filename='nutrient_stratification.shp')

Parameters

rast : SpatialRaster
raster data structure which will determine height, width, geotransform, and projection

vect : SpatialVector
the vector of polygons to stratify

layer_name : str
the layer in the vector to be stratified

attribute : str
the attribute in the layer to be stratified

features : list[str|list[str]]
the stratification values of each feature value, represented as the index in the list

filename : str
the output filename to write to, if desired

Returns

a SpatialRaster object containing the rasterized polygon.