Learn R Programming

gdalBindings (version 0.1.17)

createDataset: Creates a new GDALDataset

Description

Create a new raster file based on specified data. It will output a *.tif file.

Usage

createDataset(
  raster_path,
  nbands,
  datatype,
  projstring,
  lr_lat,
  ul_lat,
  ul_lon,
  lr_lon,
  res,
  nodata,
  co = NULL
)

Value

An object from GDALDataset R6 class.

Arguments

raster_path

Character. The output path for the raster data

nbands

Integer. Number of bands. Default 1.

datatype

GDALDataType. The GDALDataType to use for the raster, use (GDALDataType$) to find the options. Default GDALDataType$GDT_Float64

projstring

The projection string, either proj or WKT is accepted.

lr_lat

Numeric. The lower right latitude.

ul_lat

Numeric. The upper left latitude.

ul_lon

Numeric. The upper left longitude.

lr_lon

Numeric. The lower right longitude.

res

Numeric. The resolution of the output raster

nodata

Numeric. The no data value for the raster. Default 0.

co

CharacterVector. A CharacterVector of creation options for GDAL. Default NULL

Examples

Run this code
# Parameters
raster_path <- file.path(tempdir(), "output.tif")
ul_lat <- -15
ul_lon <- -45
lr_lat <- -25
lr_lon <- -35
res <- c(0.01, -0.01)
datatype <- GDALDataType$GDT_Int32
nbands <- 1
projstring <- "EPSG:4326"
nodata <- -1
co <- c("TILED=YES", "BLOCKXSIZE=512", "BLOCKYSIZE=512", "COMPRESSION=LZW")

# Create a new raster dataset
ds <- createDataset(
  raster_path = raster_path,
  nbands = nbands,
  datatype = datatype,
  projstring = projstring,
  lr_lat = lr_lat,
  ul_lat = ul_lat,
  ul_lon = ul_lon,
  lr_lon = lr_lon,
  res = res,
  nodata = nodata,
  co = co
)

# Get the GDALRasterBand for ds
band <- ds[[1]]

# Set some dummy values
band[[0, 0]] <- 1:(512 * 512)

ds$Close()

Run the code above in your browser using DataLab