Perform GIS functions on a temporary, projected version of a spatial object

gprojected(shp, fun, crs = crs_select_aeq(shp), ...)

Arguments

shp

A spatial object with a geographic (WGS84) coordinate system

fun

A function to perform on the projected object (e.g. gLength))

crs

An optional coordinate reference system (if not provided it is set automatically by crs_select_aeq).

...

Arguments to pass to fun, e.g. byid = TRUE if the function is gLength))

Examples

# Find the length of routes that are in lat/long format data(routes_fast) rlength = gprojected(routes_fast, fun = rgeos::gLength, byid = TRUE)
#> Transforming to CRS +proj=aeqd +lat_0=53.81895189 +lon_0=-1.52748741 +x_0=0 +y_0=0 +ellps=WGS84
#> Running function on a temporary projected version of the Spatial object using the CRS: +proj=aeqd +lat_0=53.81895189 +lon_0=-1.52748741 +x_0=0 +y_0=0 +ellps=WGS84
plot(routes_fast$length, rlength)
cor(routes_fast$length, rlength)
#> [1] NA
rbuf = gprojected(routes_fast, rgeos::gBuffer, byid = TRUE, width = 100)
#> Transforming to CRS +proj=aeqd +lat_0=53.81895189 +lon_0=-1.52748741 +x_0=0 +y_0=0 +ellps=WGS84
#> Running function on a temporary projected version of the Spatial object using the CRS: +proj=aeqd +lat_0=53.81895189 +lon_0=-1.52748741 +x_0=0 +y_0=0 +ellps=WGS84
plot(rbuf)
raster::crs(rbuf)
#> CRS arguments: #> +init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 #> +towgs84=0,0,0
plot(routes_fast, col = "green", add = TRUE)