6. How raster
functions map to
stars
functions
Sébastien Rochette, Adriano Fantini, Edzer
Pebesma
star の vignette のより良いバージョンは、 https://r-spatial.github.io/stars/articles/ を参照。
[issue #122] (https://github.com/r-spatial/stars/issues/122)
で説明した raster
の関数が stars
の関数にどのように対応するかを説明する表の試みが、ここにある。この表は
raster
パッケージの関数をテンプレートとして使用している。不完全、不正確、あるいは明らかに間違っているだろうので、塩の一つまみをもって見てみよう。どんなコメントや修正も大歓迎である。
一部の関数( filter
, slice
,
mutate
, select
, pull
, … )は
dplyr
を介して提供されており、これを読み込む必要がある。?stars::dplyr
を参照。
オブジェクトの作成
{raster, stack, brick} (read) |
read_stars or read_stars(along = …) |
|
{stack, brick} (concatenate layers) |
c or c(along = …) |
|
subset |
{[ ] , slice, filter} |
|
addLayer |
c() or c(along = …) |
|
dropLayer |
{[ ] , slice, filter} |
|
unstack |
combine lapply and {[ ] , slice, filter} |
|
物体の空間的な広がりや解像度を変更する
merge |
c |
#, currently only works for adjacent objects |
mosaic |
st_mosaic |
these are not identical, read the docs carefully |
crop |
filter, st_crop |
|
setExtent |
|
# maybe use st_warp? |
trim |
|
# |
aggregate |
aggregate |
WIP; raster’s aggregate with fact=2 will not work, use
st_warp in that case? |
disaggregate |
|
# use st_warp(use_gdal = TRUE)? |
resample |
{st_transform, st_warp} |
|
projectRaster |
{st_transform, st_warp} |
|
shift |
|
#, now use st_set_dimensions |
flip |
[] with reversed index |
# |
rotate |
|
* |
t |
|
NA |
セルベースコンピューティング
calc |
st_apply |
|
overlay |
c(along = , …) %>% st_apply(…) |
|
cover |
[ ] <- |
|
mask |
[ ], st_crop |
when using an sf polygon as mask |
mask |
[ ]<- NA |
when using a stars object to mask |
cut |
cut |
|
subs |
|
|
reclassify |
mutate with case_when |
or forcats::fct_recode ? |
reclassify |
cut |
see https://stackoverflow.com/questions/70619002/reclassify-2d-stars-array/ |
init |
[ ] <- |
|
stackApply |
{[ ] , slice, filter} %>% st_apply |
|
stackSelect |
|
|
空間的な文脈の計算
distance |
|
# |
gridDistance |
|
* |
distanceFromPoints |
|
# |
direction |
|
* |
focal |
f = st_apply(x1, 3, foc, w = matrix(1, 3, 3)) |
See. issue 176 |
localFun |
|
* |
boundaries |
st_as_sf(as_points=FALSE, merge=TRUE,
connect8=TRUE) |
|
clump |
st_as_sf(r, merge = TRUE) |
st_as_sf returns polygons,
clump a raster |
adjacent |
|
* |
area |
st_area |
|
terrain |
|
# |
Moran |
|
|
モデル予測
predict |
predict |
|
interpolate |
gstat::idw, gstat::krige |
st_warp has raster-raster interpolations
of gdalwarp |
データ型変換
rasterize |
st_as_stars |
|
rasterToPoints |
st_as_sf(as_points=TRUE) |
|
rasterToPolygons |
st_as_sf(as_points=FALSE, …), st_polygonize |
|
rasterToContour |
st_contour |
requires GDAL >= 2.4.0 |
rasterFromXYZ |
|
|
rasterFromCells |
|
|
まとめる
cellStats |
st_apply |
|
summary |
print, summary(as.vector(. %>% pull)) |
|
freq |
table |
* |
crosstab |
|
|
unique |
unique(as.vector(. %>% pull)) |
|
zonal |
|
* |
オブジェクトの値にアクセスする
getValues |
{pull, [[ ]]} |
|
getValuesBlock |
{[ ] , slice, filter} %>% pull |
|
getValuesFocal |
{[ ] , slice, filter} %>% pull |
|
as.matrix |
[[ ]] |
currently behaves somewhat unexpectedly * |
as.array |
[[ ]] |
currently behaves somewhat unexpectedly * |
extract (by cell) |
{[ ] , slice, filter} |
|
extract (by polygon) |
x[sf_object] |
|
extract (by point) |
aggregate(stars_object, sf_object, function(x) x[1],
as_points = FALSE) |
|
sampleRandom |
|
* |
sampleRegular |
|
* |
minValue |
purrr::map(x, min) |
|
maxValue |
purrr::map(x, max) |
|
setMinMax |
|
, |
プロット
plot |
plot, geom_stars |
|
plotRGB |
plot(x, rgb =…) |
|
spplot |
- |
|
image |
image |
|
persp |
- |
|
contour |
(st_contour, then sf::plot) |
|
filledContour |
(same) |
|
text |
text |
|
hist |
hist(x[[1]]) |
|
barplot |
|
|
density |
|
|
pairs |
|
|
boxplot |
|
|
ディメンジョンの取得と設定
ncol |
dim(x)[1] |
or use name instead of 1; cols may be the second
dimension! |
nrow |
dim(x)[2] |
or use name instead of 2; rows may be the first
dimension! |
ncell |
prod(dim(x)) |
|
res |
st_dimensions |
can also not be a constant in case of rectilinear or
curvilinear grids |
nlayers |
- |
there is no concept of layers in stars |
names |
names |
|
xres |
st_res(x)[1] |
may not be a constant in case of rectilinear or
curvilinear grids |
yres |
st_res(x)[2] |
may not be a constant in case of rectilinear or
curvilinear grids |
xmin |
st_bbox(x)[1] |
|
xmax |
st_bbox(x)[3] |
|
ymin |
st_bbox(x)[2] |
|
ymax |
st_bbox(x)[4] |
|
extent |
st_bbox(x) |
different ordering of numbers |
origin |
- |
|
projection |
st_crs(x) |
|
isLonLat |
st_is_longlat(st_crs(x)) |
|
filename |
|
stars_proxy objects carry file names where otherwise
the array data is |
bandnr |
|
stars has no general concept of bands |
nbands |
dim(x)[3] |
may also be time; bands may also be in another
dimension, or have another name |
compareRaster |
all.equal(st_dimensions(x), st_dimensions(y)) |
* |
NAvalue |
|
- |
行、列、セルの番号と座標を計算する
xFromCol |
st_get_dimension_values(., ‘x’)[col] |
I am not sure how to generally get the x dimension name
- here it is x |
yFromRow |
st_get_dimension_values(., ‘y’)[row] |
I am not sure how to generally get the y dimension name
- here it is y |
xFromCell |
|
|
yFromCell |
|
|
xyFromCell |
|
|
colFromX |
|
* |
rowFromY |
|
* |
rowColFromCell |
|
|
cellFromXY |
st_cells() |
|
cellFromRowCol |
|
|
cellsFromExtent |
|
|
coordinates |
st_coordinates |
|
validCell |
|
|
validCol |
col %>% between(st_dimensions(.)\(x\)from, st_dimensions(.)\(x\)to) |
raster columns are not always named ‘x’ |
validRow |
row %>% between(st_dimensions(.)\(y\)from, st_dimensions(.)\(y\)to) |
raster columns are not always named ‘y’ |
setValues |
[ ] <- |
|
writeRaster |
write_stars |
currently uses GDAL, somewhat limited |
KML |
|
|
この表のフォーマットは、ラスタマニュアルの
raster-package
の項目 (
https://cran.r-project.org/web/packages/raster/raster.pdf
)
に従っている。
comment legend
よくわからない/不明
* ⑭不在、低優先度
# ⑭不在、高優先度
NA = デザイン上、利用できない