Description Usage Arguments Details Value Author(s) References Examples
R wrapper for gdal_grid: creates regular grid from the scattered data
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 
src_datasource 
Character. Any OGR supported readable datasource. 
dst_filename 
Character. The GDAL supported output file. 
ot 
Character. "type". For the output bands to be of the indicated data type. 
of 
Character. "format". Select the output format. The default is GeoTIFF (GTiff). Use the short format name. 
txe 
Numeric. c(xmin,xmax). Set georeferenced X extents of output file to be created. 
tye 
Numeric. c(ymin,ymax). Set georeferenced Y extents of output file to be created. 
outsize 
Numeric. c(xsize,ysize). Set the size of the output file in pixels and lines. 
a_srs 
Character. "srs_def". Override the projection for the output file. The srs_def may be any of the usual GDAL/OGR forms, complete WKT, PROJ.4, EPSG:n or a file containing the WKT. 
zfield 
Character. "field_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). 
z_increase 
Numeric. increase_value. Addition to the attribute field on the features to be used to get a Z value from. The addition should be the same unit as Z value. The result value will be Z value + Z increase value. The default value is 0. 
z_multiply 
Numeric. multiply_value. This is multiplication ratio for Z field. This can be used for shift from e.g. foot to meters or from elevation to deep. The result value will be (Z value + Z increase value) * Z multiply value. The default value is 1. 
a 
Character. [algorithm[:parameter1=value1][:parameter2=value2]...] Set the interpolation algorithm or data metric name and (optionally) its parameters. See INTERPOLATION ALGORITHMS and DATA METRICS sections for further discussion of available options. 
spat 
Numeric. c(xmin,ymin,xmax,ymax). Adds a spatial filter to select only features contained within the bounding box described by (xmin, ymin)  (xmax, ymax). 
clipsrc 
Numeric or Character. c(xmin,ymin,xmax,ymax)WKTdatasourcespat_extent. Adds a spatial filter to select only features contained within the specified bounding box (expressed in source SRS), WKT geometry (POLYGON or MULTIPOLYGON), from a datasource or to the spatial extent of the spat option if you use the spat_extent keyword. When specifying a datasource, you will generally want to use it in combination of the clipsrclayer, clipsrcwhere or clipsrcsql options. 
clipsrcsql 
Character. Select desired geometries using an SQL query instead. 
clipsrclayer 
Character. "layername". Select the named layer from the source clip datasource. 
clipsrcwhere 
Character. "expression". Restrict desired geometries based on attribute query. 
l 
Character. "layername". 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 sql option must be specified. 
where 
Character. "expression". An optional SQL WHERE style query expression to be applied to select features to process from the input layer(s). 
sql 
Character. "select_statement". An SQL statement to be evaluated against the datasource to produce a virtual layer of features to be processed. 
co 
Character. "NAME=VALUE". Passes a creation option to the output format driver. Multiple co options may be listed. See format specific documentation for legal creation options for each format. 
q 
Logical. Suppress progress monitor and other nonerror output. 
config 
Character. Sets runtime configuration options for GDAL. See https://trac.osgeo.org/gdal/wiki/ConfigOptions for more information. 
output_Raster 
Logical. Return output dst_filename as a RasterBrick? 
ignore.full_scan 
Logical. If FALSE, perform a bruteforce scan if other installs are not found. Default is TRUE. 
verbose 
Logical. Enable verbose execution? Default is FALSE. 
This is an R wrapper for the 'gdal_grid' function that is part of the Geospatial Data Abstraction Library (GDAL). It follows the parameter naming conventions of the original function, with some modifications to allow for more Rlike parameters. For all parameters, the user can use a single character string following, precisely, the gdal_contour format (http://www.gdal.org/gdal_grid.html), or, in some cases, can use R vectors to achieve the same end.
INTERPOLATION ALGORITHMS
There are number of interpolation algorithms to choose from.
invdist
Inverse 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 radii are nonzero). 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 radii are nonzero). Default is 0.
nodata: NODATA marker to fill empty points (default 0.0).
invdistnn
(Since GDAL 2.1) Inverse distance to a power with nearest neighbor searching, ideal when max_points is used. It has following parameters:
power: Weighting power (default 2.0).
radius: The radius of the search circle, which should be nonzero. Default is 1.0.
max_points: Maximum number of data points to use. Do not search for more points than this number. Found points will be ranked from nearest to furthest distance when weighting. Default is 12.
min_points: Minimum number of data points to use. If less amount of points found the grid node is considered empty and will be filled with NODATA marker. Default is 0.
nodata: NODATA marker to fill empty points (default 0.0).
average
Moving 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.
nearest
Nearest 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).
linear
(Since GDAL 2.1) Linear interpolation algorithm.
The Linear method performs linear interpolation by compution a Delaunay triangulation of the point cloud, finding in which triangle of the triangulation the point is, and by doing linear interpolation from its barycentric coordinates within the triangle. If the point is not in any triangle, depending on the radius, the algorithm will use the value of the nearest point or the nodata value.
It has following parameters:
radius: In case the point to be interpolated does not fit into a triangle of the Delaunay triangulation, use that maximum distance to search a nearest neighbour, or use nodata otherwise. If set to 1, the search distance is infinite. If set to 0, nodata value will be always used. Default is 1.
nodata: NODATA marker to fill empty points (default 0.0).
DATA METRICS
Besides the interpolation functionality gdal_grid can 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.
count: A number of data points found in grid node search ellipse.
average_distance: An average distance between the grid node (center of the search ellipse) and all of the data points found in grid node search ellipse.
average_distance_pts: An average distance between the data points found in grid node search ellipse. The distance between each pair of points within ellipse is calculated and average of all distances is set as a grid node value.
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 radii are nonzero). Default is 0.
nodata: NODATA marker to fill empty points (default 0.0).
This function assumes the user has a working GDAL on their system. If the "gdalUtils_gdalPath" option has been set (usually by gdal_setInstallation), the GDAL found in that path will be used. If nothing is found, gdal_setInstallation will be executed to attempt to find a working GDAL that has the right drivers as specified with the "of" (output format) parameter.
The user can choose to (optionally) return a RasterBrick of the output file (assuming raster/rgdal supports the particular output format).
NULL or if(output_Raster), a RasterBrick.
Jonathan A. Greenberg (gdalUtils@estarcion.net) (wrapper) and Frank Warmerdam (GDAL lead developer).
http://www.gdal.org/gdal_grid.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44  # We'll precheck to make sure there is a valid GDAL install
# and that raster and rgdal are also installed.
# Note this isn't strictly neccessary, as executing the function will
# force a search for a valid GDAL install.
gdal_setInstallation()
valid_install < !is.null(getOption("gdalUtils_gdalPath"))
if(require(raster) && valid_install)
{
# Create a properly formatted CSV:
temporary_dir < tempdir()
tempfname_base < file.path(temporary_dir,"dem")
tempfname_csv < paste(tempfname_base,".csv",sep="")
pts < data.frame(
Easting=c(86943.4,87124.3,86962.4,87077.6),
Northing=c(891957,892075,892321,891995),
Elevation=c(139.13,135.01,182.04,135.01)
)
write.csv(pts,file=tempfname_csv,row.names=FALSE)
# Now make a matching VRT file
tempfname_vrt < paste(tempfname_base,".vrt",sep="")
vrt_header < c(
'<OGRVRTDataSource>',
'\t<OGRVRTLayer name="dem">',
'\t<SrcDataSource>dem.csv</SrcDataSource>',
'\t<GeometryType>wkbPoint</GeometryType>',
'\t<GeometryField encoding="PointFromColumns" x="Easting" y="Northing" z="Elevation"/>',
'\t</OGRVRTLayer>',
'\t</OGRVRTDataSource>'
)
vrt_filecon < file(tempfname_vrt,"w")
writeLines(vrt_header,con=vrt_filecon)
close(vrt_filecon)
tempfname_tif < paste(tempfname_base,".tiff",sep="")
# Now run gdal_grid:
setMinMax(gdal_grid(src_datasource=tempfname_vrt,
dst_filename=tempfname_tif,a="invdist:power=2.0:smoothing=1.0",
txe=c(85000,89000),tye=c(894000,890000),outsize=c(400,400),
of="GTiff",ot="Float64",l="dem",output_Raster=TRUE))
}

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.