【发布时间】:2021-10-16 16:41:30
【问题描述】:
我开始创建我的数据框的两个子集,如下所示:
a = read_sf("a.shp")
a = st_make_valid(a)
#creating first subset with polygons from base year 2000
a1 = subset(a, year==2000)
#creating second subset with polygons from all the following years
a2 = subset(a, year>2000)
#creating buffer around base year
buffer = st_buffer(a1, 500)
#intersection of buffer from base year with polygons from the following years
#(lets assume the column "year" in the data.frame has a range of years 2000-2010)
results2000 = st_intersection(buffer, a2)
我现在必须在 2010 年之前的每一年都执行这些步骤。所以接下来的结果将如下所示:
a = read_sf("a.shp")
a = st_make_valid(a)
#creating first subset with polygons from base year 2000
a1 = subset(a, year==2001)
#creating second subset with polygons from all the following years
a2 = subset(a, year>2001)
#creating buffer around base year
buffer = st_buffer(a1, 500)
#intersection of buffer from base year with polygons from the following years
#(lets assume the column "year" in the data.frame has a range of years 2000-2010)
results2001 = st_intersection(buffer, a2)
唯一改变的条目是子集代码中的年份。
最后,我需要一个包含所有 10 个结果的 data.frame(结合 results2000 到 results2010,每个结果都将 2000 年到 2010 年之间的 10 年中的一年作为基准年)。
我可以创建所有 10 个结果并将它们组合起来
rbind(results2000,results2001,...)
等等。
但是他们这样做是不是更简单? 我想过使用foreach包中的foreach函数,可能是这样的
(Spatial) Efficient way of finding all points within X meters of a point?
但是使用 foreach 创建一个循环会导致绘制时间很长,因为 data.frame "a" 包含大约 100 万行。
谁能帮忙?
【问题讨论】: