show additional area around feature, get_elev_raster() (from elevatr)

223 Views Asked by At

Following the answer to this question "Create topographic map in R" I would like to expand the bounding box to show additional area around the feature. The documentation mentions the "expand" parameter but I'm not sure how it can be applied and my google searches have not returned code examples that I have been able to use successfully.

I am testing on a dataframe with just one set of coordinates at present (Adam's peak, from Wikipedia), that looks like this:

dataframe image

The code is the same as here, as below, except for the first line "# Generate a data frame of lat/long coordinates"

library(elevatr)
library(raster)

#input dataframe
ex.df <- mtSlice

# Specify projection.
prj_dd <- "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"

# Use elevatr package to get elevation data for each point.
elev <- get_elev_raster(ex.df, prj = prj_dd, z = 10, clip = "bbox")

raster::contour(elev)

Would anyone be able to explain how to expand to show more area around the feature?

1

There are 1 best solutions below

3
On

The expand argument on get_elev_raster will expand the bounding box in the units of the CRS in your input locations. In this case that will be decimal degrees. So, to get an additional 1 degree on your bounding box:

elev_plus_one_deg <- get_elev_raster(ex.df, prj = prj_dd, z = 10, clip = "bbox", expand = 1)

note: It should be doing about an additional one degree, but on closer inspection it doesn't appear to be. I need to dig into that!