gdal_grid: gdal_grid

Description Usage Arguments Details Value Author(s) References Examples

View source: R/gdal_grid.R

Description

R wrapper for gdal_grid: creates regular grid from the scattered data

Usage

 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
gdal_grid(
  src_datasource,
  dst_filename,
  ot,
  of,
  txe,
  tye,
  outsize,
  a_srs,
  zfield,
  z_increase,
  z_multiply,
  a,
  spat,
  clipsrc,
  clipsrcsql,
  clipsrclayer,
  clipsrcwhere,
  l,
  where,
  sql,
  co,
  q,
  config,
  output_Raster = FALSE,
  ignore.full_scan = TRUE,
  verbose = FALSE
)

Arguments

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)|WKT|datasource|spat_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 non-error 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 brute-force scan if other installs are not found. Default is TRUE.

verbose

Logical. Enable verbose execution? Default is FALSE.

Details

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 R-like 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.

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:

All the metrics have the same set of options:

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).

Value

NULL or if(output_Raster), a RasterBrick.

Author(s)

Jonathan A. Greenberg (gdalUtils@estarcion.net) (wrapper) and Frank Warmerdam (GDAL lead developer).

References

http://www.gdal.org/gdal_grid.html

Examples

 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 pre-check 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))
}

gdalUtils documentation built on Feb. 14, 2020, 1:08 a.m.