identify: Get value and coordinates from location

Description Usage Arguments Details Value Author(s) Examples

Description

Functions to extract values of raster image from given location, specified by coordinates in raster projection, by cell position or by geogpaphical coordinates. Additional utils to convert cell position and planar coordinates mutually.

Usage

1
2
3
4
5
6
7
8
9
value_xy(obj, ...)

value_ll(obj, ...)

value_cr(obj, ...)

coord_xy(obj, ...)

coord_cr(obj, ...)

Arguments

obj

Object of class ursaRaster.

...

the set of argumetns, which are recognized via their names (using regular expressions) and classes:

Matched pattern Function Used name
ind *_* ind Index (positive integer) in internal value storage.
^c *_cr col Integer of non-zero length. Index of column/sample Length of column and row indices should be the same for creating set of two-dimension coordinates.
^r *_cr row Integer of non-zero length. Index of row/line. Length of column and row indices should be the same for creating set of two-dimension coordinates.
^x *_xy x Numeric of non-zero length. X-axis coordinate in grid of obj. The length of X-axis and Y-axis coordinates should be the same for creating set of two-dimension coordinates.
^y *_xy y Numeric of non-zero length. Y-axis coordinate in grid of obj. The length of X-axis and Y-axis coordinates should be the same for creating set of two-dimension coordinates.
^lon value_ll lon Longitude. The length of longitudes and latitudes should be the same for creating set of two-dimension coordinates.
^lat value_ll lat Latitude. The length of longitudes and latitudes should be the same for creating set of two-dimension coordinates.

Details

value_xy returns values for location, which is specified by planar coordinates (x, y).
value_cr returns values for location, which is specified by cell posisition (column, row) relative to upper-left corner of image .
value_ll returns values for location, which is specified by longitude and latitude (long, lat).

coord_xy transforms planar coordinates (x, y) to cell position (column, row).
coord_cr transforms cell position (column, row) to planar coordinates (x, y).

It is required to use a couple of coordinate vectors: (x, y), (c, r) or (lon, lat) of the same length. The unary argument is interpreted as index in internal value storage.

Position in column/row coordinates starts from upper-lever corner. The cell of upper-level corner has (1, 1) coordinates (in R indices starts from 1L), whereas in some GIS the same corner cell has (0, 0) coordinates.

The column names of returned matrix are character format of index in internal value storage. This index can be specify in any function as argument ind instead of coordinates (planar, geographical, cell position).

Value

For value.* numeric matrix of raster values. Band values for specific coordinates are by column. Set of specific coordinates are by row. rownames are band names, and colnames are index in internal value storage.

For coord.* numeric matrix of coordinates with a vector of couple coordinates, one coordinate per one row. rownames are returned coordinates, and colnames are index in internal value storage.

Author(s)

Nikita Platonov [email protected]

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
session_grid(NULL)
set.seed(352)
a <- as.integer(ursa_dummy(3,min=0,max=999))
ind <- which(ursa_value(a[1])==890)
print(ind)
msk <- a[1]==890
am <- a[msk]
b <- as.data.frame(am)
b$jx <- b$x+runif(nrow(b),min=-1000,max=1000)
b$jy <- b$y+runif(nrow(b),min=-1000,max=1000)
print(b)
cr1 <- coord_xy(a,x=b$jx,y=b$jy)
cr2 <- coord_xy(a,y=b$y,x=b$x)
cr3 <- coord_xy(a,ind=ind)
print(cr1)
print(all.equal(cr1,cr2,cr3))
xy1 <- coord_cr(a,c=cr1["c",],r=cr1["r",])
print(xy1)
print(c(identical(unname(xy1["x",]),b[,"x",drop=TRUE])
       ,identical(unname(xy1["y",]),b[,"y",drop=TRUE])))
val1 <- value_xy(a,x=b$jx,y=b$jy)
val2 <- value_xy(a,x=b$x,y=b$y)
val3 <- value_cr(a,ind=ind)
val4 <- value_cr(a,c=cr1["c",],r=cr1["r",])
print(val1)
print(all.equal(val1,val2,val3,val4))
ps <- pixelsize()
ll <- c(lon=180,lat=70)
v <- value_ll(ps,lon=180,lat=70)
print(c('True scale'=v/with(ursa_grid(ps),1e-6*resx*resy)))

nplatonov/ursa documentation built on Nov. 21, 2018, 2:13 p.m.