1GDAL_GRID(1) GDAL GDAL_GRID(1)
2
3
4
6 gdal_grid - Creates regular grid from the scattered data.
7
9 gdal_grid [-ot {Byte/Int16/UInt16/UInt32/Int32/Float32/Float64/
10 CInt16/CInt32/CFloat32/CFloat64}]
11 [-of format] [-co "NAME=VALUE"]
12 [-zfield field_name] [-z_increase increase_value] [-z_multiply multiply_value]
13 [-a_srs srs_def] [-spat xmin ymin xmax ymax]
14 [-clipsrc <xmin ymin xmax ymax>|WKT|datasource|spat_extent]
15 [-clipsrcsql sql_statement] [-clipsrclayer layer]
16 [-clipsrcwhere expression]
17 [-l layername]* [-where expression] [-sql select_statement]
18 [-txe xmin xmax] [-tye ymin ymax] [-outsize xsize ysize]
19 [-a algorithm[:parameter1=value1]*] [-q]
20 <src_datasource> <dst_filename>
21
23 This program creates regular grid (raster) from the scattered data read
24 from the OGR datasource. Input data will be interpolated to fill grid
25 nodes with values, you can choose from various interpolation methods.
26
27 It is possible to set the GDAL_NUM_THREADS configuration option to par‐
28 allelize the processing. The value to specify is the number of worker
29 threads, or ALL_CPUS to use all the cores/CPUs of the computer.
30
31 -ot <type>
32 Force the output image bands to have a specific type. Use type
33 names (i.e. Byte, Int16,...)
34
35 -of <format>
36 Select the output format. Starting with GDAL 2.3, if not speci‐
37 fied, the format is guessed from the extension (previously was
38 GTiff). Use the short format name.
39
40 -txe <xmin> <xmax>
41 Set georeferenced X extents of output file to be created.
42
43 -tye <ymin> <ymax>
44 Set georeferenced Y extents of output file to be created.
45
46 -outsize <xsize ysize>
47 Set the size of the output file in pixels and lines.
48
49 -a_srs <srs_def>
50 Override the projection for the output file. The <i>srs_def>
51 may be any of the usual GDAL/OGR forms, complete WKT, PROJ.4,
52 EPSG:n or a file containing the WKT. No reprojection is done.
53
54 -zfield <field_name>
55 Identifies an attribute field on the features to be used to get
56 a Z value from. This value overrides Z value read from feature
57 geometry record (naturally, if you have a Z value in geometry,
58 otherwise you have no choice and should specify a field name
59 containing Z value).
60
61 -z_increase <increase_value>
62 Addition to the attribute field on the features to be used to
63 get a Z value from. The addition should be the same unit as Z
64 value. The result value will be Z value + Z increase value. The
65 default value is 0.
66
67 -z_multiply <multiply_value>
68 This is multiplication ratio for Z field. This can be used for
69 shift from e.g. foot to meters or from elevation to deep. The
70 result value will be (Z value + Z increase value) * Z multiply
71 value. The default value is 1.
72
73 -a <[algorithm[:parameter1=value1][:parameter2=value2]...]>
74 Set the interpolation algorithm or data metric name and (option‐
75 ally) its parameters. See Interpolation algorithms and Data met‐
76 rics sections for further discussion of available options.
77
78 -spat <xmin> <ymin> <xmax> <ymax>
79 Adds a spatial filter to select only features contained within
80 the bounding box described by (xmin, ymin) - (xmax, ymax).
81
82 -clipsrc [xmin ymin xmax ymax]|WKT|datasource|spat_extent
83 Adds a spatial filter to select only features contained within
84 the specified bounding box (expressed in source SRS), WKT geome‐
85 try (POLYGON or MULTIPOLYGON), from a datasource or to the spa‐
86 tial extent of the -spat option if you use the spat_extent key‐
87 word. When specifying a datasource, you will generally want to
88 use it in combination of the -clipsrclayer, -clipsrcwhere or
89 -clipsrcsql options.
90
91 -clipsrcsql <sql_statement>
92 Select desired geometries using an SQL query instead.
93
94 -clipsrclayer <layername>
95 Select the named layer from the source clip datasource.
96
97 -clipsrcwhere <expression>
98 Restrict desired geometries based on attribute query.
99
100 -l <layername>
101 Indicates the layer(s) from the datasource that will be used for
102 input features. May be specified multiple times, but at least
103 one layer name or a -sql option must be specified.
104
105 -where <expression>
106 An optional SQL WHERE style query expression to be applied to
107 select features to process from the input layer(s).
108
109 -sql <select_statement>
110 An SQL statement to be evaluated against the datasource to pro‐
111 duce a virtual layer of features to be processed.
112
113 -co <NAME=VALUE>
114 Many formats have one or more optional creation options that can
115 be used to control particulars about the file created. For
116 instance, the GeoTIFF driver supports creation options to con‐
117 trol compression, and whether the file should be tiled.
118
119 The creation options available vary by format driver, and some
120 simple formats have no creation options at all. A list of
121 options supported for a format can be listed with the --formats
122 command line option but the documentation for the format is the
123 definitive source of information on driver creation options.
124 See raster_drivers format specific documentation for legal cre‐
125 ation options for each format.
126
127 -q Suppress progress monitor and other non-error output.
128
129 <src_datasource>
130 Any OGR supported readable datasource.
131
132 <dst_filename>
133 The GDAL supported output file.
134
136 There are number of interpolation algorithms to choose from.
137
138 More details about them can also be found in gdal_grid_tut
139
140 invdist
141 Inverse distance to a power. This is default algorithm. It has follow‐
142 ing parameters:
143
144 · power: Weighting power (default 2.0).
145
146 · smoothing: Smoothing parameter (default 0.0).
147
148 · radius1: The first radius (X axis if rotation angle is 0) of search
149 ellipse. Set this parameter to zero to use whole point array.
150 Default is 0.0.
151
152 · radius2: The second radius (Y axis if rotation angle is 0) of search
153 ellipse. Set this parameter to zero to use whole point array.
154 Default is 0.0.
155
156 · angle: Angle of search ellipse rotation in degrees (counter clock‐
157 wise, default 0.0).
158
159 · max_points: Maximum number of data points to use. Do not search for
160 more points than this number. This is only used if search ellipse is
161 set (both radii are non-zero). Zero means that all found points
162 should be used. Default is 0.
163
164 · min_points: Minimum number of data points to use. If less amount of
165 points found the grid node considered empty and will be filled with
166 NODATA marker. This is only used if search ellipse is set (both radii
167 are non-zero). Default is 0.
168
169 · nodata: NODATA marker to fill empty points (default 0.0).
170
171 invdistnn
172 New in version 2.1.
173
174
175 Inverse distance to a power with nearest neighbor searching, ideal when
176 max_points is used. It has following parameters:
177
178 · power: Weighting power (default 2.0).
179
180 · smoothing: Smoothing parameter (default 0.0).
181
182 · radius: The radius of the search circle, which should be non-zero.
183 Default is 1.0.
184
185 · max_points: Maximum number of data points to use. Do not search for
186 more points than this number. Found points will be ranked from near‐
187 est to furthest distance when weighting. Default is 12.
188
189 · min_points: Minimum number of data points to use. If less amount of
190 points found the grid node is considered empty and will be filled
191 with NODATA marker. Default is 0.
192
193 · nodata: NODATA marker to fill empty points (default 0.0).
194
195 average
196 Moving average algorithm. It has following parameters:
197
198 · radius1: The first radius (X axis if rotation angle is 0) of search
199 ellipse. Set this parameter to zero to use whole point array.
200 Default is 0.0.
201
202 · radius2: The second radius (Y axis if rotation angle is 0) of search
203 ellipse. Set this parameter to zero to use whole point array.
204 Default is 0.0.
205
206 · angle: Angle of search ellipse rotation in degrees (counter clock‐
207 wise, default 0.0).
208
209 · min_points: Minimum number of data points to use. If less amount of
210 points found the grid node considered empty and will be filled with
211 NODATA marker. Default is 0.
212
213 · nodata: NODATA marker to fill empty points (default 0.0).
214
215 Note, that it is essential to set search ellipse for moving average
216 method. It is a window that will be averaged when computing grid nodes
217 values.
218
219 nearest
220 Nearest neighbor algorithm. It has following parameters:
221
222 · radius1: The first radius (X axis if rotation angle is 0) of search
223 ellipse. Set this parameter to zero to use whole point array.
224 Default is 0.0.
225
226 · radius2: The second radius (Y axis if rotation angle is 0) of search
227 ellipse. Set this parameter to zero to use whole point array.
228 Default is 0.0.
229
230 · angle: Angle of search ellipse rotation in degrees (counter clock‐
231 wise, default 0.0).
232
233 · nodata: NODATA marker to fill empty points (default 0.0).
234
235 linear
236 New in version 2.1.
237
238
239 Linear interpolation algorithm.
240
241 The Linear method performs linear interpolation by computing a Delaunay
242 triangulation of the point cloud, finding in which triangle of the tri‐
243 angulation the point is, and by doing linear interpolation from its
244 barycentric coordinates within the triangle. If the point is not in
245 any triangle, depending on the radius, the algorithm will use the value
246 of the nearest point or the nodata value.
247
248 It has following parameters:
249
250 · radius: In case the point to be interpolated does not fit into a tri‐
251 angle of the Delaunay triangulation, use that maximum distance to
252 search a nearest neighbour, or use nodata otherwise. If set to -1,
253 the search distance is infinite. If set to 0, nodata value will be
254 always used. Default is -1.
255
256 · nodata: NODATA marker to fill empty points (default 0.0).
257
259 Besides the interpolation functionality ref gdal_grid can be used to
260 compute some data metrics using the specified window and output grid
261 geometry. These metrics are:
262
263 · minimum: Minimum value found in grid node search ellipse.
264
265 · maximum: Maximum value found in grid node search ellipse.
266
267 · range: A difference between the minimum and maximum values found in
268 grid node search ellipse.
269
270 · count: A number of data points found in grid node search ellipse.
271
272 · average_distance: An average distance between the grid node (center
273 of the search ellipse) and all of the data points found in grid node
274 search ellipse.
275
276 · average_distance_pts: An average distance between the data points
277 found in grid node search ellipse. The distance between each pair of
278 points within ellipse is calculated and average of all distances is
279 set as a grid node value.
280
281 All the metrics have the same set of options:
282
283 · radius1: The first radius (X axis if rotation angle is 0) of search
284 ellipse. Set this parameter to zero to use whole point array.
285 Default is 0.0.
286
287 · radius2: The second radius (Y axis if rotation angle is 0) of search
288 ellipse. Set this parameter to zero to use whole point array.
289 Default is 0.0.
290
291 · angle: Angle of search ellipse rotation in degrees (counter clock‐
292 wise, default 0.0).
293
294 · min_points: Minimum number of data points to use. If less amount of
295 points found the grid node considered empty and will be filled with
296 NODATA marker. This is only used if search ellipse is set (both radii
297 are non-zero). Default is 0.
298
299 · nodata: NODATA marker to fill empty points (default 0.0).
300
302 Often you have a text file with a list of comma separated XYZ values to
303 work with (so called CSV file). You can easily use that kind of data
304 source in ref gdal_grid. All you need is create a virtual dataset
305 header (VRT) for you CSV file and use it as input datasource for ref
306 gdal_grid. You can find details on VRT format at vector.vrt description
307 page.
308
309 Here is a small example. Let we have a CSV file called <i>dem.csv> con‐
310 taining
311
312 Easting,Northing,Elevation
313 86943.4,891957,139.13
314 87124.3,892075,135.01
315 86962.4,892321,182.04
316 87077.6,891995,135.01
317 ...
318
319 For above data we will create <i>dem.vrt> header with the following
320 content:
321
322 <OGRVRTDataSource>
323 <OGRVRTLayer name="dem">
324 <SrcDataSource>dem.csv</SrcDataSource>
325 <GeometryType>wkbPoint</GeometryType>
326 <GeometryField encoding="PointFromColumns" x="Easting" y="Northing" z="Elevation"/>
327 </OGRVRTLayer>
328 </OGRVRTDataSource>
329
330 This description specifies so called 2.5D geometry with three coordi‐
331 nates X, Y and Z. Z value will be used for interpolation. Now you can
332 use <i>dem.vrt> with all OGR programs (start with ref ogrinfo to test
333 that everything works fine). The datasource will contain single layer
334 called <i>"dem"> filled with point features constructed from values in
335 CSV file. Using this technique you can handle CSV files with more than
336 three columns, switch columns, etc.
337
338 If your CSV file does not contain column headers then it can be handled
339 in the following way:
340
341 <GeometryField encoding="PointFromColumns" x="field_1" y="field_2" z="field_3"/>
342
343 The vector.csv description page contains details on CSV format sup‐
344 ported by GDAL/OGR.
345
347 This utility is also callable from C with GDALGrid().
348
350 The following would create raster TIFF file from VRT datasource
351 described in Reading comma separated values section using the inverse
352 distance to a power method. Values to interpolate will be read from Z
353 value of geometry record.
354
355 gdal_grid -a invdist:power=2.0:smoothing=1.0 -txe 85000 89000 -tye 894000 890000 -outsize 400 400 -of GTiff -ot Float64 -l dem dem.vrt dem.tiff
356
357 The next command does the same thing as the previous one, but reads
358 values to interpolate from the attribute field specified with
359 <b>-zfield</b> option instead of geometry record. So in this case X and
360 Y coordinates are being taken from geometry and Z is being taken from
361 the <i>"Elevation"> field. The GDAL_NUM_THREADS is also set to paral‐
362 lelize the computation.
363
364 gdal_grid -zfield "Elevation" -a invdist:power=2.0:smoothing=1.0 -txe 85000 89000 -tye 894000 890000 -outsize 400 400 -of GTiff -ot Float64 -l dem dem.vrt dem.tiff --config GDAL_NUM_THREADS ALL_CPUS
365
367 Andrey Kiselev <dron@ak4719.spb.edu>
368
370 1998-2021
371
372
373
374
375 Jan 05, 2021 GDAL_GRID(1)