Compare commits

...

10 Commits

Author SHA1 Message Date
1508919f76 changed README 2023-10-18 13:57:21 -05:00
28041df425 ignore figures 2023-10-18 13:53:37 -05:00
c8c5a086a6 excluded figures from git repo to reduce repo size 2023-10-18 13:51:01 -05:00
755089821c changed political boundary data
added a way to select state in 03_make_figures.R
2023-10-18 13:42:54 -05:00
17205a5c19 added jpeg export
commented out tiff and jpeg
changed dimensions to 8X10
2023-10-18 11:31:09 -05:00
214ff525cd changed extent
added political layer under rivers
changed colors of background
2023-10-18 11:17:55 -05:00
4e4576d93d changed spacing/formatting of scripts 2023-10-16 16:59:19 -05:00
4b33f2d71a edited figure script 2023-10-16 16:54:10 -05:00
529d3ae923 edited figure script 2023-10-16 16:53:19 -05:00
9cf982c483 added layers variable to 2nd script 2023-10-16 16:46:49 -05:00
10 changed files with 84 additions and 41 deletions

2
.gitignore vendored
View File

@ -4,3 +4,5 @@
.Ruserdata
data/*
figures/*

View File

@ -30,7 +30,6 @@ extent <- list(longitude_max = max(extent$longitude),
latitude_max = max(extent$latitude),
latitude_min = min(extent$latitude))
# get watershed areas
extent_huc <- get_huc(AOI = extent_poly, buffer = 0, type = "huc04")

View File

@ -1,4 +1,5 @@
# load libraries
library(nhdplusTools)
library(sf)
# reload extent data so you don't need to run the download data script again
@ -26,13 +27,18 @@ extent <- list(longitude_max = max(extent$longitude),
# load and crop hydrologic data
data <- list(NULL)
sf_use_s2(FALSE)
layers <- c("NHDArea",
"NHDFlowline",
"NHDWaterbody",
"NHDPlusLandSea")
for (layer in layers){
data[[layer]] <- st_crop(st_read(paste0(nhdplusTools_data_dir(),"/data.gpkg"), layer = layer), y = extent_bbox)
}
# load political boundaries
political <- list(NULL)
political_boundaries <- list.files(path = paste0(data_dir, "/political_boundaries"))
for (boundary in political_boundaries) {
political[[boundary]] <- st_read(paste0(data_dir, "/political_boundaries/", boundary))
}
political <- st_crop(
st_transform(
st_read(
paste0(data_dir, "/political_boundaries/bound_p/boundaries_p_2021_v3.shp")),
crs=crs),
y = extent_bbox)

View File

@ -7,21 +7,32 @@ ifelse(!dir.exists(file.path(getwd(), figure_dir)), dir.create(file.path(getwd()
# set colors
colors <- list(darkblue = "#062e57",
lightblue = "#b1dcf3")
lightblue = "#b1dcf3",
lightgrey = "#6D6D6D")
# set dimensions of figures
width <- 8.5
height <- 11
width <- 8
height <- 10
units <- "in"
res <- 600
margin <- 0
# set state to highlight
state <- c("Wisconsin")
# plot map
plot_map <- function () {
plot(sf::st_geometry(extent_poly),
col = colors$lightblue,
border = NA)
plot(sf::st_geometry(political$geometry),
col = colors$lightgrey,
border = NA,
add = TRUE)
plot(sf::st_geometry(political[political$NAME_En %in% state, ]),
col = colors$darkblue,
border = "black")
border = NA,
add = TRUE)
plot(sf::st_geometry(data$NHDWaterbody),
col = colors$lightblue,
border = NA,
@ -35,19 +46,35 @@ plot(sf::st_geometry(data$NHDFlowline),
lwd = data$NHDFlowline$TotDASqKM^0.3204*0.0446,
border = NA,
add = TRUE)
plot(sf::st_geometry(extent_poly),
col = NA,
border = "black",
lwd = 1,
add = TRUE)
}
# save figure
tiff(filename = paste0(figure_dir,"/map.tiff"),
width = width,
height = height,
units = units,
res = res,
compression = "lzw")
par(mai=c(margin, margin, margin, margin))
par(mar=c(1,1,1,1))
plot_map()
dev.off()
# tiff(filename = paste0(figure_dir,"/map.tiff"),
# width = width,
# height = height,
# units = units,
# res = res,
# compression = "lzw")
# par(mai=c(margin, margin, margin, margin))
# par(mar=c(1,1,1,1))
# plot_map()
# dev.off()
#
# jpeg(filename = paste0(figure_dir,"/map.jpg"),
# width = width,
# height = height,
# units = units,
# res = res,
# quality = 93)
# par(mai=c(margin, margin, margin, margin))
# par(mar=c(1,1,1,1))
# plot_map()
# dev.off()
png(filename = paste0(figure_dir, "/map.png"),
width = width,

View File

@ -6,10 +6,10 @@ Downloads USGS data for a given location and makes a pretty map of the rivers. T
1. Clone the repository
2. Edit the extent of the map you want to produce in `extent.csv`. Include lat/long coordinates of two opposite corners (i.e. top-left and bottom-right).
3. Run the scripts:
- `01_download_data.R` - This will take the longest. The whole of Wisconsin downloads ~12GB of data
- `02_process_data.R`
- `03_make_figures.R`
- `01_download_data.R` - This will take the longest. The whole of Wisconsin downloads ~12GB of data. It downloads the data to a `data` directory in the repo
- `02_process_data.R` - This loads and processes the data. After the initial run downloading the data for a given extent, you can start with this script.
- `03_make_figures.R` - This generates figures in a `figures` directory in the repo.
## Example figure
![example figure](figures/map.png)
![example figure](example.png)

BIN
example.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 MiB

View File

@ -1,3 +1,3 @@
latitude,longitude
47.33402,-93.10419
42.43754,-86.832
47.73208,-93.55154
41.49273,-86.64896

1 latitude longitude
2 47.33402 47.73208 -93.10419 -93.55154
3 42.43754 41.49273 -86.832 -86.64896

3
extent_olympic.csv Normal file
View File

@ -0,0 +1,3 @@
latitude,longitude
48.50775,-124.91972
46.88398,-122.07015
1 latitude longitude
2 48.50775 -124.91972
3 46.88398 -122.07015

3
extent_wa.csv Normal file
View File

@ -0,0 +1,3 @@
latitude,longitude
49.17657,-125.43151
45.23644,-115.81455
1 latitude longitude
2 49.17657 -125.43151
3 45.23644 -115.81455

3
extent_wi.csv Normal file
View File

@ -0,0 +1,3 @@
latitude,longitude
47.73208,-93.55154
41.49273,-86.64896
1 latitude longitude
2 47.73208 -93.55154
3 41.49273 -86.64896