Search code examples
ramazon-web-servicesgeospatialelevatr

How to access multiple elevation points at the same time with get_elev_point


I hava another geodata question. I am trying to access the elevation data for specific points with the get_elev_point ()

I have about 160 points that I would like to get the elevation data for, so I would like to not do it one by one but I do not know how to retrieve them all at once.

I have made a data.frame of all my points where the first column x is longitude and the second column y is latitude and these are the only data in the data.frame.

I am using the elevatr package

Reproducible example:

location_1 <- data.frame (x=-7.37,y=5.775)

location_1_elev <-get_elev_point(locations = location_1, units="meters", prj = ll_prj, src = "aws")

When I do this, everything is fine and I get an elevation point back, but when I try to access several points at the same time I run into errors.

I took the earthquake data from R and transformed it into a data.frame that has only the longitude and latitiude. Then tried to access the elevation points via get_elev_points and got the error message:

data(quakes)

head(quakes)

locations <- data.frame(x = c(quakes$long, 1000), y = c(quakes$lat, 1000))

quakes_elev <-get_elev_point(locations = locations, units="meters", prj = ll_prj, src = "aws")

Error: API did not return tif

Do you have any tips how to make this happen, to be able to access multiple elevation points?

Thank you! ps.: Sorry for my clumsy asking, I am only learning now.


Solution

  • It's likely the error is caused because the points are in the sea so there is no land elevation tif file to get an elevation from. For example, here is an example that tries to find the elevation of a point in the sea and then a point on land.

        library(elevatr)
        ll_prj <- "EPSG:4326"
                
        sea <- data.frame(x=181.62, y=-20.42)
        # This errors
        sea_elev <- get_elev_point(locations = sea, units='meters', prj=ll_prj, src='aws')
        # Error: This url: https://s3.amazonaws.com/elevation-tiles-prod/geotiff/5/32/18.tif did not return a tif
        
        land <- data.frame(x=-71.3036, y=44.2700)
        # This works
        land_elev <- get_elev_point(locations = land, units='meters', prj=ll_prj, src='aws')
        land_elev$elevation
        # [1] 1478
    

    Using the epqs option returns NA without error so I suppose you could replace that with 0 if you want to use sea level as the elevation.