0

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?

Gmichael
  • 526
  • 1
  • 5
  • 16
  • The buffer is more than a parallel to a line because it has to make up a polygon: it thus needs caps (flat/rounded...) and mitres (with a specified 'spikyness') where the line bends. Where buffer areas or mitres meet (e.g. after sharp turns or along ragged parts), they have to be merged, and holes arise and disappear, depending on buffer distance, where the line loops. Long story short: the amount of clean-up for a neat buffer polygon increases with buffering distance - and might exceed your machine's capacity at a given point. –  May 03 '22 at 07:52
  • On a practical note: if you need a 100km buffer anyway, it might help to `st_simplify()` your line *ic*, i. e. remove vertices (bends) which go beyond the resolution needed for an illustrative display of the map element (the iron curtain buffer). –  May 03 '22 at 08:12
  • Yes, this would be possible for simple plotting etc. but st_simplify is from sf which does finefor plotting but not necessarily for measuring things (another part of my project non-pertinent to this question). – Gmichael May 03 '22 at 08:21
  • 1
    I see your point. Border length could still be calculated for the initial line (which in turn will be an approximation, depending on provenience and resolution of your geodata). However, I find it difficult to see how a fixed-distance buffer, even if precise to the cm², would be more than a very coarse demarkation of any border-dependent physical/political/economical phenomenon in the real world. My 2c ;-) –  May 03 '22 at 08:42

1 Answers1

0

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)
}
Gmichael
  • 526
  • 1
  • 5
  • 16