在terra::rasterizeGeom()中,count和crosses之间的区别。

huangapple go评论54阅读模式
英文:

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)})

在terra::rasterizeGeom()中,count和crosses之间的区别。

英文:

"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 &lt;- rast(ncol=2, nrow=2, xmin=0, xmax=10, ymin=0, ymax=10)
v &lt;- vect(c(&quot;LINESTRING (1 7, 3 8)&quot;, &quot;LINESTRING (8 7, 4 6, 3 3)&quot;, &quot;LINESTRING (7 2, 8 4)&quot;))

cross &lt;- rasterizeGeom(v, r, &quot;crosses&quot;)
count &lt;- rasterizeGeom(v, r, &quot;count&quot;)

x &lt;- c(cross, count)
names(x) &lt;- c(&quot;cross&quot;, &quot;count&quot;)
  
plot(x, fun=\(){lines(x, col=&quot;gray&quot;); lines(v, col=rainbow(3), lwd=2)})

在terra::rasterizeGeom()中,count和crosses之间的区别。

huangapple
  • 本文由 发表于 2023年3月10日 00:27:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/75687422.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定