定义要在For循环中使用的同一文件夹(List.Vector)中的shapefile列表 - 地理空间建​​模环境

时间:2016-09-07 12:49:19

标签: list for-loop geospatial shapefile

我正在尝试使用list.vector在地理空间建​​模环境中创建shapefile列表。哪个有效并产生以下列表。

list.vector(in="D:\Buffers", match="*.shp");
  

d:\缓冲器\ OBJECTID_1.shp,   d:\缓冲区\ OBJECTID_10.shp,   d:\缓冲区\ OBJECTID_100.shp,
  d:\缓冲区\ OBJECTID_1000.shp,   d:\缓冲器\ OBJECTID_10000.shp ......

然后我想使用isectpolypoly函数遍历不同的shapefile。目前我的代码是:

list<-list.vector(in="D:\Buffers", match="*.shp");

for (i in 1:length(list)) {

isectpolypoly(in=paste(i), poly="D:\Polygons\agri.shp", field="P_", thematic=TRUE, proportion=TRUE);

};

我收到以下错误。

  

错误:未正确指定for循环。长度   函数似乎不是指定义的向量。

所以看起来好像我没有定义&#34; list&#34;正确地能够在循环中使用它。关于如何做到这一点,我找不到任何明确的答案。

任何人都可以帮我改变我的代码,以便我可以定义shapefile列表然后遍历列表中的shapefile吗?

1 个答案:

答案 0 :(得分:0)

如果有人有兴趣我设法解决自己的问题。

我无法成功回忆这个列表,并且由于我的每个shapefile都有一个唯一的数字标识符,因此可以循环遍历这些数字。

wd<-"D:\Buffers\";
for (i in 10001:10006);
{ 
isectpolypoly(in=paste(wd,"OBJECTID_",i,".shp"),
poly="D:\Polygons\agri.shp", 
field=“CLASS”, 
prefix="P_", 
thematic=TRUE, proportion=TRUE) 
};