R 沿横断面提取光栅像素的位置
我有以下几点R 沿横断面提取光栅像素的位置,r,gis,r-raster,R,Gis,R Raster,我有以下几点 library(raster) r <- raster(ncol=2421, nrow=5005) r: class : RasterLayer dimensions : 2421, 5005, 12117105 (nrow, ncol, ncell) resolution : 1, 1 (x, y) extent : 501121, 506126, 2809088, 2811509 (xmin, xmax,
library(raster)
r <- raster(ncol=2421, nrow=5005)
r:
class : RasterLayer
dimensions : 2421, 5005, 12117105 (nrow, ncol, ncell)
resolution : 1, 1 (x, y)
extent : 501121, 506126, 2809088, 2811509 (xmin, xmax, ymin,
ymax)
crs : +proj=utm +zone=17 +datum=WGS84 +units=m +no_defs
+ellps=WGS84 +towgs84=0,0,0
source : E:/Datat Layers/Clip/Harney_XMerge.tif
names : Harney_XMerge
values : -3.126388e-13, 57.14 (min, max)
我想提取沿横断面的每个像素的坐标,但我自己找不到任何这样做的函数
我使用了以下提取功能,但它仅从光栅中提取信息(在本例中为树高数据)。我是否有办法使用提取功能或其他功能提取沿已建立横断面的每个像素的UTM坐标
extract(r,line )
当提出问题时,请提供一个可重复的最小示例。查看R帮助文件中的示例。例如,从明显的位置复制,?光栅::提取: 它返回一个列表,其中每个多段线都有一个包含单元号和值的矩阵。从手机号码可以得到坐标
f <- lapply(e, function(x) xyFromCell(r, x[,1]))
如果需要沿直线对点进行排序,请使用extract参数ALOWN=TRUE
library(raster)
r <- raster(ncol=36, nrow=18, vals=1)
cds1 <- rbind(c(-50,0), c(0,60), c(40,5), c(15,-45), c(-10,-25))
cds2 <- rbind(c(80,20), c(140,60), c(160,0), c(140,-55))
lines <- spLines(cds1, cds2)
extract(r, lines)
e <- extract(r, lines, cellnumbers = TRUE)
f <- lapply(e, function(x) xyFromCell(r, x[,1]))
e <- extract(r, lines, cellnumbers = TRUE, df=T)
d <- data.frame(ID=e[,1], xyFromCell(r, e[,2]))
head(d)
# ID x y
#[1,] 1 -5 55
#[2,] 1 5 55
#[3,] 1 -15 45
#[4,] 1 -5 45
#[5,] 1 5 45
#[6,] 1 15 45