Skip to main content
Spatially stratified sampling partitions the data into a grid and randomly samples each partition independently.

spatially_stratified_sample

Spatially stratified sampling of a DataFrame containing spatial data. Each dimension will be rounded to the nearest integer.
def spatially_stratified_sample(dataframe: DataFrame, fraction: float, partition_count: int, geometry: Optional[str], seed: int)

Parameters

dataframe
DataFrame
required
DataFrame containing spatial data to be sampled. Must contain a geometry column.
fraction
float
required
Sampling rate between 0 and 1
partition_count
int
required
Number of partitions to divide the data into. If not a perfect square, the number of partitions
geometry
Optional[str]
Column containing the geometry data. Default is “geometry”
seed
int
required
Seed for sampling the data

Returns

The input DataFrame sampled down to the specified rate.

Usage Examples

from spatially_stratified_sampling import *

# Example usage of spatially_stratified_sample
result = spatially_stratified_sample(dataframe=example_value, fraction=example_value, partition_count=example_value)