英文:
Difference between count and crosses in terra::rasterizeGeom()
问题
我想使用terra R包将道路(SpatVector; 线)转换为栅格(SpatRaster)。terra::rasterizeGeom()
函数支持四种功能: "count", "area", "length" 或 "crosses"。
- "area" 在这种情况下没有意义。
- "length" 很直观。
我不明白"count"和"crosses"之间的区别。您能否解释使用这两个功能选项的输出地图之间的差异。
谢谢,Ahmed
英文:
I would like to convert roads (SpatVector; lines) to raster (SpatRaster) using terra R package. The terra::rasterizeGeom()
function supports four functions: "count", "area", "length", or "crosses".
- "area" does not make sense in this context.
- "length" is intuitive.
I do not understand the difference between "count" and "crosses". Could you please explain the difference in the output map using either function options.
Cheers, Ahmed
答案1
得分: 1
"crosses"计算穿越单元格边界的线条数量。 "count"还包括不穿越边界的线条。如下所示:
library(terra)
r <- rast(ncol=2, nrow=2, xmin=0, xmax=10, ymin=0, ymax=10)
v <- vect(c("LINESTRING (1 7, 3 8)", "LINESTRING (8 7, 4 6, 3 3)", "LINESTRING (7 2, 8 4)"))
cross <- rasterizeGeom(v, r, "crosses")
count <- rasterizeGeom(v, r, "count")
x <- c(cross, count)
names(x) <- c("cross", "count")
plot(x, fun=function(){lines(x, col="gray"); lines(v, col=rainbow(3), lwd=2)})
英文:
"crosses" counts the number of lines that cross the border of a cell. "count" also includes lines that do not cross the border. Illustrated below
library(terra)
r <- rast(ncol=2, nrow=2, xmin=0, xmax=10, ymin=0, ymax=10)
v <- vect(c("LINESTRING (1 7, 3 8)", "LINESTRING (8 7, 4 6, 3 3)", "LINESTRING (7 2, 8 4)"))
cross <- rasterizeGeom(v, r, "crosses")
count <- rasterizeGeom(v, r, "count")
x <- c(cross, count)
names(x) <- c("cross", "count")
plot(x, fun=\(){lines(x, col="gray"); lines(v, col=rainbow(3), lwd=2)})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论