TransWikia.com

Remove internal boundaries in spatial object/polygon for plotting

Geographic Information Systems Asked by user5481267 on April 29, 2021

I am trying to plot a spatial object where only the outer boundaries/borders are plotted. The only way I can think to do this is by manually removing all the lines/points within the spatial object and leaving those for the outer borders in it, but I have no idea how I know which are which and wondered if there was a simpler way to do this.

The file I am using can be found here

The code I use to read this in and plot is:

m1<-geojson_read("topo_E06000023.json", what="sp")
plot(m1)

The object plotted is shown below and currently this shows all the lines/borders.

here

2 Answers

There is no lines/borders, just borders of each polygon. R can handle this as other GIS software who identify shared borders easily to represent them in a map. What are you looking for is a geoprocess called Dissolve. With rgeos you can achieve this in R:

library(geojsonio)
library(sp)
library(rgeos)

m1<-geojson_read("topo_E06000023.json", what="sp")
m2 <- gUnaryUnion(m1)

plot(m1)
plot(m2, add=T, border = 'red')

enter image description here

Correct answer by aldo_tapia on April 29, 2021

You can do this using the newer sf classes with st_union. You also don't need a separate package to read geojson.

library(sf)
m = st_read("./topo_E06000023.json")
plot(m$geom)
plot(st_union(m$geom))

enter image description here

Answered by Spacedman on April 29, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP