gpt4 book ai didi

r - 在 R 中沿(Poly)线创建等距点

转载 作者:行者123 更新时间:2023-12-04 16:33:56 25 4
gpt4 key购买 nike

如果我有一个像这样的空间线对象:

require(sp)

x <- c(18.25721, 18.25763,18.25808,18.25846,18.25864,18.25886,18.25892,18.25913,18.25940,18.25962,
18.25976,18.25997,18.26021,18.26048,18.26061,18.26086,18.26107,18.26128,18.26154,18.26219,
18.26276,18.26350,18.26445,18.26510,18.26584,18.26668,18.26704,18.26807,18.26850,18.26944,
18.27020,18.27080,18.27111,18.27134,18.27168,18.27191,18.27217,18.27254,18.27309,18.27345,
18.27368,18.27389,18.27398,18.27400,18.27392,18.27383,18.27370)

y <- c(44.69540,44.69539,44.69544,44.69552,44.69563,44.69586,44.69608,44.69644,44.69672,44.69687
,44.69701,44.69718,44.69737,44.69763,44.69771,44.69778,44.69781,44.69781,44.69782,44.69776
,44.69772,44.69778,44.69794,44.69805,44.69814,44.69822,44.69824,44.69826,44.69821,44.69805
,44.69775,44.69737,44.69728,44.69717,44.69701,44.69687,44.69671,44.69649,44.69616,44.69598
,44.69578,44.69560,44.69539,44.69513,44.69490,44.69476,44.69453)

river<-SpatialLines(list(Lines(Line(cbind(x,y)), ID="a")))
proj4string(river) <- CRS("+init=epsg:4326")

例如,如何每 3m 沿这条线创建点。结果看起来像这样:
enter image description here

我无法弄清楚或找到一个可以做到这一点的软件包。

最佳答案

来自 sp package 的 spsample() 函数怎么样? ?您将只对 n 个点进行采样,其中

numOfPoints  <-  gLength(river) / 3
spsample(river, n = numOfPoints, type = "regular")

(gLength 是来自 rgeos package 的函数)

属性 不必是整数,所以你应该得到非常接近的估计。

关于r - 在 R 中沿(Poly)线创建等距点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33281319/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com