2

I've read a similar post but couldn't apply the solution. Namely, I have a polygon of France's boundary and want to buffer it as follows:

fra_bound <- readOGR(dsn = "data/FRA_adm", layer = "FRA_adm0")
fra_buf <- gBuffer(fra_bound, width = 1000, quadsegs = 10)

The problem is this executes too long and throws: Error in gBuffer(fra_bound, width = 1000, quadsegs = 10) : std::bad_alloc

The projection of this shape is:

proj4string(fra_bound)

[1] "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"

What am I doing wrong? Maybe I should use another way but I need it in R.

1
  • where is the data from? can you provide a link such that we can attempt to reproduce the error?
    – jbukoski
    Commented Jul 15, 2017 at 14:49

1 Answer 1

10

Your data is in Lat-long (EPSG:4326 by the look of it) so you are making a buffer of 1000 degrees which is going to wrap round the earth about three times!

You need to transform your spatial object to a different coordinate system based on metres (or km, or whatever units your 1000 is) using spTransform. I suspect for France there's a reasonable UTM zone with corresponding EPSG code. That will give you metres for a 1km zone with width=1000.

Note that for a whole country like France the outline may be very detailed and you might want to use gSimplify first to get a simpler outline.

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.