I would like to find all of the rivers within a certain bounding box. My final goal is subset them by name so I can choose which rivers to plot, but first I must know the names of the features in my extent! I'd prefer to use ggplot/tidyverse tools.
For example:
# Download river shapefile here: https://www.weather.gov/gis/Rivers
# Import river data as SF
st_read(dsn = 'rv16my07/', layer = 'rv16my07') %>%
{. ->> my_rivers}
# Add a common CRS to the river dataset
st_crs(my_rivers) <- CRS('+proj=longlat')
# Set x and y limits for the plot
ylims <- c(30.2, 31.4)
xlims <- c(-88.3, -87)
# Create sf for this bounding box
bounding.box <- st_as_sf(data.frame(long = xlims, lat = ylims), coords = c("lat", "long"), crs = CRS('+proj=longlat'))
# Try to find features that intersect
intersecting.rivers <- st_intersection(my_rivers, bounding.box)
However, the intersection is empty. What am I doing wring here?
After I find the rivers within that bounding box, I'd like to do something like this:
unqiue(intersecting.rivers$PNAME)
river.subsets <- subset(intersecting.rivers, PNAME %in% c("MOBILE R", "ALABAMA R"))
But first I need to know the names of the features within the bounding box.
