1v.random(1)                 GRASS GIS User's Manual                v.random(1)
2
3
4

NAME

6       v.random  - Generates random 2D/3D vector points.
7

KEYWORDS

9       vector,  sampling, statistics, random, point pattern, stratified random
10       sampling, level1
11

SYNOPSIS

13       v.random
14       v.random --help
15       v.random   [-zab]    output=name    npoints=integer     [restrict=name]
16       [layer=string]      [cats=range]     [where=sql_query]     [zmin=float]
17       [zmax=float]    [seed=integer]    [column=name]    [column_type=string]
18       [--overwrite]  [--help]  [--verbose]  [--quiet]  [--ui]
19
20   Flags:
21       -z
22           Create 3D output
23
24       -a
25           Generate  n  points for each individual area (requires restrict pa‐
26           rameter)
27
28       -b
29           Do not build topology
30           Advantageous when handling a large number of points
31
32       --overwrite
33           Allow output files to overwrite existing files
34
35       --help
36           Print usage summary
37
38       --verbose
39           Verbose module output
40
41       --quiet
42           Quiet module output
43
44       --ui
45           Force launching GUI dialog
46
47   Parameters:
48       output=name [required]
49           Name for output vector map
50
51       npoints=integer [required]
52           Number of points to be created
53
54       restrict=name
55           Name of input vector map
56           Restrict points to areas in input vector
57
58       layer=string
59           Layer number or name (’-1’ for all layers)
60           A single vector map can be connected to multiple  database  tables.
61           This  number  determines  which table to use. When used with direct
62           OGR access this is the layer name.
63           Default: -1
64
65       cats=range
66           Category values
67           Example: 1,3,7-9,13
68
69       where=sql_query
70           WHERE conditions of SQL statement without ’where’ keyword
71           Example: income < 1000 and population >= 10000
72
73       zmin=float
74           Minimum z height (needs -z flag or column name)
75           Default: 0.0
76
77       zmax=float
78           Maximum z height (needs -z flag or column name)
79           Default: 0.0
80
81       seed=integer
82           The seed to initialize the random generator. If not set the process
83           ID is used
84
85       column=name
86           Name of column for z values
87           Writes z values to column
88
89       column_type=string
90           Type of column for z values
91           Options: integer, double precision
92           Default: double precision
93

DESCRIPTION

95       v.random randomly generates vector points within the current region us‐
96       ing the selected random number generator.
97
98       v.random can generate also 3D vector points or write  random  value  to
99       the  attribute  table.  Point  height range or attribute value range is
100       controlled by specifying zmin and zmax options.  Both z values are  in‐
101       cluded  in  range (zmin <= z <= zmax). Generated random attribute value
102       type can be controlled by column_type. Use integer column type for  in‐
103       tegers  and double precision for floating point numbers. Integer values
104       are calculated by rounding random floating point number.
105
106       To produce repeatable results a random seed can be set using the option
107       seed.
108
109   Restriction to vector areas
110       If an restrict vector map with areas is specified, the location of ran‐
111       dom points is restricted to the selected areas.  By  default,  the  re‐
112       quested number of points are distributed across all areas.
113
114       If  the  -a  flag is given, the requested number of points is generated
115       for each individual area. For example, if 20 points should be generated
116       and  the input map has 100 individual areas, 2000 points will be gener‐
117       ated in total.
118
119       Attributes attached to restrict vector map are also transferred if  the
120       layer parameter is defined > 0, see example below.
121

NOTES

123       Importantly,  attributes  will  only be transferred if layer > 0 (e.g.,
124       layer=1).
125

EXAMPLES

