geo-registry

Random Points in Polygons

A given number of randomly placed points inside each polygon.

Pitfall. Some engines spread the count over the whole layer rather than placing it in each polygon.
Pitfall. Some return one multipoint per polygon rather than separate points.
About this operation
Also called Create Random Points, random sample, generate points, sample points
Group vector/sampling
Checks geometry.valid
Pitfalls 2 listed above
Columbus tool Not stated
Notes Not stated
Status active
Broader Not stated
Narrower Not stated
Related

Parameters

Name Type Required Default Values Note
count integer yes Not stated Not stated Points per polygon.
seed integer no Not stated Not stated A seed for the random numbers, so a run can be repeated.

Inputs and outputs

Direction Name Type Geometry Note
Input layer vector polygon Not stated
Output output vector point Not stated

In each engine

Engine Tool Parameters Differences
geopandas geopandas.GeoSeries.sample_points
  • count → size
  • seed → rng
  • Returns one MultiPoint per row; method can also use pointpats' cluster processes.
grass v.random
  • count → npoints
  • seed → seed
  • layer → restrict
  • output → output
  • npoints is the total for the region or the restricting areas unless flag a puts that many in each area; this mapping sets a.
Preset: {"flag_a":true}
postgis st_generatepoints
  • count → #2
  • seed → #3
  • layer → #1
  • Returns one MultiPoint per polygon.
qgis native:randompointsinpolygons
  • count → POINTS_NUMBER
  • seed → SEED
  • layer → INPUT
  • output → OUTPUT
  • INCLUDE_POLYGON_ATTRIBUTES (on by default) copies the polygon's attributes, including a GeoPackage's fid, so writing the points to a GeoPackage fails on duplicate fids; turn it off or write another format.
  • MIN_DISTANCE keeps points apart; it may place fewer points when they do not fit.
sf sf::st_sample
  • count → size
  • seed Call set.seed() first; there is no seed argument.
  • layer → x
  • size is the total over all polygons, shared by area, unless given one value per polygon.
terra terra::spatSample
  • count → size
  • seed Call set.seed() first; there is no seed argument.
  • layer → x
  • For polygons, size is the total over the layer; strata can spread it by polygon.