1

I am trying out @tylermorganwall Rayshader R library. Some instructions are given here by tylermw8 to get elevation data from the USGS National Map.

I am interested in obtaining data around the Golden Gate Bridge. The data I download from from USGS National Map (n38w123) is, I believe, a one degree square tile which is 60 miles N/S and about 53 miles W/E. That's too much data for playing around with his rayshader library.

The bounding square of interest is:

(37.88, -122.56) (37.88, -122.41)

(37.77, -122.56) (37.77, -122.41)

How do I 'cut' this elevation data out of the large download from USGS? Is this where the library(sf) comes in handy?

2
  • The USGS national map page isn't working for me at the moment - is that because of the current US government shutdown?
    – Spacedman
    Commented Jan 15, 2019 at 10:52
  • How are you loading the data into R? If its a "raster" object then there's tools in the raster package to crop large rasters to small extents. Show some of your code to show what you've done so far.
    – Spacedman
    Commented Jan 15, 2019 at 10:53

1 Answer 1

1

Yes, it does look like the USGS National Map page is down. I think creating a simple feature dataframe and using that with raster::crop is what I was looking for.

library(raster)
library(sf)

# Bay area data: long_min = -123.0056, long_max = -121.99944, lat_min = 36.99944, lat_max = 38.00056
sf_bay_data = raster::raster("data/goldengate/n38w123/imgn38w123_13.img")

# Create Simple Feature Geometry (sfg) Polygon around GG Bridge
gg_sfg <- st_polygon(list(cbind(c(-122.56, -122.56, -122.41, -122.41, -122.56), c(37.88, 37.77, 37.77, 37.88, 37.88))))

# Add projection info by creating an sfc object
gg_sfc <- st_sfc(gg_sfg, crs = "+init=epsg:4326")

# Create simple feature dataframe
gg_sf <- st_sf(gg_sfc)

# Crop SF Bay data to zoom in around GG Bridge
gg_data <- raster::crop(sf_bay_data, gg_sf)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.