0
votes

I am currently trying to create (100m) buffer around points in R. I have found two very usefull answers, but I still have problems. Here the answers I found: Buffer (geo)spatial points in R with gbuffer Create buffer and count points in R

My problem is that when I create my buffer, I only have one big buffer.

ANFR_IDF is a dataframe. The column "ID" is a unique ID, the column "coordonnees" the coordinates.

ANFR_IDF$lat=as.numeric(gsub(",.*$", "", ANFR_IDF$coordonnees))
ANFR_IDF$lon=as.numeric(gsub(".*, ", "", ANFR_IDF$coordonnees))
coordinates( ANFR_IDF ) <- c( "lon", "lat" )
CRS=CRS("+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0")
proj4string(ANFR_IDF)=CRS

ANFR_IDF <- spTransform(ANFR_IDF,CRS)
test2=gBuffer( ANFR_IDF, width=100,id=ANFR_IDF$ID, byid=TRUE )

Any idea of what can be the problem? Many thanks!

1

1 Answers

2
votes

It looks like you have a geographic coordinate system with units in decimal degrees so when you provide 100 for the width parameter, it creates a 100 decimal degree buffer (one huge buffer!). Try projecting first

library(sp)
ANFR_IDF_prj <- spTransform(ANFR_IDF, crs([your preferred projection]))
test2=gBuffer( ANFR_IDF_prj, width=100,id=ANFR_IDF_prj$ID, byid=TRUE )