i would like to create a buffer around a line-shapefile with wgs84 coordinates.
I prepared a shapefile with a single line segment and Datum: D_WGS_1984. After that, i loaded the .shp into R using the 'readOGR' command.
After that i tried the gBuffer method out of the rgeos-package for computing the buffer:
gBuffer(l2, width=1.0, quadsegs=5, capStyle="ROUND", joinStyle="ROUND", mitreLimit=0.01))
Warning:
In gBuffer(l2, width = 1, quadsegs = 5, capStyle = "ROUND", joinStyle = "ROUND", :
Spatial object is not projected; GEOS expects planar coordinates
Obviously the command has a problem with the coordinates. I tried some approaches, but didn't find a solution.
Another example i found for a buffer around points was the following, but i'm not sure how to use it in my case: http://r-sig-geo.2731867.n2.nabble.com/compute-buffer-from-point-shapefile-to-have-shapefile-td4574666.html
Any ideas?
Best regards, Stefan
//update:
Reduced to the relevant part, here is the code:
require("rgeos")
require("rgdal")
l2=readOGR(dsn="C:/Maps", layer="osm_ms")
proj4string(l2) <- CRS("+proj=longlat")
l2.trans <- spTransform(l2, CRS("+proj=longlat"))
summary(l2.trans)
> Object of class SpatialLinesDataFrame
> Coordinates:
> min max
> x 7.478942 7.772171
> y 51.840318 52.058856
> Is projected: FALSE
> proj4string : [+proj=longlat +ellps=WGS84]
> Data attributes:
plot(l2.trans)
plot(gBuffer(l2.trans, width=1.0, quadsegs=5, capStyle="ROUND", joinStyle="ROUND", mitreLimit=0.01))
Probably the line:
Is projected: FALSE is the reason for the problem, but i'm not sure how to use the spTranform and how to find the correct projection.