How to calculate linear buffer using SpatialLinesDataFrame

I would like to create a buffer around the shape-shape file with the wgs84 coordinates.

I prepared a shapefile with one line segment and Datum: D_WGS_1984. After that I loaded .shp into R using the "readOGR" command.

After that, I tried the gBuffer method from the rgeos package to calculate 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 team has a problem with the coordinates. I tried some approaches but could not find a solution.

Another example I found for a buffer around dots 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?

Regards, Stefan

// update:

Reduced to the corresponding 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:

Projected: FALSE is causing the problem, but I'm not sure how to use spTranform and how to find the correct projection.

+4
source share
2 answers

Think about the size of your buffer 1.0 units. That would be, in lats, 1.0 degrees. This does not make much sense, since a 1-degree NS is different from a 1st degree EW. GEOS is trying to stop you from doing something that, in his opinion, is a little strange.

That way, you can trick him by assigning him almost any programmed CRS line of coordinates, making a buffer, and then assigning it back. Base numbers will not change. For example, if you do:

  proj4string(l2) = CRS("+init=epsg:27700") 

you are lying to the system that the numbers are UK network meters. Then you make a buffer, and you give units that, as you know, are really degrees. GEOS performs calculations using numbers, assuming the points are on a grid (not a sphere). Then you just install CRS back. Numbers do not change.

Actually, apparently, the correct ESPG code exists for the projected lat-long, so ignore the previous line and do:

  proj4string(l2) = CRS("+init=epsg:3395") 

The EPSG code database is here: http://www.epsg-registry.org/ - pay attention to the "area" in detail for epsg: 3395 is "very small scale."

If you really need a buffer in meters, you need to convert it to a metric projection (for work in the UK I always use epsg: 27700) using spTransform, which changes the base numbers.

+7
source

The answer to your question is the error you are getting. Your data should be projected, not into the latlon system. Take a look at spTransform from the rgdal package for projection.

+1
source

Source: https://habr.com/ru/post/1401780/


All Articles