pam.samplers.spatial
GeometryRandomSampler(geo_df_file, geometry_name_column, default_region, seed=None)
#
PARAMETER | DESCRIPTION |
---|---|
geo_df_file
|
TYPE:
|
geometry_name_column
|
TYPE:
|
default_region
|
TYPE:
|
seed
|
If given, seed number for reproducible results. Defaults to None. |
Source code in src/pam/samplers/spatial.py
default_geom = self.geo_df.geometry.loc[default_id]
instance-attribute
#
default_region = default_region
instance-attribute
#
geo_df = gp.read_file(geo_df_file)
instance-attribute
#
geo_df_loc_lookup = {value: keyfor (key, value) in self.geo_df[geometry_name_column].to_dict().items()}
instance-attribute
#
geometry_name_column = geometry_name_column
instance-attribute
#
seed = seed
instance-attribute
#
sample_point(geo_region, patience=1000)
#
Randomly sample point within geodata loaded on class initialisation.
Note that it uses random sampling within the shape's bounding box then checks if point is within given geometry.
PARAMETER | DESCRIPTION |
---|---|
geo_region
|
TYPE:
|
patience
|
Defaults to 1000.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
RuntimeWarning
|
If the method cannot return a valid point within 50 attempts then a RunTimeWarning is raised. |
RETURNS | DESCRIPTION |
---|---|
Point
|
Sampled geometry.
TYPE:
|
Source code in src/pam/samplers/spatial.py
RandomPointSampler(geoms, patience=100, fail=True, seed=None)
#
Returns randomly placed point within given geometries, as defined by geoms.
Note that it uses random sampling within the shape's bounding box then checks if point is within given geometry. If the method cannot return a valid point within 'patience' attempts then either a RunTimeWarning is raised or returns None.
PARAMETER | DESCRIPTION |
---|---|
geoms
|
TYPE:
|
patience
|
number of tries to sample point. Defaults to 100.
TYPE:
|
fail
|
If True, raise error rather than return None. Defaults to True.
TYPE:
|
seed
|
If given, seed number for reproducible results. Defaults to None. |
RAISES | DESCRIPTION |
---|---|
UserWarning
|
|
Source code in src/pam/samplers/spatial.py
fail = fail
instance-attribute
#
geoms = geoms
instance-attribute
#
index = list(geoms.index)
instance-attribute
#
logger = logging.getLogger(__name__)
instance-attribute
#
patience = patience
instance-attribute
#
seed = seed
instance-attribute
#
sample(idx, activity)
#
PARAMETER | DESCRIPTION |
---|---|
idx
|
index of initialised geometry dataset. |
activity
|
Unused. Kept for consistency across samplers.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
IndexError
|
|
RETURNS | DESCRIPTION |
---|---|
Optional[Point]
|
Optional[Point]: None if |
Source code in src/pam/samplers/spatial.py
sample_point_from_linestring(geom)
#
sample_point_from_multilinestring(geom)
#
sample_point_from_multipoint(geom)
#
sample_point_from_multipolygon(geom)
#
sample_point_from_point(geom)
#
sample_point_from_polygon(geom)
#
Return random coordinates within polygon, note that will return float coordinates.