0

For a GIS class I'm taking I'm trying to create some spatial statistics for a route through a city. I need to create a buffer of 100m around the route. It looks like i can use gbuffer from rgdal but that requires that the data is prjected, which it's currently not. It sounds like i can project with spTransform but I'm not certain which method from rgdal to use.

Is there an obvious answer or a good resource for figuring that out?

Summary of the Spatial Lines Dataframe object I'm working with below.

Object of class SpatialLinesDataFrame
Coordinates:
   min       max
x -0.13590  0.033067
y 51.47773 51.543564
Is projected: FALSE 
proj4string :
[+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0]

I'm currently trying this line but the object it returns still is not projected...

Projected_Path = sp::spTransform(path, "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0" )
0

1 Answer 1

3

When you do:

 Projected_Path = sp::spTransform(path, "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0" )

the coordinates of path get changed from the coordinate system they are in to the coordinates described by the second argument to spTransform. In this case you've given the same string as the coordinates that path is in, so nothing much has happened. The points are still in lat-long degrees.

You need a coordinate system that is a projection of lat-long to a flat plane. There are thousands. Some work only in small areas, some are global but cause massive distortion, like at the poles.

If you are working in a country, there's usually a country-wide planar coordinate system. In the UK that would be the Ordnance Survey Grid System, which you get with "+init=epsg:27700" as a coordinate reference string. Projecting lat-long in the UK to that coordinate system gets you a grid system in metres which you can then buffer by metres.

If you are not in the UK, you can use one of the "UTM" coordinate systems relevant to your longitude. You can look these up https://en.wikipedia.org/wiki/Universal_Transverse_Mercator_coordinate_system and get the EPSG code which you can use in "+init=epsg:XXXXX". Again you get metres.

And then you can use gBuffer which comes from the rgeos package, not rgdal.

Also you might want to look at the sf package which provides a new set of objects for spatial data and has all the buffering and transform and geometry operations included in one package.

3
  • Cool that all makes sense. I actually realized we had done it in a practical so i borrowed BNG = "+init=epsg:27700" and that seemed to work out. Dec 7, 2018 at 12:28
  • the reason I used sp instead of sf was that I need (i think) to use rgeos::gBuffer to create a buffer around the path and the gBuffer documentation specifies an sp opject. Is there a better way to do that? I tried initially with an sf object and got an error but that could have been a projection problem not a problem with the type of object i was passing gBuffer Dec 7, 2018 at 12:30
  • sf has st_buffer - the only reason I use sp now is when another package only takes sp objects.
    – Spacedman
    Dec 7, 2018 at 13:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.