繁体   English   中英

rgeos::createPolygonsComment(oobj) 中的错误:在 R 中使用 geojsonio 的孤立洞

[英]Error in rgeos::createPolygonsComment(oobj) : orphaned hole using geojsonio in R

我正在尝试在我的本地存储库中为此 output创建一个.geojson文件。 我正在本地下载文件,进行调整并编写input21.geojson ,但是,我收到以下消息:

Error in rgeos::createPolygonsComment(oobj) : 
rgeos_PolyCreateComment: orphaned hole, cannot find containing polygon for hole at index 51

到目前为止我的代码:

library(jsonlite)
library(rgdal)
library(downloader)
library(geojsonio)
library(maptools)


u <- paste0('https://servicodados.ibge.gov.br/api/v2/malhas/21?formato=application/vnd.geo+json')

downloader::download(url = u, destfile = "/tmp/gas.GeoJSON")
gas <- readOGR(dsn = "/tmp/gas.GeoJSON")

gas$var0031 <- 21
gas$var0517 <- 0 
gas$var0514  <- as.numeric(substr(as.character(gas$var0031),1,1))
gas$var0512 <- "MA"
gas$var0513 <- "Maranhão"
gas <- gas[which(names(gas) %in% c("var0517", "var0031", "var0514", "var0512", "var0513"))]

geojsonio::geojson_write(gas, file = paste0("./data/in/sidra_malhas/input21.geojson"))

我想出了一个名为cleangeo的 package 来纠正与地理结构相关的一些问题,添加以下行来解决问题:

gas <- cleangeo::clgeo_Clean(gas)
slot(gas, "polygons") <- lapply(slot(gas, "polygons"), checkPolygonsHoles)

行前:

geojsonio::geojson_write(gas, file = paste0("./data/in/sidra_malhas/input21.geojson"))

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM