##Title: DWVGIS 2. DMAs.R
#Author: Jack Reilly
#Purpose: Illustrate loading an internal shape file (luxembourg) and and an external shape file (dma_export.shp)
#Requires: the dma_export folder (dma_export.shp with its .shx, .dbf, .prj and .cpg files), in ~/desktop/working/dwv26;
#  download it from the Course Drive

library(sf)
library(terra)
library(tmap)
library(tidyverse)
library(RColorBrewer)
library(maptiles)
library(cartogram)

#Set the working directory
setwd("~/desktop/working/dwv26")

#Identify the path to the internal luxembourg data
filename <- system.file("ex/lux.shp", package="terra")
filename

#Load and draw the data
lux <- vect(filename)
class(lux)
plot(lux)

#Read and plot dma_export.shp
dmas <- st_read("dma_export/dma_export.shp")
plot(dmas)

#Show the filetypes supported by st_read
st_drivers()

#Keep just the lower 48: crop to a box around them and plot the outlines
lower48 <- st_crop(dmas, xmin = -125, xmax = -66, ymin = 24, ymax = 50)
plot(st_geometry(lower48))
