Skip to content

Commit

Permalink
in-class lab
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshMerfeld committed Oct 15, 2024
1 parent 113075c commit 9a53e01
Show file tree
Hide file tree
Showing 30 changed files with 2,107 additions and 0 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified assignments/.DS_Store
Binary file not shown.
Binary file added assignments/in-class1/.DS_Store
Binary file not shown.
512 changes: 512 additions & 0 deletions assignments/in-class1/.Rhistory

Large diffs are not rendered by default.

83 changes: 83 additions & 0 deletions assignments/in-class1/cleaning.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# cleaning data for assignment 1

library(tidyterra)
library(tidyverse)
library(terra)

# load previous shapefile for projection
temp <- vect("/Users/Josh/Dropbox/KDIS/Classes/geospatialdataR/week4files/kgrid.shp")


# load geojson of provinces
do <- vect("/Users/Josh/Downloads/skorea-provinces-2018-geo.json")
do <- do |> filter(name_eng=="Seoul")
do <- do |> dplyr::select(province = name_eng)
do <- project(do, crs(temp))

# gu
gu <- vect("/Users/Josh/Downloads/skorea-municipalities-2018-geo.json")
gu <- gu |> select("name_eng")
gu <- project(gu, crs(temp))
gu <- intersect(gu, do)
gu <- aggregate(gu, "name_eng")
writeVector(gu, "data/seoulgu.shp", overwrite = TRUE)

# create grid
grid <- rast(do, res=100)
grid <- as.polygons(grid)
grid$id <- 1:nrow(grid)
grid <- intersect(grid, do)
grid <- aggregate(grid, "id")
# pop raster
pop <- rast("/Users/Josh/Downloads/kor_ppp_2020_constrained.tif")
pop <- project(pop, crs(temp))
# extract
grid$pop <- round(extract(pop["kor_ppp_2020_constrained"], grid, fun = "mean", na.rm = TRUE, method = "bilinear", ID = FALSE), 0)
writeVector(grid, "data/seoulgrid.shp", overwrite = TRUE)



# Load rail stations
transport <- vect("/Users/Josh/Downloads/south-korea-latest-free.shp/gis_osm_transport_free_1.shp")
transport <- transport |> filter(fclass=="railway_station")
transport <- project(transport, crs(temp))
transport <- intersect(transport, do)
transport <- project(transport, "EPSG:4326")
writeVector(transport, "data/seoulrail.shp", overwrite = TRUE)



# points of interest
points <- vect("/Users/Josh/Downloads/south-korea-latest-free.shp/gis_osm_pois_a_free_1.shp")
points <- points |> filter(fclass %in% c("hospital", "supermarket", "school"))
points$fclass[grep("초등학교", points$name)] <- "elementaryschool"
points$fclass[grep("중학교", points$name)] <- "middleschool"
points$fclass[grep("고등학교", points$name)] <- "highschool"
points <- points |> select(-c("osm_id", "name"))
points <- project(points, crs(temp))
points <- intersect(points, do)
points <- project(points, "EPSG:4326")
# get lon/lat
points$lon <- geom(points)[,"x"]
points$lat <- geom(points)[,"y"]
# remove geometry
points <- as_tibble(points)
write_csv(points, "data/seoulpoints.csv")



# water
water <- vect("/Users/Josh/Downloads/south-korea-latest-free.shp/gis_osm_water_a_free_1.shp")
water <- project(water, crs(temp))
water <- intersect(water, do)
water <- aggregate(water, "osm_id")
writeVector(water, "data/seoulwater.shp", overwrite = TRUE)

ggplot() +
geom_spatvector(data = water, fill = "blue") +
geom_spatvector(data = gu, fill = NA)





