geovalidate.PointSampler

class geovalidate.PointSampler(n_samples=100, quasi_random=None, random_state=None)[source]

Sample points uniformly at random inside a Shapely geometry.

Mimics the sklearn model-selection estimator API: hyperparameters are set in __init__ and sample() acts as the primary callable.

Parameters:
n_samples : int, default 100

Number of points to generate.

random_state : int, RandomState instance, or None, default None

Seed / random state passed to sklearn.utils.check_random_state.

Examples

>>> from shapely.geometry import box
>>> from geovalidate import PointSampler
>>> pts = PointSampler(n_samples=200, random_state=0).sample(box(0, 0, 1, 1))
>>> len(pts)
200
__init__(n_samples=100, quasi_random=None, random_state=None)[source]

Methods

__init__([n_samples, quasi_random, random_state])

get_metadata_routing()

Get metadata routing of this object.

get_params([deep])

Get parameters for this estimator.

sample(geometry[, n_samples])

Sample n_samples points uniformly inside geometry.

set_params(**params)

Set the parameters of this estimator.

get_metadata_routing()[source]

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Returns:

routing – A MetadataRequest encapsulating routing information.

Return type:

MetadataRequest

get_params(deep=True)[source]

Get parameters for this estimator.

Parameters:
deep : bool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:

params – Parameter names mapped to their values.

Return type:

dict

sample(geometry, n_samples=None)[source]

Sample n_samples points uniformly inside geometry.

Parameters:
geometry : shapely.Geometry | geopandas.GeoSeries | geopandas.GeoDataFrame

Region to sample from. A GeoSeries / GeoDataFrame is dissolved into a single union before sampling. CRS is inferred automatically.

n_samples : int, optional

Overrides self.n_samples for this call.

Returns:

Single-column geometry GeoDataFrame of sampled Points.

Return type:

geopandas.GeoDataFrame

set_params(**params)[source]

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects (such as Pipeline). The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:
**params : dict

Estimator parameters.

Returns:

self – Estimator instance.

Return type:

estimator instance