4

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 2

10

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

1

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.