如何从r中另一个形状文件的多边形接触的多边形创建一个新的形状文件?

问题描述

我有两个shapefile,一个有大多边形,另一个有小多边形SpatialpolygonDataFrame我有很多大的多边形SpatialpolygonDataFrame,可以容纳许多小的多边形,我想创建一个仅包含大多边形被小多边形触及。我不仅想要交叉点,还想要所有大多边形。但是尝试解决这个问题,我做了一个交集以获取带有相交ID的列。我以为有了这些信息,我就可以从另一个多边形中提取多边形,但是它不起作用。

类似这样的东西:

enter image description here

library (raster)
intsct_shp<-raster::intersect(shp1,shp2)

intsct_shp$ID.1 #ID.1 because both had the same column name "ID"

[1] 9  17 17 38 38 38 39 39 50 53 54 71 84 89 89 89 89 89
101 Levels: 0 1 10 100 11 12 13 14 15 16 17 18 19 2 20 21 22 23 24 25 ... 99

 # my original data has many more polygons
 ids<- as.vector(unique(intsct_shp$ID.1)) 
 ids
 [1] "50" "38" "53" "89" "17" "9"  "39" "84" "54" "71"    
 
 new_shp<-shp1[shp1@data$ID == ids,] 
 
 
 Warning messages:
    1: In `==.default`(shp1@data$ID,ids) :
    longer object length is not a multiple of shorter object length
     2: In is.na(e1) | is.na(e2) :
     longer object length is not a multiple of shorter object length
     

     plot(new_shp)

    

enter image description here

仅绘制了一个多边形

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)