Binary file added assignments/in-class1/data/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions assignments/in-class1/data/seoulgrid.cpg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UTF-8
Binary file added assignments/in-class1/data/seoulgrid.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions assignments/in-class1/data/seoulgrid.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROJCS["Korea_2000_Korea_Unified_Coordinate_System",GEOGCS["GCS_Korea_2000",DATUM["D_Korea_2000",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",1000000.0],PARAMETER["False_Northing",2000000.0],PARAMETER["Central_Meridian",127.5],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",38.0],UNIT["Meter",1.0]]
Binary file added assignments/in-class1/data/seoulgrid.shp
Binary file not shown.
Binary file added assignments/in-class1/data/seoulgrid.shx
Binary file not shown.
1 change: 1 addition & 0 deletions assignments/in-class1/data/seoulgu.cpg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UTF-8
Binary file added assignments/in-class1/data/seoulgu.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions assignments/in-class1/data/seoulgu.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROJCS["Korea_2000_Korea_Unified_Coordinate_System",GEOGCS["GCS_Korea_2000",DATUM["D_Korea_2000",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",1000000.0],PARAMETER["False_Northing",2000000.0],PARAMETER["Central_Meridian",127.5],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",38.0],UNIT["Meter",1.0]]
Binary file added assignments/in-class1/data/seoulgu.shp
Binary file not shown.
Binary file added assignments/in-class1/data/seoulgu.shx
Binary file not shown.
1,460 changes: 1,460 additions & 0 deletions assignments/in-class1/data/seoulpoints.csv

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions assignments/in-class1/data/seoulrail.cpg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UTF-8
Binary file added assignments/in-class1/data/seoulrail.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions assignments/in-class1/data/seoulrail.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]
Binary file added assignments/in-class1/data/seoulrail.shp
Binary file not shown.
Binary file added assignments/in-class1/data/seoulrail.shx
Binary file not shown.
1 change: 1 addition & 0 deletions assignments/in-class1/data/seoulwater.cpg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UTF-8
Binary file added assignments/in-class1/data/seoulwater.dbf
Binary file not shown.
1 change: 1 addition & 0 deletions assignments/in-class1/data/seoulwater.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROJCS["Korea_2000_Korea_Unified_Coordinate_System",GEOGCS["GCS_Korea_2000",DATUM["D_Korea_2000",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",1000000.0],PARAMETER["False_Northing",2000000.0],PARAMETER["Central_Meridian",127.5],PARAMETER["Scale_Factor",0.9996],PARAMETER["Latitude_Of_Origin",38.0],UNIT["Meter",1.0]]
Binary file added assignments/in-class1/data/seoulwater.shp
Binary file not shown.
Binary file added assignments/in-class1/data/seoulwater.shx
Binary file not shown.
6 changes: 6 additions & 0 deletions assignments/in-class1/header.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

\definecolor{kdisgreen}{RGB}{0, 99, 52}
\definecolor{kdisplatinum}{RGB}{167, 169, 172}



Binary file added assignments/in-class1/inclasslab1.pdf
Binary file not shown.
38 changes: 38 additions & 0 deletions assignments/in-class1/inclasslab1.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: |
| In-class lab 1
subtitle: |
| Geospatial analysis in R
| KDI School Fall 2024
# Output type and options (no TOC and yes fig captions)
format:
pdf:
toc: false

# This includes latex arguments
header-includes:
- \input{header.tex}

---

You can find all of the data in the assignments/in-class1/data folder. The datasets are:

- seoulgrid.shp: a grid of 100m x 100m cells covering Seoul
- seoulgu.shp: the administrative districts (gu/구) of Seoul
- seoulrail.shp: the rail stations in Seoul
- seoulwater.shp: the water bodies in Seoul
- seoulpoints.csv: points of interest in Seoul

By the end of class, you need to turn in a raw markdown file AND the pdf output. Please make sure ALL STUDENTS' names are on the assignment. Here are your tasks for today:

- Let's start easy. The grid shapefile has a variable in it: estimated population in the grid cell (from [WorldPop](https://www.worldpop.org/)). Load the grid shapefile and plot the population distribution in Seoul. Please make the map look nice.
- You'll notice there are a lot of grid cells with missing values. Please write what you think might be going on there.
- Next, filter out any grid cells that are majority water. Plot the population distribution in Seoul again.
- Please write what you think the missing values are again.
- I forgot to put the Gu identifier into the grid cells. Please add that using the seoulgu.shp file.






0 comments on commit 9a53e01

Please sign in to comment.