-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathgis-learning-2.R
49 lines (37 loc) · 1.07 KB
/
gis-learning-2.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
# load libraries
library(sf)
library(ggplot2)
library(dplyr)
# import with sf
ward86 <- read_sf("gis-visualization/spring-2019/data/ward1986.shp")
water <- read_sf("gis-visualization/spring-2019/data/Waterways.geojson")
# project
st_crs(ward86)
st_buffer(ward86) # does not work with unprojected data!!
st_crs(water)
ward86 <- st_transform(ward86, 32616)
st_crs(ward86)
water <- st_transform(water, 32616)
st_crs(water)
ggplot() +
geom_sf(data = ward86) +
geom_sf(data = water, col = "blue")
water <- filter(water, name != "LAKE MICHIGAN")
# calculate centroids
# plot with ggplot2
ggplot() +
geom_sf(data = ward86)
centroids <- st_centroid(ward86)
centroids_buffer <- st_buffer(centroids, 1000)
st_crs(centroids)
ggplot() +
geom_sf(data = ward86) +
geom_sf(data = centroids_buffer) +
geom_sf(data = centroids)
# spatial intersection (important!!)
intersects <- st_intersects(ward86, water)
water_wards <- filter(ward86, lengths(intersects) > 0)
ggplot() +
geom_sf(data = ward86) +
geom_sf(data = water_wards, fill = "pink") +
geom_sf(data = water, col = "blue")