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

Functions

 sgspy.sample.srs.srs.srs (SpatialRaster rast, int num_samples, [int|float] mindist=0, Optional[SpatialVector] existing=None, Optional[SpatialVector] access=None, Optional[str] layer_name=None, Optional[int|float] buff_inner=None, Optional[int|float] buff_outer=None, bool plot=False, str filename='')
 This function conducts simple random sampling on the raster given.

Detailed Description

Function Documentation

◆ srs()

sgspy.sample.srs.srs.srs ( SpatialRaster rast,
int num_samples,
[int | float] mindist = 0,
Optional[SpatialVector] existing = None,
Optional[SpatialVector] access = None,
Optional[str] layer_name = None,
Optional[int | float] buff_inner = None,
Optional[int | float] buff_outer = None,
bool plot = False,
str filename = '' )

This function conducts simple random sampling on the raster given.

Sample points are randomly selected from data pixels (can't be nodata). All sample points are at least mindist distance away from eachother. If unable to get the full number of sample points, a message is printed.

An access vector of LineString or MultiLineString type can be provided. buff_outer specifies the buffer distance around the geometry which is allowed to be included in the sampling, buff_inner specifies the buffer distance around the geometry which is not allowed to be included in the sampling. buff_outer must be larger than buff_inner. For a multi layer vector, layer_name must be specified.

A vector containing existing sample points can be provided. If this is the case then all of the points in the existing sample are automatically added and random samples are chosen as required until num_samples number of samples are chosen.

Examples

rast = sgspy.SpatialRaster("raster.tif")
samples = sgspy.sample.srs(rast, num_samples=250)

rast = sgspy.SpatialRaster("raster.tif")
samples = sgspy.sample.srs(rast, num_samples=250, mindist=100, plot=True, filename="srs_samples.shp")
rast = sgspy.SpatialRaster("raster.tif")
access = sgspy.SpatialVector("access_network.shp")
samples = sgspy.sample.srs(rast, num_samples=200, mindist=100, access=access, buff_outer=300)

rast = sgspy.SpatialRaster("raster.tif")
access = sgspy.SpatialVector("access_network.shp")
samples = sgspy.sample.srs(rast, num_samples=200, access=access, buff_inner=50, buff_outer=300)

rast = sgspy.SpatialRaster("raster.tif")
existing = sgspy.SpatialVector("existing_samples.shp")
samples = sgspy.sample.srs(rast, num_samples=200, existing=existing)

Parameters

rast : SpatialRaster
raster data structure containing the raster to sample

num_samples : int
the target number of samples

mindist : float
the minimum distance each sample point must be from each other

existing : SpatialVector
a vector specifying existing sample points

access : SpatialVector
a vector specifying access network

layer_name : str
the layer within access that is to be used for sampling

buff_inner : int | float
buffer boundary specifying distance from access which CANNOT be sampled

buff_outer : int | float
buffer boundary specifying distance from access which CAN be sampled

plot : bool
whether to plot the samples or not

filename : str
the filename to write to, or '' if file should not be written

Returns

a SpatialVector object containing point geometries of sample locations