XY 숫자로 구성된
Creating a map based on address or xy coordinates - convert to lat and long?
Elevation data in R, Ivan Lizarazo, 21.09.2020
<- data.frame( city = "Trinbak", lon = 556305, lat = 6306381 )
df
library(sf)
library(leaflet)
<- st_as_sf( df, coords = c("lon", "lat") ) %>%
df.sf st_set_crs( 2198 ) %>% #set coordinate system used
st_transform( 4326 ) #transform coordinates to WGS84 coordinates
leaflet() %>% addTiles() %>% addMarkers( data = df.sf )
GIS DEVELOPER 대한민국 최신 행정구역(SHP) 다운로드 웹사이트에서 침수피해가 이슈가 된 강남구와 인접한 서초구 두 구를 뽑아 시각화해보자.
강남역이 위치한 서초구와 강남구 두 구에 대한 높이 데이터는 elevatr
패키지로 해결한다.
library(tidyverse)
library(raster)
library(viridis)
library(sf)
<- sf::read_sf("data/shapefile/SIG_201902/TL_SCCO_SIG.shp") %>%
sgg_sf mutate(SIG_KOR_NM = iconv(SIG_KOR_NM, from = "cp949", to ="utf-8"))
# gangnam <- sgg_sf %>%
# filter(SIG_KOR_NM == "강남구")
#
# gangnam
# sgg_sf %>%
# filter(SIG_KOR_NM == "서초구")
<- sf::read_sf("data/shapefile/EMD_201902/TL_SCCO_EMD.shp")
emd_sf
<- emd_sf %>%
gangnam mutate(EMD_KOR_NM = iconv(EMD_KOR_NM, from = "cp949", to ="utf-8")) %>%
mutate(SIG_CD = str_sub(EMD_CD, 1, 5)) %>%
filter(SIG_CD == 11680 | SIG_CD == 11650) # 강남구(11680)와 서초구(11650)
library(elevatr)
<- get_elev_raster(gangnam, z = 14)
elevation
elevation
plot(elevation, main="강남역 인근 강남구와 서초구")
plot(gangnam, add=TRUE)
지하철 2호선 교대역, 강남역, 역삼역으로 이어지는 3개 지하철역을 표시하고 서초구와 강남구의 높이 데이터를 매칭한다.
<- elevation %>%
elevation_tbl as.data.frame(xy=TRUE) %>%
drop_na() %>%
as_tibble() %>%
set_names(c("x", "y", "value")) %>%
filter(value > -10)
<- st_as_sf(tibble(y = 37.497952, x = 127.027619, label = "강남역"),
gangnam_station coords = c("x", "y"), remove = FALSE,
crs = 4326, agr = "constant")
<- st_as_sf(tibble(y = 37.5007694, x = 127.0368262, label = "역삼역"),
yeoksam_station coords = c("x", "y"), remove = FALSE,
crs = 4326, agr = "constant")
<- st_as_sf(tibble(y = 37.4936866, x = 127.0136717, label = "교대역"),
edu_station coords = c("x", "y"), remove = FALSE,
crs = 4326, agr = "constant")
<- gangnam %>%
gangnam_elevation_g ggplot() +
geom_raster(data = elevation_tbl, aes(x= x, y= y, fill = value)) +
geom_sf(aes(geometry = geometry), fill = 'transparent') +
geom_sf_text(aes(label =EMD_KOR_NM),size=3, family="MaruBuri", color = "white") +
scale_fill_viridis_c(name = "높이") +
::theme_cowplot() +
cowplotlabs(x = "", y = "",
title = "서울 강남구와 서초구와 폭우 지하철역 높이 시각화") +
geom_sf(data = gangnam_station, size = 1.5) +
geom_sf(data = yeoksam_station, size = 1.5) +
geom_sf(data = edu_station, size = 1.5) +
geom_sf_text(data = gangnam_station, aes(label = label), size = 5.5, vjust = 2.0, color ="white", size = 2) +
geom_sf_text(data = yeoksam_station, aes(label = label), size = 3.5, vjust = -2.0) +
geom_sf_text(data = edu_station, aes(label = label), size = 3.5, vjust = 2.0)
ggsave( glue::glue("fig/gangnam_elevation_g.png") ,
gangnam_elevation_g,device = ragg::agg_png,
width = 297, height = 210, units = "mm", res = 600)
서초동과 역삼동만 확대하여 강남역 인근 높이를 확인한다.
<- gangnam %>%
gangnam_bbox filter(EMD_KOR_NM %in% c("역삼동", "서초동")) %>%
st_bbox()
<- elevation_tbl %>%
station_elevation filter(x > gangnam_bbox$xmin, x < gangnam_bbox$xmax,
> gangnam_bbox$ymin, y < gangnam_bbox$ymax)
y
<- gangnam %>%
two_dong_g filter(EMD_KOR_NM %in% c("역삼동", "서초동")) %>%
ggplot() +
geom_raster(data = station_elevation, aes(x= x, y= y, fill = value)) +
geom_sf(aes(geometry = geometry), fill = 'transparent') +
geom_sf_text(aes(label =EMD_KOR_NM),size=3, family="MaruBuri", color = "white") +
scale_fill_viridis_c(name = "높이") +
::theme_cowplot() +
cowplotlabs(x = "", y = "",
title = "강남역 인근 서초동과 역삼동 지형 높이") +
geom_sf(data = gangnam_station, size = 1.5) +
geom_sf(data = yeoksam_station, size = 1.5) +
geom_sf(data = edu_station, size = 1.5) +
geom_sf_text(data = gangnam_station, aes(label = label), size = 5.5, vjust = 2.0, color ="white", size = 2) +
geom_sf_text(data = yeoksam_station, aes(label = label), size = 3.5, vjust = -2.0) +
geom_sf_text(data = edu_station, aes(label = label), size = 3.5, vjust = 2.0)
ggsave( glue::glue("fig/two_dong_g.png") ,
two_dong_g,device = ragg::agg_png,
width = 297, height = 210, units = "mm", res = 600)
library(rayshader)
<- gangnam %>%
two_dong_sf filter(EMD_KOR_NM %in% c("역삼동", "서초동"))
<- raster::crop(elevation, two_dong_sf)
station_elevation
plot(station_elevation)
<- raster_to_matrix(station_elevation) %>%
station_matrix resize_matrix(0.25)
<- station_matrix %>%
flood_map height_shade() %>%
add_overlay(sphere_shade(station_matrix, texture = "desert",
zscale=4, colorintensity = 5), alphalayer=0.5) %>%
add_shadow(lamb_shade(station_matrix, zscale = 6),0) %>%
add_shadow(ambient_shade(station_matrix), 0) %>%
add_shadow(texture_shade(station_matrix, detail=8/10, contrast=9, brightness = 11), 0.1)
= "#7d4911"
contour_color
<- generate_contour_overlay(station_matrix, color = contour_color,
contours_layer linewidth = 0.05,
levels=seq(min(station_matrix),
max(station_matrix),
by=20))
<- geoviz::slippy_overlay(station_elevation,
overlay_image_terrain image_source = "stamen",
image_type = "terrain",
png_opacity = 1)
%>%
flood_map # add_overlay(contours_layer, alphalayer = 0.95) %>%
add_overlay(overlay_image_terrain) %>%
::plot_map() rayshader
데이터 과학자 이광춘 저작
kwangchun.lee.7@gmail.com