2012-07-11 65 views
14

我正在嘗試使用over函數(rgeos)在兩個多邊形(「grd」和「range」)之間進行空間疊加。如何在R或ArcGIS中處理多邊形shape文件中的「孤立孔」?

此代碼適用於所有的文件,但一個:

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 

我明白,有沒有在shape文件的某處周圍的多邊形孔,但我無法弄清楚如何解決它。 我可以簡單地刪除索引9處的孔嗎?怎麼樣 ? 如果您有解決方案來修復ArcGIS中的shapefile,那也適用於我。

非常感謝您的幫助!

問候, 卡斯滕

+0

沒有人會對此有所幫助,因爲我們有對GRD或結構不知道範圍。許多對象可能有一個@ data $ grdID插槽。這需要做一個可重現的例子。但是,使用(免費)QGIS與幾何工具或(負擔得起的)與拓撲工廠的歧管交互式幾何檢查。 – mdsumner 2012-07-11 13:31:08

+0

這聽起來像刪除索引9的洞應該工作。當你嘗試時會發生什麼? 'taRifx'包中的'subset'應該做到這一點,如果你沒有更好的方法(我現在還沒有使用空間方法)。 – 2012-07-11 13:32:12

+0

好吧,我明白了,對不起,我的問題沒有具體說明: – user1012744 2012-07-11 15:01:16

回答

2

兩個grdrange是類SpatialPolygonsDataFrame的。

range具有這樣的結構:

> str(range) 
Formal class 'SpatialPolygonsDataFrame' [package "sp"] with 5 slots 
    [email protected] 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" ... 
    [email protected] polygons :List of 3 
    .. ..$ :Formal class 'Polygons' [package "sp"] with 5 slots 
    .. .. .. [email protected] Polygons :List of 138 
    .. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots 
    .. .. .. .. .. .. [email protected] labpt : num [1:2] 178.6 51.8 
    .. .. .. .. .. .. [email protected] area : num 4.58 
    .. .. .. .. .. .. [email protected] hole : logi FALSE 
    .. .. .. .. .. .. [email protected] ringDir: int 1 
    .. .. .. .. .. .. [email protected] coords : num [1:49, 1:2] 180 180 179 179 179 ... 
    .. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots 
    .. .. .. .. .. .. [email protected] labpt : num [1:2] -172.2 52.6 

...等等。

grd具有這樣的結構:

> str(grd) 
Formal class 'SpatialPolygonsDataFrame' [package "sp"] with 5 slots 
    [email protected] 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" ... 
    [email protected] polygons :List of 40680 
    .. ..$ :Formal class 'Polygons' [package "sp"] with 5 slots 
    .. .. .. [email protected] Polygons :List of 1 
    .. .. .. .. ..$ :Formal class 'Polygon' [package "sp"] with 5 slots 
    .. .. .. .. .. .. [email protected] labpt : num [1:2] -179.5 79.1 
    .. .. .. .. .. .. [email protected] area : num 5.3 
    .. .. .. .. .. .. [email protected] hole : logi FALSE 
    .. .. .. .. .. .. [email protected] ringDir: int 1 
    .. .. .. .. .. .. [email protected] coords : num [1:13, 1:2] -179 -180 -180 -180 -180 ... 
    .. .. .. [email protected] plotOrder: int 1 
    .. .. .. [email protected] 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