简体   繁体   中英

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

Im am trying to create a .geojson file in my local repository for this output . I am downloading the file locally, making my adjustments and writing input21.geojson , however, I get the message:

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

My code so far:

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"))

I Have figured a package called cleangeo that corrects some issues related with geo structure, adding the lines solve the problem:

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

before the line:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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