arc.raster-class: Reference Class "arc.raster"

arc.raster-classR Documentation

Reference Class "arc.raster"

Description

A raster dataset is any valid raster format organized into one or more bands. Each band consists of an array of pixels (cells), and each pixel has a value. A raster dataset has at least one band. Raster data is a discrete data representation in which space is divided into uniform cells, or pixels.

Fields

sr

Get or set spacial reference

extent

Get or set extent. Use it to read a portion of the raster.

nrow

Get or set number of rows.

ncol

Get or set number of columns.

cellsize

Get pixel size.

pixel_type

Get or set pixel type. For details see ArcGIS help on pixel types.

pixel_depth

Get pixel depth. Pixel depth/Bit depth (1, 2, 4, 8, 16, 32, 64). For details see ArcGIS help on pixel types.

nodata

Get or set nodata value

resample_type

Get or set resampling type. For details see ArcGIS help on rasampling.

colormap

Get or set color map table. Return is a vector of 256 colors in the RGB format.

bands

Get list of raster bands

band

Get a single raster band

Methods

names

return bands names

dim

retrieves dimensions

$show()

show object

$pixel_block(ul_x, ul_y, nrow, ncol, bands)

Read pixel values.

ul_x, ul_y - optional, upper left corner in pixels nrow, ncol - optional, size in pixels bands - optional, select band(s).

The values returned are always a matrix, with the rows representing cells, and the columns representing band(s), c(nrow*ncol, length(bands)) (see Example #1)

$write_pixel_block(values, ul_x, ul_y, ncol, nrow)

Write pixel values. (see Example #2)

ul_x, ul_y - optional, upper left corner in pixels nrow, ncol - optional, size in pixels

$has_colormap()

logical, return TRUE if raster has colormap

$attribute_table()

Query raster attribute table. Return data.frame object.

Raster datasets that contain attribute tables typically have cell values that represent or define a class, group, category, or membership.

$save_as(path, opt)

TODO (see Example #3)

$commit(opt)

End writing. (see Example #2.3)

opt - additional parameter(s): (default: "build-stats"), ("build-pyramid")

arc.write

Write to an ArcGIS raster dataset

See Also

arc.raster, arc.write, arc.datasetraster-class

Examples


## Example #1. read 5x5 pixel block with 10,10 offset
r.file <- system.file("pictures", "cea.tif", package="rgdal")
r <- arc.raster(arc.open(r.file))
v <- r$pixel_block(ul_x = 10L, ul_y = 10L, nrow = 5L, ncol= 5L)
dim(v) == c(25, 1)
#[1] TRUE TRUE

stopifnot(length(v) == 25)

## Example #2. process big raster
## 2.1 create new arc.raster
r2 = arc.raster(NULL, path=tempfile("r2", fileext=".img"),
                dim=dim(r), pixel_type=r$pixel_type, nodata=r$nodata,
                extent=r$extent,sr=r$sr)
## 2.2 loop by rows, process pixels
for (i in 1L:r$nrow)
{
  v <- r$pixel_block(ul_y = i - 1L, nrow = 1L)
  r2$write_pixel_block(v * 1.5, ul_y = i - 1L, nrow = 1L, ncol = r$ncol)
}
## 2.3 stop all writings and crete raster file
r2$commit()

## Example #3. resample raster
r <- arc.raster(arc.open(r.file), nrow=200L, ncol=200L, resample_type="BilinearGaussBlur")
## save to a different format
r$save_as(tempfile("new_raster", fileext=".img"))

## Example #4. get and compare all pixel values
r.file <- system.file("pictures", "logo.jpg", package="rgdal")
rx <- raster::brick(r.file)
r <- arc.raster(arc.open(r.file))
stopifnot(all(raster::values(rx) == r$pixel_block()))



R-ArcGIS/r-bridge documentation built on May 3, 2024, 9:47 a.m.