ceateRaster: Create an empty Raster

Description Usage Arguments Author(s) Examples

Description

This function would be useful specifically when you deal with big raster data. You can create an empty raster file (single or multi-layer) then you can write the raster values partially directly to the file using writeInRaster function. Given then the memory mapped to the file, the procedure or reading and writing from/to the file is efficient and quick.

In multi-layer files, the band-order can be set to BIL ('Bands Interleaved by Line'), BIP ('Bands Interleaved by Pixels') or BSQ ('Bands SeQuential').

dtype specifies the data type, determines the interpretation of values written to disk. Datatypes are described by 5 characters. The first three indicate whether the values are integers, decimal number or logical values. The fourth character indicates the number of bytes used to save the values on disk, and the last character indicates whether the numbers are signed (i.e. can be negative and positive values) or not (only zero and positive values allowed).

The following datatypes are available:

Datatype definition minimum possible value maximum possible value
LOG1S FALSE (0) TRUE (1)
INT1S -127 127
INT1U 0 255
INT2S -32,767 32,767
INT2U 0 65,534
INT4S -2,147,483,647 2,147,483,647
INT4U 0 4,294,967,296
FLT4S -3.4e+38 3.4e+38
FLT8S -1.7e+308 1.7e+308

Usage

1
  createRaster(filename,nrow,ncol,extent,nlayers=1,dtype='FLT4S',bandorder='BSQ',crs=NA,overwrite=FALSE,echo=TRUE)

Arguments

filename

character specifying the filename (with .grd extension) for the new empty Raster* object

nrow

a numeric value: number of rows

ncol

a numeric value: number of columns

extent

a numeric vector specifying the extent of the new raster including 4 values: xmin, xmax, ymin, and ymax

nlayes

a numeric value: number of raster layers (bands)

dtype

a character (default: 'FLT4S') specifying the type of data for the raster values (see description)

bandorder

a character (default: 'BSQ') specifying the organisation of raster values in the file; can be one of 'BSQ','BIP', 'BIL'

crs

a character specifying definitions for a coordinate reference system

overwrite

logical, if the filename already exists specifying whether the file should be overwritten

echo

logical; whether a message should be printed on the screen to report the success/fail of the new raster file creation

Author(s)

Babak Naimi naimi.b@gmail.com

http://r-gis.net

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
## Not run: 

# creating an empty raster with two layers:
createRaster('test.grd',nrow=10,ncol=10,extent=c(0,10,0,10),nlayers=2)

# reading the empty raster using the brick function from the raster package:
r <- brick('test.grd')

r

r[1:10] # check the values of cells 1:10 from both layers

plot(r) # Obviously, it is empty!


# writing values (randomly generated) into the first band
writeInRaster(rnorm(100),"test.grd",band=1)

plot(r)

# writing values into the second layers:
writeInRaster(1:100,"test.grd",band=2)

plot(r)


r[1:10]

## End(Not run)

babaknaimi/mraster documentation built on May 28, 2019, 2:34 a.m.