-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprepbasemap.R
66 lines (53 loc) · 2.98 KB
/
prepbasemap.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
### this script takes a giant .gdb file (a standard GIS archive format) of PLSS tracts of many states and filters down to a specific type of tract data for a specific area.
### it uses R's sf, which is impressive and easy and made the impossible possible
#setwd("~/projecto/research_projects/hacking/yofarmo/")
#install.packages("devtools")
#devtools::install_github("tidyverse/ggplot2")
#install.packages("sf")
library("sf")
library("dplyr")
library("rnaturalearth")
library("rnaturalearthdata")
library("ggplot2")
theme_set(theme_bw())
#library(data.table)
# https://gis.stackexchange.com/questions/184013/read-a-table-from-an-esri-file-geodatabase-gdb-using-r
#sf::st_layers(dsn = "data/CadRef_v10.gdb")
#CAPLSSmetadata <- sf::st_read(dsn = "data/CadRef_v10.gdb", layer = "MetadataGlance")
#CAPLSStownship <- sf::st_read(dsn = "data/CadRef_v10.gdb", layer = "PLSSTownship")
CAPLSSsection <- sf::st_read(dsn = "data/CadRef_v10.gdb", layer = "PLSSFirstDivision")
#CAPLSSintrsct <- sf::st_read(dsn = "data/CadRef_v10.gdb", layer = "PLSSIntersected")
#CAPLSSpoints <- sf::st_read(dsn = "data/CadRef_v10.gdb", layer = "PLSSPoint")
#setnames( DavisPLSS2, c("POINTID", "XCOORD", "YCOORD", "SHAPE"), c("ID", "X", "Y", "geometry"))
#DavisPLSSsect <- subset(CAPLSSsection, startsWith(FRSTDIVID,"CA210080N0020E0"))
### Yolo county stretches roughly from 7-11N and 2W to 3E
DavisPLSSsect <- subset(CAPLSSsection, str_detect(FRSTDIVID,"CA210(06|07|08|09|10|11|12)0N00[1234]0[EW]0"))
# finer sections can't resolve from county data, so use coardser section/firstdivision data instead
#DavisPLSSqrtsect <- subset(CAPLSSintrsct, startsWith(SECDIVID,"CA210080N0020E0"))
#DavisPLSSqrtsect$HiUmHello = 'sqzz?'
#DavisPLSSqrtsect$Description = '<a href="https://google.com">a link</a><br/><a href="https://google.com">a nother link</a>'
# exploratory plotting
if (FALSE) {
# sf and shape files
# plotting cribbed from https://www.r-spatial.org/r/2018/10/25/ggplot2-sf-2.html
world <- ne_countries(scale = "medium", returnclass = "sf")
# township (spatial scale of ~ 6 mile sq)
ggplot(data = world) +
geom_sf() +
geom_sf(data = st_as_sf( vessel ), fill = NA) +
coord_sf(xlim = c(-121.82, -121.68), ylim = c(38.48, 38.59), expand = FALSE)
# section (spatial scale of ~1 mile sq)
ggplot(data = world) +
geom_sf() +
geom_sf(data = st_as_sf( DavisPLSSsect ), fill = NA) +
coord_sf(xlim = c(-121.82, -121.68), ylim = c(38.48, 38.59), expand = FALSE)
# quartersection (spatial scale of <1 mile sq. This is the finest scale, and the scale of reporting)
ggplot(data = world) +
geom_sf() +
geom_sf(data = st_as_sf( DavisPLSSqrtsect ), fill = NA) +
coord_sf(xlim = c(-121.82, -121.68), ylim = c(38.48, 38.59), expand = FALSE)
}
### write to kml
#system("touch data/countyPrepped.kml") # kludge
#write_sf(DavisPLSSqrtsect, "data/countyPrepped.kml", driver = "kml", delete_dsn = TRUE)
write_sf(DavisPLSSsect, "data/countyPrepped.gpkg", delete_dsn = TRUE)