127       All examples are based on the North Carolina sample dataset.
128
129   Generating random points in 2D
130       Generate 20 random points with binary attributes (only 0 or 1):
131       v.random output=binary_random npoints=20 zmin=0 zmax=1 column=’binary’
132       v.db.select binary_random
133       cat|binary
134       1|0.63495
135       2|0.233421
136       3|0.489302
137       4|0.748264
138       5|0.505556
139       6|0.32975
140       [...]
141       v.univar -d binary_random
142       Calculating geometric distances between 20 primitives...
143       [...]
144       minimum: 148.515
145       maximum: 16572.8
146       [...]
147
148   Generating random points in 2D with binary attributes
149       Generate 20 random points with binary attributes (only 0 or 1):
150       v.random output=binary_random npoints=20 zmin=0 zmax=1 column=’binary’ column_type=integer
151       v.db.select binary_random
152       cat|binary
153       1|0
154       2|0
155       3|0
156       4|0
157       5|1
158       6|0
159       [...]
160
161   Generating random points in 3D
162       Generate 20 random 3D points using a specific random seed:
163       v.random seed=52 output=height_random npoints=40 zmin=110 zmax=170 -z
164       v.univar -d height_random
165       Calculating geometric distances between 40 primitives...
166       [...]
167       minimum: 334.889
168       maximum: 18351.9
169       range: 18017
170       sum: 5.38425e+06
171       mean: 7266.2
172       mean of absolute values: 7266.2
173       population standard deviation: 3563.95
174       [...]
175       skewness: 0.34703
176
177       Random points with different X, Y, and Z coordinates
178
179   Generating random points in selected areas
180       Generate 3 random points only in selected areas ("RALEIGH" related  ZIP
181       code areas):
182       v.random restrict=zipcodes_wake output=zipcodes_local_random_n3 npoints=3 where="ZIPNAME = ’RALEIGH’" -a
183       # visualization
184       d.mon wx0
185       d.vect zipcodes_wake
186       d.vect zipcodes_wake fcolor=yellow where="ZIPNAME = ’RALEIGH’"
187       d.vect zipcodes_local_random_n3 color=red icon=basic/circle
188       Fixed number of random points generated in selected areas
189
190   Generating random adjacent areas
191       To generate random adjacent areas, first the centroids are generated as
192       points, then a triangulation is run (North Carolina sample dataset:
193       g.region vector=nc_state
194       v.random output=randpoints6k npoints=6000
195       v.voronoi input=randpoints6k output=randareas6k
196       v.info -t randareas6k
197       v.category randareas6k option=print
198       # plot vector areas
199       d.mon wx0
200       d.vect randareas6k -c
201
202       Random adjacent areas from random points (here: used as centroids)
203
204       To eventually obtain isolated areas, selected areas  can  be  extracted
205       with v.extract.
206
207       These vector areas can also be rasterized:
208       # rasterize areas
209       # note: rastermaps must result in at least 6k pixel in this example
210       g.region vector=nc_state res=500 -p -a
211       v.to.rast randareas6k out=randareas6k use=cat
212       r.colors randareas6k color=random
213       d.rast randareas6k
214
215   Random sampling from raster map
216       Generate 20 random samples from a raster map:
217       g.region -p raster=elevation
218       v.random output=random_samples npoints=20
219       v.db.addtable map=random_samples columns=’cat INTEGER, sample DOUBLE PRECISION’
220       v.what.rast map=random_samples raster=elevation column=sample
221       v.db.select random_samples
222       cat|sample
223       1|103.9935
224       2|129.1266
225       3|96.01388
226       [...]
227
228   Random sampling from vector map
229       Generate  20 random points and sample attribute data from geology (vec‐
230       tor) map:
231       g.region -p vector=geology
232       v.random output=random_samples npoints=20
233       v.db.addtable map=random_samples columns=’cat integer, geology varchar(100)’
234       v.what.vect map=random_samples column=geology query_map=geology query_layer=1 query_column=GEO_NAME
235       v.db.select random_samples
236       cat|geology
237       1|PzZm
238       2|
239       3|Zatm
240       [...]
241
242   Stratified random sampling: Random sampling from vector map by attribute
243       Generate 20 random points restricted to forested areas:
244       g.region -p raster=landclass96
245       r.to.vect -v input=landclass96 output=landclass96 type=area
246       v.random restrict=landclass96 output=random_samples npoints=20 where="label = ’forest’" layer=1
247       v.db.select map=random_samples
248       cat|landclass96_cat|landclass96_label
249       1|5|forest
250       2|5|forest
251       3|5|forest
252       ...
253
254       Random points only sampled in forested areas  (stratified  random  sam‐
255       pling)
256
257   Stratified  random  sampling:  Random sampling from vector map with spatial
258       constraints
259       Generating n points for each individual area: in this example two  ran‐
260       dom points in each water body:
261       g.region -p raster=landclass96
262       r.to.vect -v input=landclass96 output=landclass96 type=area
263       v.random restrict=landclass96 output=random_samples npoints=2 where="label = ’water’" layer=1 -a
264
265       Two  random  points  sampled  in each individual water body (stratified
266       random sampling)
267

SEE ALSO

269        g.region,  r.random,  v.db.addtable,  v.perturb,  v.sample,  v.univar,
270       v.what.rast, v.what.vect
271
272       SQL support in GRASS GIS
273

AUTHOR

275       James Darrell McCauley <darrell@mccauley-usa.com>,
276       when he was at: Agricultural Engineering Purdue University
277

SOURCE CODE

279       Available at: v.random source code (history)
280
281       Accessed: Saturday Jan 21 20:40:13 2023
282
283       Main  index  | Vector index | Topics index | Keywords index | Graphical
284       index | Full index
285
286       © 2003-2023 GRASS Development Team, GRASS GIS 8.2.1 Reference Manual
287
288
289
290GRASS 8.2.1                                                        v.random(1)
Impressum