在R或ArcGIS中,我该如何处理多边形shapefile文件中的“孤立孔”?

18

我正在尝试使用over函数(rgeos)对两个多边形(“grd”和“range”)进行空间叠加。

这段代码对所有文件都有效,但有一个文件无法使用:

range.grd.overlay <- grd[!is.na(over(grd, range)), ]@data$grdID # get gridcells that overlap with range

并且收到以下错误信息:

Error in createPolygonsComment(p) : 
  rgeos_PolyCreateComment: orphaned hole, cannot find containing polygon for hole at index 9

我知道在这个shapefile中有一个没有周围多边形的洞,但我不知道如何解决它。 我可以简单地删除第9个洞吗?如何删除? 如果您有在ArcGIS中修复shapefile的解决方案,对我来说也可以。

非常感谢您提前的帮助!

谢谢, 卡斯滕


没有人能够帮助解决这个问题,因为我们不清楚grd或range的结构。许多对象可能具有@data$grdID插槽。这需要进行一些工作才能制作出可重复的示例。但是,您可以使用(免费的)QGIS与Geometry Tools或(经济实惠的)Manifold与Topology Factory进行交互式几何检查。 - mdsumner
听起来删除索引为9的洞应该可以解决问题。当您尝试时会发生什么?如果您没有更好的方法,taRifx包中的subset函数可以实现它(我最近不太了解空间方法)。 - Ari B. Friedman
好的,我明白了,很抱歉我没有非常具体地描述我的问题: - user1012744
@ari-b-friedman,taRifx似乎不再具有子集函数。 - geotheory
与GIS StackExchange相关的问题及答案:https://gis.stackexchange.com/questions/113964/fixing-orphaned-holes-in-r;提到的用于修复几何错误(也可找到孤立洞)的软件包:https://cran.r-project.org/web/packages/cleangeo/vignettes/quickstart.html。 - user3386170
在我读完这篇文章后,第一次出现了这个错误。震惊! - Peter.k
1个回答

3

grdrange 都是 SpatialPolygonsDataFrame 类。

range 的结构如下:

> str(range)
Formal class 'SpatialPolygonsDataFrame' [package "sp"] with 5 slots
  ..@ data       :'data.frame': 3 obs. of  17 variables:
  .. ..$ OBJECTID  : int [1:3] 725 726 727
  .. ..$ SPCRECID  : int [1:3] 3313 3313 3313
  .. ..$ DATE_     : Factor w/ 1 level "19/10/2009": 1 1 1
  .. ..$ SCINAME   : Factor w/ 1 level "Synthliboramphus antiquus": 1 1 1
  .. ..$ SOURCE    : Factor w/ 1 level "Gaston & Jones, 1998; Brazil, 2009": 1 1 1
  .. ..$ PRESENCE  : int [1:3] 1 1 1
  .. ..$ ORIGIN    : int [1:3] 1 1 1
  .. ..$ SEASONAL  : int [1:3] 2 1 3
  .. ..$ DATA_SENS : Factor w/ 0 levels: NA NA NA
  .. ..$ SENS_COMM : Factor w/ 0 levels: NA NA NA
  .. ..$ COMPILER  : Factor w/ 1 level "Philip Taylor (BirdLife International)": 1 1 1
  .. ..$ TAX_COM   : Factor w/ 0 levels: NA NA NA
  .. ..$ DIST_COM  : Factor w/ 0 levels: NA NA NA
  .. ..$ REVIEWERS : Factor w/ 0 levels: NA NA NA
  .. ..$ CITATION  : Factor w/ 1 level "BirdLife International and Natureserve (2011) Bird species distribution maps of the world.": 1 1 1
  .. ..$ SHAPE_Leng: num [1:3] 190 209 1240
  .. ..$ SHAPE_Area: num [1:3] 39 16.6 600.8
  .. ..- attr(*, "data_types")= chr [1:17] "N" "N" "C" "C" ...
  ..@ polygons   :List of 3
  .. ..$ :Formal class 'Polygons' [package "sp"] with 5 slots
  .. .. .. ..@ Polygons :List of 138
  .. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
  .. .. .. .. .. .. ..@ labpt  : num [1:2] 178.6 51.8
  .. .. .. .. .. .. ..@ area   : num 4.58
  .. .. .. .. .. .. ..@ hole   : logi FALSE
  .. .. .. .. .. .. ..@ ringDir: int 1
  .. .. .. .. .. .. ..@ coords : num [1:49, 1:2] 180 180 179 179 179 ...
  .. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
  .. .. .. .. .. .. ..@ labpt  : num [1:2] -172.2 52.6

grd 的结构如下:

> str(grd)
Formal class 'SpatialPolygonsDataFrame' [package "sp"] with 5 slots
  ..@ data       :'data.frame': 40680 obs. of  12 variables:
  .. ..$ ID        : int [1:40680] 361 362 363 364 365 366 367 368 369 370 ...
  .. ..$ X_COORD   : num [1:40680] -180 -178 -178 -176 -176 ...
  .. ..$ Y_COORD   : num [1:40680] 79.1 79.1 79.1 79.1 79.1 ...
  .. ..$ ID_1      : Factor w/ 13713 levels "10","10000","10001",..: NA NA NA NA NA NA NA NA NA NA ...
  .. ..$ grdID     : int [1:40680] 1 2 3 4 5 6 7 8 9 10 ...
  .. ..$ ROW       : int [1:40680] 1 1 1 1 1 1 1 1 1 1 ...
  .. ..$ COL       : int [1:40680] 1 2 3 4 5 6 7 8 9 10 ...
  .. ..$ AREA      : num [1:40680] 12364 12364 12364 12364 12364 ...
  .. ..$ PERIMETER : num [1:40680] 445 445 445 445 445 ...
  .. ..$ MAJORITY  : int [1:40680] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ PROP0_0062: num [1:40680] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..$ AREA_KM2  : num [1:40680] 0 0 0 0 0 0 0 0 0 0 ...
  .. ..- attr(*, "data_types")= chr [1:12] "N" "N" "N" "C" ...
  ..@ polygons   :List of 40680
  .. ..$ :Formal class 'Polygons' [package "sp"] with 5 slots
  .. .. .. ..@ Polygons :List of 1
  .. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots
  .. .. .. .. .. .. ..@ labpt  : num [1:2] -179.5 79.1
  .. .. .. .. .. .. ..@ area   : num 5.3
  .. .. .. .. .. .. ..@ hole   : logi FALSE
  .. .. .. .. .. .. ..@ ringDir: int 1
  .. .. .. .. .. .. ..@ coords : num [1:13, 1:2] -179 -180 -180 -180 -180 ...
  .. .. .. ..@ plotOrder: int 1
  .. .. .. ..@ labpt    : num [1:2] -179.5 79.1

我从Roger Bivand处得到了帮助,并且这个方法已经成功解决了三个问题文件中的两个:

>slot(shape.input, "polygons") <- lapply(slot(shape.input, "polygons"), checkPolygonsHoles)
>range.grd.overlay <- grd[!is.na(over(grd, range)), ]@data$grdID # get gridcells of that overlay with range polygon

但是对于第三个文件,修复并没有起作用。R会冻结直到我最终按下Esc键,之后当我尝试进行空间叠加时,我会得到相同的错误信息:

 Error in createPolygonsComment(p) : 
   rgeos_PolyCreateComment: orphaned hole, cannot find containing polygon for hole at index 13

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接