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] [-tr xres yres] [-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 data type sup‐
33 ported by the driver, which may be one of the following: Byte,
34 UInt16, Int16, UInt32, Int32, Float32, Float64, CInt16, CInt32,
35 CFloat32 or CFloat64.
36
37 -of <format>
38 Select the output format. Starting with GDAL 2.3, if not speci‐
39 fied, the format is guessed from the extension (previously was
40 GTiff). Use the short format name.
41
42 -txe <xmin> <xmax>
43 Set georeferenced X extents of output file to be created.
44
45 -tye <ymin> <ymax>
46 Set georeferenced Y extents of output file to be created.
47
48 -tr <xres> <yres>
49 Set output file resolution (in target georeferenced units).
50 Note that -tr just works in combination with a valid input from
51 -txe and -tye
52
53 New in version 3.2.
54
55
56 -outsize <xsize ysize>
57 Set the size of the output file in pixels and lines. Note that
58 -outsize cannot be used with -tr
59
60 -a_srs <srs_def>
61 Override the projection for the output file. The srs_def may be
62 any of the usual GDAL/OGR forms, complete WKT, PROJ.4, EPSG:n or
63 a file containing the WKT. No reprojection is done.
64
65 -zfield <field_name>
66 Identifies an attribute field on the features to be used to get
67 a Z value from. This value overrides Z value read from feature
68 geometry record (naturally, if you have a Z value in geometry,
69 otherwise you have no choice and should specify a field name
70 containing Z value).
71
72 -z_increase <increase_value>
73 Addition to the attribute field on the features to be used to
74 get a Z value from. The addition should be the same unit as Z
75 value. The result value will be Z value + Z increase value. The
76 default value is 0.
77
78 -z_multiply <multiply_value>
79 This is multiplication ratio for Z field. This can be used for
80 shift from e.g. foot to meters or from elevation to deep. The
81 result value will be (Z value + Z increase value) * Z multiply
82 value. The default value is 1.
83
84 -a <[algorithm[:parameter1=value1][:parameter2=value2]...]>
85 Set the interpolation algorithm or data metric name and (option‐
86 ally) its parameters. See Interpolation algorithms and Data met‐
87 rics sections for further discussion of available options.
88
89 -spat <xmin> <ymin> <xmax> <ymax>
90 Adds a spatial filter to select only features contained within
91 the bounding box described by (xmin, ymin) - (xmax, ymax).
92
93 -clipsrc [xmin ymin xmax ymax]|WKT|datasource|spat_extent
94 Adds a spatial filter to select only features contained within
95 the specified bounding box (expressed in source SRS), WKT geome‐
96 try (POLYGON or MULTIPOLYGON), from a datasource or to the spa‐
97 tial extent of the -spat option if you use the spat_extent key‐
98 word. When specifying a datasource, you will generally want to
99 use it in combination of the -clipsrclayer, -clipsrcwhere or
100 -clipsrcsql options.
101
102 -clipsrcsql <sql_statement>
103 Select desired geometries using an SQL query instead.
104
105 -clipsrclayer <layername>
106 Select the named layer from the source clip datasource.
107
108 -clipsrcwhere <expression>
109 Restrict desired geometries based on attribute query.
110
111 -l <layername>
112 Indicates the layer(s) from the datasource that will be used for
113 input features. May be specified multiple times, but at least
114 one layer name or a -sql option must be specified.
115
116 -where <expression>
117 An optional SQL WHERE style query expression to be applied to
118 select features to process from the input layer(s).
119
120 -sql <select_statement>
121 An SQL statement to be evaluated against the datasource to pro‐
122 duce a virtual layer of features to be processed.
123
124 -co <NAME=VALUE>
125 Many formats have one or more optional creation options that can
126 be used to control particulars about the file created. For in‐
127 stance, the GeoTIFF driver supports creation options to control
128 compression, and whether the file should be tiled.
129
130 The creation options available vary by format driver, and some
131 simple formats have no creation options at all. A list of op‐
132 tions supported for a format can be listed with the --formats
133 command line option but the documentation for the format is the
134 definitive source of information on driver creation options.
135 See Raster drivers format specific documentation for legal cre‐
136 ation options for each format.
137
138 -q Suppress progress monitor and other non-error output.
139
140 <src_datasource>
141 Any OGR supported readable datasource.
142
143 <dst_filename>
144 The GDAL supported output file.
145
147 There are number of interpolation algorithms to choose from.
148
149 More details about them can also be found in GDAL Grid Tutorial
150
151 invdist
152 Inverse distance to a power. This is default algorithm. It has follow‐
153 ing parameters:
154
155 • power: Weighting power (default 2.0).
156
157 • smoothing: Smoothing parameter (default 0.0).
158
159 • radius1: The first radius (X axis if rotation angle is 0) of search
160 ellipse. Set this parameter to zero to use whole point array. De‐
161 fault is 0.0.
162
163 • radius2: The second radius (Y axis if rotation angle is 0) of search
164 ellipse. Set this parameter to zero to use whole point array. De‐
165 fault is 0.0.
166
167 • radius: Set first and second radius (mutually exclusive with radius1
168 and radius2). Default is 0.0. Added in GDAL 3.6
169
170 • angle: Angle of search ellipse rotation in degrees (counter clock‐
171 wise, default 0.0).
172
173 • max_points: Maximum number of data points to use. Do not search for
174 more points than this number. This is only used if search ellipse is
175 set (both radii are non-zero). Zero means that all found points
176 should be used. Default is 0.
177
178 • min_points: Minimum number of data points to use. If less amount of
179 points found the grid node considered empty and will be filled with
180 NODATA marker. This is only used if search ellipse is set (both radii
181 are non-zero). Default is 0.
182
183 • max_points_per_quadrant: Maximum number of data points to use per
184 quadrant. Default is 0. Added in GDAL 3.6. When specified, this ac‐
185 tually uses invdistnn implementation.
186
187 • min_points_per_quadrant: Minimum number of data points to use per
188 quadrant. Default is 0. Added in GDAL 3.6. When specified, this ac‐
189 tually uses invdistnn implementation.
190
191 • nodata: NODATA marker to fill empty points (default 0.0).
192
193 invdistnn
194 New in version 2.1.
195
196
197 Inverse distance to a power with nearest neighbor searching, ideal when
198 max_points is used. It has following parameters:
199
200 • power: Weighting power (default 2.0).
201
202 • smoothing: Smoothing parameter (default 0.0).
203
204 • radius: The radius of the search circle, which should be non-zero.
205 Default is 1.0.
206
207 • max_points: Maximum number of data points to use. Do not search for
208 more points than this number. Found points will be ranked from near‐
209 est to furthest distance when weighting. Default is 12.
210
211 • min_points: Minimum number of data points to use. If less amount of
212 points found the grid node is considered empty and will be filled
213 with NODATA marker. Default is 0.
214
215 • max_points_per_quadrant: Maximum number of data points to use per
216 quadrant. Default is 0. Added in GDAL 3.6. When specified, the al‐
217 gorithm will only take into account up to max_points_per_quadrant
218 points for each of the right-top, left-top, right-bottom and
219 right-top quadrant relative to the point being interpolated.
220
221 • min_points_per_quadrant: Minimum number of data points to use per
222 quadrant. Default is 0. Added in GDAL 3.6. If that number is not
223 reached, the point being interpolated will be set with the NODATA
224 marker. When specified, the algorithm will collect at least
225 min_points_per_quadrant points for each of the right-top, left-top,
226 right-bottom and right-top quadrant relative to the point being in‐
227 terpolated.
228
229 • nodata: NODATA marker to fill empty points (default 0.0).
230
231 When min_points_per_quadrant or max_points_per_quadrant is specified,
232 the search will start with the closest point to the point being inter‐
233 polated from the first quadrant, then the closest point to the point
234 being interpolated from the second quadrant, etc. up to the 4th quad‐
235 rant, and will continue with the next closest point in the first quad‐
236 rant, etc. until max_points and/or max_points_per_quadrant thresholds
237 are reached.
238
239 average
240 Moving average algorithm. It has following parameters:
241
242 • radius1: The first radius (X axis if rotation angle is 0) of search
243 ellipse. Set this parameter to zero to use whole point array. De‐
244 fault is 0.0.
245
246 • radius2: The second radius (Y axis if rotation angle is 0) of search
247 ellipse. Set this parameter to zero to use whole point array. De‐
248 fault is 0.0.
249
250 • radius: Set first and second radius (mutually exclusive with radius1
251 and radius2). Default is 0.0. Added in GDAL 3.6
252
253 • angle: Angle of search ellipse rotation in degrees (counter clock‐
254 wise, default 0.0).
255
256 • max_points: Maximum number of data points to use. Do not search for
257 more points than this number. Found points will be ranked from near‐
258 est to furthest distance when weighting. Default is 0. Added in GDAL
259 3.6 Only taken into account if one or both of min_points_per_quadrant
260 or max_points_per_quadrant is specified
261
262 • min_points: Minimum number of data points to use. If less amount of
263 points found the grid node considered empty and will be filled with
264 NODATA marker. Default is 0.
265
266 • max_points_per_quadrant: Maximum number of data points to use per
267 quadrant. Default is 0. Added in GDAL 3.6. When specified, the al‐
268 gorithm will only take into account up to max_points_per_quadrant
269 points for each of the right-top, left-top, right-bottom and
270 right-top quadrant relative to the point being interpolated.
271
272 • min_points_per_quadrant: Minimum number of data points to use per
273 quadrant. Default is 0. Added in GDAL 3.6. If that number is not
274 reached, the point being interpolated will be set with the NODATA
275 marker. When specified, the algorithm will collect at least
276 min_points_per_quadrant points for each of the right-top, left-top,
277 right-bottom and right-top quadrant relative to the point being in‐
278 terpolated.
279
280 • nodata: NODATA marker to fill empty points (default 0.0).
281
282 Note, that it is essential to set search ellipse for moving average
283 method. It is a window that will be averaged when computing grid nodes
284 values.
285
286 When min_points_per_quadrant or max_points_per_quadrant is specified,
287 the search will start with the closest point to the point being inter‐
288 polated from the first quadrant, then the closest point to the point
289 being interpolated from the second quadrant, etc. up to the 4th quad‐
290 rant, and will continue with the next closest point in the first quad‐
291 rant, etc. until max_points and/or max_points_per_quadrant thresholds
292 are reached.
293
294 nearest
295 Nearest neighbor algorithm. It has following parameters:
296
297 • radius1: The first radius (X axis if rotation angle is 0) of search
298 ellipse. Set this parameter to zero to use whole point array. De‐
299 fault is 0.0.
300
301 • radius2: The second radius (Y axis if rotation angle is 0) of search
302 ellipse. Set this parameter to zero to use whole point array. De‐
303 fault is 0.0.
304
305 • radius: Set first and second radius (mutually exclusive with radius1
306 and radius2). Default is 0.0. Added in GDAL 3.6
307
308 • angle: Angle of search ellipse rotation in degrees (counter clock‐
309 wise, default 0.0).
310
311 • nodata: NODATA marker to fill empty points (default 0.0).
312
313 linear
314 New in version 2.1.
315
316
317 Linear interpolation algorithm.
318
319 The Linear method performs linear interpolation by computing a Delaunay
320 triangulation of the point cloud, finding in which triangle of the tri‐
321 angulation the point is, and by doing linear interpolation from its
322 barycentric coordinates within the triangle. If the point is not in
323 any triangle, depending on the radius, the algorithm will use the value
324 of the nearest point or the nodata value.
325
326 It has following parameters:
327
328 • radius: In case the point to be interpolated does not fit into a tri‐
329 angle of the Delaunay triangulation, use that maximum distance to
330 search a nearest neighbour, or use nodata otherwise. If set to -1,
331 the search distance is infinite. If set to 0, nodata value will be
332 always used. Default is -1.
333
334 • nodata: NODATA marker to fill empty points (default 0.0).
335
337 Besides the interpolation functionality ref gdal_grid can be used to
338 compute some data metrics using the specified window and output grid
339 geometry. These metrics are:
340
341 • minimum: Minimum value found in grid node search ellipse.
342
343 • maximum: Maximum value found in grid node search ellipse.
344
345 • range: A difference between the minimum and maximum values found in
346 grid node search ellipse.
347
348 • count: A number of data points found in grid node search ellipse.
349
350 • average_distance: An average distance between the grid node (center
351 of the search ellipse) and all of the data points found in grid node
352 search ellipse.
353
354 • average_distance_pts: An average distance between the data points
355 found in grid node search ellipse. The distance between each pair of
356 points within ellipse is calculated and average of all distances is
357 set as a grid node value.
358
359 All the metrics have the same set of options:
360
361 • radius1: The first radius (X axis if rotation angle is 0) of search
362 ellipse. Set this parameter to zero to use whole point array. De‐
363 fault is 0.0.
364
365 • radius2: The second radius (Y axis if rotation angle is 0) of search
366 ellipse. Set this parameter to zero to use whole point array. De‐
367 fault is 0.0.
368
369 • radius: Set first and second radius (mutually exclusive with radius1
370 and radius2). Default is 0.0. Added in GDAL 3.6
371
372 • angle: Angle of search ellipse rotation in degrees (counter clock‐
373 wise, default 0.0).
374
375 • min_points: Minimum number of data points to use. If less amount of
376 points found the grid node considered empty and will be filled with
377 NODATA marker. This is only used if search ellipse is set (both radii
378 are non-zero). Default is 0.
379
380 • max_points_per_quadrant: Maximum number of data points to use per
381 quadrant. Default is 0. Added in GDAL 3.6. When specified, the al‐
382 gorithm will only take into account up to max_points_per_quadrant
383 points for each of the right-top, left-top, right-bottom and
384 right-top quadrant relative to the point being interpolated.
385
386 • min_points_per_quadrant: Minimum number of data points to use per
387 quadrant. Default is 0. Added in GDAL 3.6. If that number is not
388 reached, the point being interpolated will be set with the NODATA
389 marker. When specified, the algorithm will collect at least
390 min_points_per_quadrant points for each of the right-top, left-top,
391 right-bottom and right-top quadrant relative to the point being in‐
392 terpolated.
393
394 • nodata: NODATA marker to fill empty points (default 0.0).
395
396 When min_points_per_quadrant or max_points_per_quadrant is specified,
397 the search will start with the closest point to the point being inter‐
398 polated from the first quadrant, then the closest point to the point
399 being interpolated from the second quadrant, etc. up to the 4th quad‐
400 rant, and will continue with the next closest point in the first quad‐
401 rant, etc. until max_points and/or max_points_per_quadrant thresholds
402 are reached.
403
405 Often you have a text file with a list of comma separated XYZ values to
406 work with (so called CSV file). You can easily use that kind of data
407 source in ref gdal_grid. All you need is create a virtual dataset
408 header (VRT) for you CSV file and use it as input datasource for ref
409 gdal_grid. You can find details on VRT format at VRT -- Virtual Format
410 description page.
411
412 Here is a small example. Let we have a CSV file called dem.csv contain‐
413 ing
414
415 Easting,Northing,Elevation
416 86943.4,891957,139.13
417 87124.3,892075,135.01
418 86962.4,892321,182.04
419 87077.6,891995,135.01
420 ...
421
422 For above data we will create dem.vrt header with the following con‐
423 tent:
424
425 <OGRVRTDataSource>
426 <OGRVRTLayer name="dem">
427 <SrcDataSource>dem.csv</SrcDataSource>
428 <GeometryType>wkbPoint</GeometryType>
429 <GeometryField encoding="PointFromColumns" x="Easting" y="Northing" z="Elevation"/>
430 </OGRVRTLayer>
431 </OGRVRTDataSource>
432
433 This description specifies so called 2.5D geometry with three coordi‐
434 nates X, Y and Z. Z value will be used for interpolation. Now you can
435 use dem.vrt with all OGR programs (start with ref ogrinfo to test that
436 everything works fine). The datasource will contain single layer called
437 "dem" filled with point features constructed from values in CSV file.
438 Using this technique you can handle CSV files with more than three col‐
439 umns, switch columns, etc.
440
441 If your CSV file does not contain column headers then it can be handled
442 in the following way:
443
444 <GeometryField encoding="PointFromColumns" x="field_1" y="field_2" z="field_3"/>
445
446 The Comma Separated Value (.csv) description page contains details on
447 CSV format supported by GDAL/OGR.
448
450 This utility is also callable from C with GDALGrid().
451
453 The following would create raster TIFF file from VRT datasource de‐
454 scribed in Reading comma separated values section using the inverse
455 distance to a power method. Values to interpolate will be read from Z
456 value of geometry record.
457
458 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
459
460 The next command does the same thing as the previous one, but reads
461 values to interpolate from the attribute field specified with -zfield
462 option instead of geometry record. So in this case X and Y coordinates
463 are being taken from geometry and Z is being taken from the "Elevation"
464 field. The GDAL_NUM_THREADS is also set to parallelize the computa‐
465 tion.
466
467 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
468
470 Andrey Kiselev <dron@ak4719.spb.edu>
471
473 1998-2023
474
475
476
477
478 Apr 17, 2023 GDAL_GRID(1)