Man Linux: Main Page and Category List

gdal_grid - gdal_grid creates regular grid from the scattered data

Usage: gdal_grid [--help-general] [--formats] [-ot {Byte/Int16/UInt16/UInt32/Int32/Float32/Float64/ CInt16/CInt32/CFloat32/CFloat64}] [-of format] [-co "NAME=VALUE"] [-zfield field_name] [-a_srs srs_def] [-spat xmin ymin xmax ymax] [-l layername]* [-where expression] [-sql select_statement] [-txe xmin xmax] [-tye ymin ymax] [-outsize xsize ysize] [-a algorithm[:parameter1=value1]*] [-quiet] <src_datasource> <dst_filename>

This program creates regular grid (raster) from the scattered data read from the OGR datasource. Input data will be interpolated to fill grid nodes with values, you can choose from various interpolation methods.-ottype:For the output bands to be of the indicated data type.-offormat:Select the output format. The default is GeoTIFF (GTiff). Use the short format name.-txexminxmax:Set georeferenced X extents of output file to be created.-tyeyminymax:Set georeferenced Y extents of output file to be created.-outsizexsizeysize:Set the size of the output file in pixels and lines.-a_srssrs_def:Override the projection for the output file. Thesrs_defmay be any of the usual GDAL/OGR forms, complete WKT, PROJ.4, EPSG:n or a file containing the WKT.-zfieldfield_name:Identifies an attribute field on the features to be used to get a Z value from. This value overrides Z value read from feature geometry record (naturally, if you have a Z value in geometry, otherwise you have no choice and should specify a field name containing Z value).-a[algorithm[:parameter1=value1][:parameter2=value2]...]:Set the interpolation algorithm or data metric name and (optionally) its parameters. SeeINTERPOLATIONALGORITHMSandDATAMETRICSsections for further discussion of available options.-spatxminyminxmaxymax:Adds a spatial filter to select only features intersecting the bounding box described by (xmin, ymin) - (xmax, ymax).-llayername:Indicates the layer(s) from the datasource that will be used for input features. May be specified multiple times, but at least one layer name or a-sqloption must be specified.-whereexpression:An optional SQL WHERE style query expression to be applied to select features to process from the input layer(s).-sqlselect_statement:An SQL statement to be evaluated against the datasource to produce a virtual layer of features to be processed.-coNAME=VALUE:Passes a creation option to the output format driver. Multiple-cooptions may be listed. See format specific documentation for legal creation options for each format.-quiet:Suppress progress monitor and other non-error output.src_datasource:Any OGR supported readable datasource.dst_filename:The GDAL supported output file.

There are number of interpolation algorithms to choose from.invdistInverse distance to a power. This is default algorithm. It has following parameters:power:Weighting power (default 2.0).smoothing:Smoothing parameter (default 0.0).radius1:The first radius (X axis if rotation angle is 0) of search ellipse. Set this parameter to zero to use whole point array. Default is 0.0.radius2:The second radius (Y axis if rotation angle is 0) of search ellipse. Set this parameter to zero to use whole point array. Default is 0.0.angle:Angle of search ellipse rotation in degrees (counter clockwise, default 0.0).max_points:Maximum number of data points to use. Do not search for more points than this number. This is only used if search ellipse is set (both radiuses are non-zero). Zero means that all found points should be used. Default is 0.min_points:Minimum number of data points to use. If less amount of points found the grid node considered empty and will be filled with NODATA marker. This is only used if search ellipse is set (both radiuses are non-zero). Default is 0.nodata:NODATA marker to fill empty points (default 0.0).averageMoving average algorithm. It has following parameters:radius1:The first radius (X axis if rotation angle is 0) of search ellipse. Set this parameter to zero to use whole point array. Default is 0.0.radius2:The second radius (Y axis if rotation angle is 0) of search ellipse. Set this parameter to zero to use whole point array. Default is 0.0.angle:Angle of search ellipse rotation in degrees (counter clockwise, default 0.0).min_points:Minimum number of data points to use. If less amount of points found the grid node considered empty and will be filled with NODATA marker. Default is 0.nodata:NODATA marker to fill empty points (default 0.0). Note, that it is essential to set search ellipse for moving average method. It is a window that will be averaged when computing grid nodes values.nearestNearest neighbor algorithm. It has following parameters:radius1:The first radius (X axis if rotation angle is 0) of search ellipse. Set this parameter to zero to use whole point array. Default is 0.0.radius2:The second radius (Y axis if rotation angle is 0) of search ellipse. Set this parameter to zero to use whole point array. Default is 0.0.angle:Angle of search ellipse rotation in degrees (counter clockwise, default 0.0).nodata:NODATA marker to fill empty points (default 0.0).

Besides the interpolation functionalitygdal_gridcan be used to compute some data metrics using the specified window and output grid geometry. These metrics are:minimum:Minimum value found in grid node search ellipse.maximum:Maximum value found in grid node search ellipse.range:A difference between the minimum and maximum values found in grid node search ellipse. All the metrics have the same set of options:radius1:The first radius (X axis if rotation angle is 0) of search ellipse. Set this parameter to zero to use whole point array. Default is 0.0.radius2:The second radius (Y axis if rotation angle is 0) of search ellipse. Set this parameter to zero to use whole point array. Default is 0.0.angle:Angle of search ellipse rotation in degrees (counter clockwise, default 0.0).min_points:Minimum number of data points to use. If less amount of points found the grid node considered empty and will be filled with NODATA marker. This is only used if search ellipse is set (both radiuses are non-zero). Default is 0.nodata:NODATA marker to fill empty points (default 0.0).

Often you have a text file with a list of comma separated XYZ values to work with (so called CSV file). You can easily use that kind of data source ingdal_grid. All you need is create a virtual dataset header (VRT) for you CSV file and use it as input datasource forgdal_grid. You can find details on VRT format at Virtual Format description page. Here is a small example. Let we have a CSV file calleddem.csvcontaining Easting,Northing,Elevation 86943.4,891957,139.13 87124.3,892075,135.01 86962.4,892321,182.04 87077.6,891995,135.01 For above data we will createdem.vrtheader with the following content: <OGRVRTDataSource> <OGRVRTLayer name="dem"> <SrcDataSource>dem.csv</SrcDataSource> <GeometryType>wkbPoint</GeometryType> <GeometryField encoding="PointFromColumns" x="Easting" y="Northing" z="Elevation"/> </OGRVRTLayer> </OGRVRTDataSource> This description specifies so called 2.5D geometry with three coordinates X, Y and Z. Z value will be used for interpolation. Now you can usedem.vrtwith all OGR programs (start withogrinfoto test that everything works fine). The datasource will contain single layer calleddemfilled with point features constructed from values in CSV file. Using this technique you can handle CSV files with more than three columns, switch columns, etc. If your CSV file does not contain column headers then it can be handled in the following way: <GeometryField encoding="PointFromColumns" x="field_1" y="field_2" z="field_3"/> Comma Separated Value description page contains details on CSV format supported by GDAL/OGR.

The following would create raster TIFF file from VRT datasource described inREADINGCOMMASEPARATEDVALUESsection using the inverse distance to a power method. Values to interpolate will be read from Z value of geometry record. 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 The next command does the same thing as the previos one, but reads values to interpolate from the attribute field specified with-zfieldoption instead of geometry record. So in this case X and Y coordinates are being taken from geometry and Z is being taken from theElevationfield. 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

Andrey Kiselev <dron@ak4719.spb.edu>