1r.random(1) GRASS GIS User's Manual r.random(1)
2
3
4
6 r.random - Creates randomly placed raster cells or vector points
7 Creates a raster map and vector point map containing randomly located
8 cells and points.
9
11 raster, sampling, vector, random, level1
12
14 r.random
15 r.random --help
16 r.random [-snzb] input=name [cover=name] npoints=number[%]
17 [raster=name] [vector=name] [seed=integer] [--overwrite]
18 [--help] [--verbose] [--quiet] [--ui]
19
20 Flags:
21 -s
22 Generate random seed (result is non-deterministic)
23
24 -n
25 Generate points also for NULL cells
26
27 -z
28 Generate vector points as 3D points
29 Input raster values will be used for Z coordinates
30
31 -b
32 Do not build topology
33 Do not build topology for vector points
34
35 --overwrite
36 Allow output files to overwrite existing files
37
38 --help
39 Print usage summary
40
41 --verbose
42 Verbose module output
43
44 --quiet
45 Quiet module output
46
47 --ui
48 Force launching GUI dialog
49
50 Parameters:
51 input=name [required]
52 Name of input raster map
53
54 cover=name
55 Name of cover raster map
56
57 npoints=number[%]Â [required]
58 The number of points (or cells) to generate
59 The number of vector points or raster cells to generate, possibly
60 as a percentage of number of cells
61
62 raster=name
63 Name for output raster map
64
65 vector=name
66 Name for output vector map
67
68 seed=integer
69 Seed for rand() function
70
72 The module r.random creates a raster map with values in random places.
73 Alternatively, it creates random vector points at these places. Number
74 of random cells or points can be a fixed number or a percentage of
75 cells from the input. By default, generated cells or points will be
76 subset of non-NULL cells of the input. Resulting raster map consists
77 of original cell values at the selected random locations and NULL (no
78 data) values elsewhere.
79
80 Placement of cells and points
81 The module allows the user to create a raster map and/or a vector
82 points map containing coordinates of points whose locations have been
83 randomly determined. The module places these randomly generated vector
84 points within the current computational region and raster mask (if
85 any), on non-NULL raster cells in a user-specified raster map. If the
86 user sets the -n flag, points will be randomly generated across all
87 cells (even those with NULL values). Cells in the resulting raster
88 overlap with the cells of the input raster based on the current compu‐
89 tational region. Points in the resulting vector map are placed in cell
90 centers of these cells.
91
92 Number of cells and points
93 The user may specify the quantity of random locations to be generated
94 either as a positive integer (e.g., 10), or as a percentage of the
95 raster map’s cells (e.g., 10%, or 3.05%). The number of cells consid‐
96 ered for the percentage reflects whether or not the -n flag was given.
97 Options are 0-100; fractions of percent may be stated as decimals
98 (e.g., 66.67%, or 0.05%).
99
100 Values
101 The cell values and corresponding category names (if present) associ‐
102 ated with the random point locations in the input map are assigned to
103 the newly generated cells in the raster map. If the -n is specified,
104 then a unique entry is made for the value used where the input was
105 NULL. This value is at least 1 less than the smallest value in the in‐
106 put raster and is given a medium gray color.
107
108 If a cover raster map is specified, values are taken from the cover
109 raster map instead of the input raster map. If a cover raster map is
110 specified and the cover map contains NULL (no data) values, these
111 points are suppressed in the resulting vector or raster map.
112
113 Vector output
114 The vector file created by r.random contains vector points that repre‐
115 sent the center points of the randomly generated cells. A value attri‐
116 bute contains the cell value of the input raster (or the assigned value
117 when -n is used). If a cover map is additionally specified, a second
118 column covervalue is populated with raster values from the cover map.
119
120 If the user sets the -b flag, vector points are written without topol‐
121 ogy to minimize the required resources. This is suitable input to
122 v.surf.rst and other vector modules.
123
125 To decide on the number of points r.random will create, use r.univar,
126 g.region, or r.report. r.univar is the fastest way to obtain number of
127 non-NULL cells and NULL cells in a raster map given the current compu‐
128 tational region and raster mask:
129 r.univar map=inputmap
130 The text output contains total number of null and non-null cells
131 (called cells in the machine-readable shell script style output), total
132 null cells (null_cells), and number of non-null cells (n). Alterna‐
133 tively, you can use the following to examine the computational region
134 and the raster map:
135 g.region -p
136 r.report map=inputmap units=c null="*" nsteps=1
137
138 To create random vector point locations within some, but not all, cate‐
139 gories of a integer input raster map (aka CELL raster map), the user
140 must first create a reclassified raster map of the original raster map
141 (e.g., using the GRASS module r.reclass) that contains only the desired
142 categories, and then use the reclassed raster map as input to r.random.
143
145 Random 2D vector elevation points
146 Random vector elevation points sampled from elevation map in the North
147 Carolina sample dataset region, result stored in 2D vector map:
148 g.region raster=elevation -p
149 r.random elevation vector=elevrand n=100
150 v.db.select elevrand
151 v.univar elevrand col=value type=point
152
153 Random 3D vector elevation points
154 Random vector elevation points sampled from elevation map in the North
155 Carolina sample dataset region with collocated values sampled from lan‐
156 duse map, result stored in 3D vector map:
157 g.region raster=elevation -p
158 r.random -z elevation cover=landclass96 vector=luserand3d n=100
159 # data output (value: elevation, covervalue: landuse class):
160 v.db.select luserand3d
161 cat|value|covervalue
162 1|111.229591|5
163 2|71.093758|1
164 3|122.51075|5
165 4|146.17395|4
166 ...
167
169 • g.region for setting the computational region and examining the
170 total number of cells,
171
172 • r.reclass for working only with subset of values in the raster
173 map,
174
175 • v.random for generating vector points without any involvement
176 of raster data,
177
178 • r.random.cells for generating random cells with with spatial
179 dependence (minimal distance),
180
181 • r.surf.random as an option for generating random cell values,
182
183 • v.surf.rst as an option for creating a surface from sampled
184 points.
185
187 Dr. James Hinthorne, GIS Laboratory, Central Washington University
188
189 Modified for GRASS 5.0 by Eric G. Miller
190
191 Cover map support by Markus Neteler, 2007
192
194 Available at: r.random source code (history)
195
196 Accessed: Saturday Oct 28 18:17:52 2023
197
198 Main index | Raster index | Topics index | Keywords index | Graphical
199 index | Full index
200
201 © 2003-2023 GRASS Development Team, GRASS GIS 8.3.1 Reference Manual
202
203
204
205GRASS 8.3.1 r.random(1)