2
votes

Trying to find the minimum elevation within 10km of a certain latitude and longitude using R.

So far I have

dem <- getData("SRTM", lat=42.90, lon=-78.85, path = datadir)
plot(dem)

I know I need to create spatial points and eventually buffer/extract the information.

When I try:

buffdem <- buffer(dem, width=10000)

It does not work because I don't have any points.

I tried

dem <- getData("SRTM", lat=42.90, lon=-78.85, path = datadir)
coords <- data.frame(
  x = rnorm(100),
  y = rnorm(100)
)
coordinates(dem)

spdf = SpatialPointsDataFrame(coords, dem)

I get the following error:

Error in validObject(.Object) : invalid class “SpatialPointsDataFrame” object: invalid object for slot "data" in class "SpatialPointsDataFrame": got class "RasterLayer", should be or extend class "data.frame"

1
A reproducible example, please. - harre
You don't necessarily need to buffer the points. Do a focal min of the raster and then use extract - see ?focal - jbaums
"reproducible" means you provide us with a sample data set we can use to demonstrate/test solutions: tinyurl.com/reproducible-000 - Ben Bolker
I see, I will try to the focal min. Thanks! - user6754289
I would post an example but that ftp is painfully slow for me. I'll see if I can find a smaller tile. - jbaums

1 Answers

2
votes

I think this accomplishes what you need:

library(raster)
#elevation <- getData("SRTM", lat=42.90, lon=-78.85)
#poi <- cbind(lon=-78.85, lat=42.90)

using a smaller example data set for quicker download:

elevation <- getData('alt', country='CHE')
poi <- cbind(8.13, 46.47)

e <- extract(elevation, poi, buffer=10000)

sapply(e, min, na.rm=TRUE)

By the way, this is a duplicate of this and this question.