Reputation: 328
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"))
Upvotes: 0
Views: 341
Reputation: 328
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"))
Upvotes: 0