##Title: DWVGIS - 7. Kauai Island OSM.R
#Author: Jack Reilly
#Purpose: Draw Kauai Island
#Requires: no external data; must install osmdata within script

library(osmdata)
library(sf)
library(dplyr)
library(ggplot2)


kauaibb<-getbb("Kauai")

is_coast <- kauaibb %>%
  opq()%>%
  add_osm_feature(key = "natural", value="coastline") %>%
  osmdata_sf()

is_water <- kauaibb%>%
  opq()%>%
  add_osm_feature(key = "natural", value="water") %>%
  osmdata_sf()

is_big_streets <- kauaibb %>%
  opq() %>%
  add_osm_feature(key = "highway",
                  value = c("motorway", "trunk", "primary", "motorway_link", "primary_link", "trunk_link")) %>%
  osmdata_sf()

is_med_streets <- kauaibb%>%
  opq()%>%
  add_osm_feature(key = "highway", 
                  value = c("secondary", "tertiary", "secondary_link", "tertiary_link")) %>%
  osmdata_sf()


is_small_streets <- kauaibb%>%
  opq()%>%
  add_osm_feature(key = "highway", 
                  value = c("residential", "living_street",
                            "unclassified",
                            "service", "footway"
                  )) %>%
  osmdata_sf()


is_river <- kauaibb%>%
  opq()%>%
  add_osm_feature(key = "waterway", value = "river") %>%
  osmdata_sf()

is_railway <- kauaibb %>%
  opq()%>%
  add_osm_feature(key = "railway", value="rail") %>%
  osmdata_sf()


ggplot() +
  geom_sf(data = is_coast$osm_lines,
          inherit.aes = FALSE,
          color = "green4",
          size = 1)


ggplot() +
  geom_sf(data = is_coast$osm_lines,
          inherit.aes = FALSE,
          color = "steelblue",
          size = .3) +
  geom_sf(data = is_water$osm_polygons,
          inherit.aes = FALSE,
          color = "steelblue",
          size = .15,
          fill = "white") +
  geom_sf(data = is_railway$osm_lines,
          inherit.aes = FALSE,
          color = "red",
          size = .2,
          linetype="dotdash",
          alpha = .9) +
  geom_sf(data = is_med_streets$osm_lines,
          inherit.aes = FALSE,
          color = "black",
          size = .3,
          alpha = .5) +
  geom_sf(data = is_small_streets$osm_lines,
          inherit.aes = FALSE,
          color = "#666666",
          size = .2,
          alpha = .3) +
  geom_sf(data = is_big_streets$osm_lines,
          inherit.aes = FALSE,
          color = "black",
          size = .5,
          alpha = .6) +
  coord_sf(xlim = kauaibb[1,], 
           ylim = kauaibb[2,],
           expand = FALSE) +
  theme_void() + # get rid of background color, grid lines, etc.
  theme(plot.title = element_text(size = 20, family = "lato", face="bold", hjust=.5),
        plot.subtitle = element_text(family = "lato", size = 8, hjust=.5, margin=margin(2, 0, 5, 0))) +
  labs(title = "KAUA'I", subtitle = "HAWAI'I")

setwd("~/desktop/working/dwv26")
ggsave(file="kauai.pdf", units="in", width=6, height=7)