r buffering line feature causes crash

63 views Asked by At

I am try to select points in an area around the former Iron Curtain.

So I got the shapefiles and intersected former Eastern and Western Europe to get a line feature

library(raster)
library(sp)
library(rgeos)

### set project crs
proj.crs<-CRS("+init=epsg:3035")

### Get shp
iso.star<-c("AUT", "DEU", "SVK", "CZE", "HUN", "HRV", "ITA", "LIE", "CHE", "SVN")
star.shp<-do.call("bind",lapply(iso.star,function(x) getData('GADM',country=x,level=1,path=getwd())))

### remove S-Italian Provinces
star.excl<-c("Sardegna","Sicily", "Abruzzo", "Marche","Umbria", "Toscana","Calabria","Basilicata","Molise","Lazio","Puglia","Apulia","Campania")
star.shp<-star.shp[!star.shp@data$NAME_1 %in% star.excl,]
star.shp<-spTransform(star.shp, proj.crs)

### Socioeconomic orientation
ctry.w<-c("Austria", "Italy", "Liechtenstein","Switzerland", "Liechtenstein", "Germany")
ctry.e<-c("Slovakia", "Czech Republic", "Hungary")
ctry.y<-c("Croatia", "Slovenia")
ger.east<-c("Brandenburg", "Mecklenburg-Vorpommern", "Sachsen", "Thüringen", "Sachsen-Anhalt", "Berlin")

### include east/west/yugoslav info
star.shp@data[star.shp@data$NAME_0 %in% ctry.w, "socio"]<-"Western Europe"
star.shp@data[star.shp@data$NAME_0 %in% ctry.e, "socio"]<-"Eastern Europe"
star.shp@data[star.shp@data$NAME_0 %in% ctry.y, "socio"]<-"Yugoslavia"
star.shp@data[star.shp@data$NAME_1 %in% ger.east, "socio"]<-"Eastern Europe"

### now separate Germany
star.shp@data$NAME_new<-star.shp@data$NAME_0
star.shp@data$NAME_new[star.shp@data$NAME_0=="Germany"]<-"West Germany"
star.shp@data$NAME_new[star.shp@data$NAME_1 %in% ger.east]<-"East Germany"

east<-unionSpatialPolygons(star.shp[star.shp@data$socio=="Eastern Europe",], rep(1,48))
plot(east)

west<-unionSpatialPolygons(star.shp[star.shp@data$socio=="Western Europe",], rep(1,64))
plot(west)

ic<-gIntersection(west,east)

So then I figured I would just simply buffer around the line, in my case I need a (flat-capped) buffer the size of 100-200km. First I tried this:

ic.buff<-gBuffer(ic, width=100000, capStyle="FLAT", byid=F)

Which caused my entire PC to crash. At first I thought it was my mistake, but then I tried a way smaller distance:

ic.buff<-gBuffer(ic, width=1, capStyle="FLAT", byid=F)

And this works fine. Up to width=1000 I have no problems but then either R or my entire PC crash.

I have tried using other functions (i.e. from the sf-package) and was met with similar issues. I am unclear as to what to do and why this happens... A buffer should only be a point in a specific distance from the line, what difference does it make how large this distance is?

1

There are 1 answers

0
Gmichael On

A simple workaround was to use a loop. Now all I would have to do is cut off the buffer to get flat caps. Could theoretically be done manually with extents but thinking there has to be a generalized solution.


ic.buff100<-gBuffer(ic, width=1000, capStyle="FLAT", joinStyle="MITRE", mitreLimit=1.0,  byid=F, quadsegs=1)

### loop over the buffer 99 times to create 99*1000 + 1000 m = 100 000 m = 100 km

for (i in 1:99){
  ic.buff100<-gBuffer(ic.buff100, width=1000, capStyle="FLAT", joinStyle="MITRE", mitreLimit=1.0,  byid=F, quadsegs=1)
}