简体   繁体   English

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

[英]How can I handle an “orphaned hole” in a polygon shapefile in R or ArcGIS?

I am trying to make a spatial overlay between two polygons ("grd" and "range") using the over function (rgeos). 我试图使用over函数(rgeos)在两个多边形(“grd”和“range”)之间进行空间叠加。

This code works for all files but one: 此代码适用于所有文件但只有一个:

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

and get this error message: 并收到此错误消息:

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

I understand that there is a hole without a surrounding polygon somewhere in the shapefile, but I can't figure out how to work around it. 我知道shapefile中有一个没有周围多边形的洞,但我无法弄清楚如何解决它。 Can I simply delete the hole at index 9 ? 我可以简单地删除索引9处的洞吗? How ? 怎么样 ? If you have a solution to fix the shapefile in ArcGIS that would also be fine for me. 如果您有一个解决方案来修复ArcGIS中的shapefile,那对我来说也没问题。

Thanks a lot in advance for your help !! 非常感谢您的帮助!

Regards, Carsten 此致,卡斯滕

Both grd and range are of the class SpatialPolygonsDataFrame . grdrange都属于SpatialPolygonsDataFrame类。

range has a structure like this: 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

... and so on. ... 等等。

grd has a structure like this: 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

... and so on. ... 等等。

I found this help from Roger Bivand and this worked for two out of three problematic files: 我从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

but for the third file the fixing did not work. 但对于第三个文件,修复不起作用。 R would freeze until I eventually pressed Esc, after which I would get the same error message when trying to make the spatial overlay: R会冻结,直到我最终按下Esc,之后我会在尝试制作空间叠加时得到相同的错误消息:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Shapefile多边形聚合地理编码数据以使用R进行可视化? - How can I aggregate geocoded data by a shapefile polygon for visualisation using R? 如何遍历 R 中单个 shapefile 中的多个重叠多边形以获取每个多边形的区域统计信息? - How can I iterate through multiple overlapping polygons in a single shapefile in R to get zonal statistics of each polygon? 我如何 map 到 R 中我的多边形/形状文件的最近点的纬度/经度 - How can I map a lat/long to the nearest point of my polygon/shapefile in R 如何通过 R 中的另一个多边形 shapefile 剪辑多边形 shapefile? - How to clip a polygon shapefile by another polygon shapefile in R? R 如何合并具有多个多边形的 shapefile 中的多边形特征? (可重现的代码示例) - R How do I merge polygon features in a shapefile with many polygons? (reproducible code example) Z - R中多边形(shapefile)的值 - Z - Values for polygon (shapefile) in R 如何从R中的shapefile中按属性消除某些区域并创建新的shapefile? - How can I eliminate some areas by attribute from a shapefile in R and create a new shapefile? 如何从shapefile传单R访问多边形信息 - How to access polygon information from shapefile leaflet R 如何在R中将多边形shapefile的许多字段自动转换为栅格 - How to automatically convert many fields of a polygon shapefile to raster in R 来自 ArcGIS 的 Shapefile 孔未保存在 R 或 QGIS 中 - Shapefile holes from ArcGIS not preserved in R or QGIS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM