vathymut - 2 months ago 23

R Question

I'm trying to buffer the points in my dataset with a radius of 100km. I'm using the function

`gBuffer`

`rgeos`

`head( sampledf )`

# postalcode lat lon city province

#1 A0A0A0 47.05564 -53.20198 Gander NL

#4 A0A1C0 47.31741 -52.81218 St. John's NL

coordinates( sampledf ) <- c( "lon", "lat" )

proj4string( sampledf ) <- CRS( "+proj=longlat +datum=WGS84" )

distInMeters <- 1000

pc100km <- gBuffer( sampledf, width=100*distInMeters, byid=TRUE )

I get the following warning:

In gBuffer(sampledf, width = 100 * distInMeters, byid = TRUE) :

Spatial object is not projected; GEOS expects planar coordinates

From what I understand/read, I need to change the Coordinate Reference System (CRS),

in particular the projection, of the dataset from 'geographic' to 'projected'.

I'm not sure sure how to change this. These are all Canadian addresses, I might add.

So NAD83 seems to me a natural projection to choose but I may be wrong.

Any/all help would be greatly appreciated.

Answer

With a little bit more digging, it turns out that using a 'projected' coordinates reference system is as simple as

```
# To get Statscan CRS, see here:
# http://spatialreference.org/ref/epsg/3347/
pc <- spTransform( sampledf, CRS( "+init=epsg:3347" ) )
```

EPSG3347, used by STATSCAN (adequate for Canadian addresses), uses a lambert conformal conic projection. Note that NAD83 is inappropriate: it is a 'geographic', rather than a 'projected' CRS. To buffer the points

```
pc100km <- gBuffer( pc, width=100*distm, byid=TRUE )
# Add data, and write to shapefile
pc100km <- SpatialPolygonsDataFrame( pc100km, data=pc100km@data )
writeOGR( pc100km, "pc100km", "pc100km", driver="ESRI Shapefile" )
```