Skip to content

Commit

Permalink
working on hexagon"
Browse files Browse the repository at this point in the history
  • Loading branch information
statkclee committed Nov 13, 2023
1 parent d9cce65 commit 05a3494
Show file tree
Hide file tree
Showing 18 changed files with 7,975 additions and 4 deletions.
2 changes: 2 additions & 0 deletions _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ website:
text: "지도 기본기"
- href: tour.qmd
text: "대통령 해외순방"
- href: cartogram.qmd
text: "인구비례 선거구"

- text: "GIS 분석&챗GPT"
menu:
Expand Down
126 changes: 126 additions & 0 deletions cartogram.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
---
title: "지도제작 대회"
subtitle: "인구비례 선거구"
description: |
인구비례 선거구 지도가 필요한 시점이 되었습니다.
author:
- name: 이광춘
url: https://www.linkedin.com/in/kwangchunlee/
affiliation: 한국 R 사용자회
affiliation-url: https://github.com/bit2r
title-block-banner: true
format:
html:
theme: flatly
code-fold: true
code-overflow: wrap
toc: true
toc-depth: 3
toc-title: 목차
number-sections: true
highlight-style: github
self-contained: false
default-image-extension: jpg
filters:
- lightbox
lightbox: auto
link-citations: true
knitr:
opts_chunk:
eval: true
message: false
warning: false
collapse: true
comment: "#>"
R.options:
knitr.graphics.auto_pdf: true
editor_options:
chunk_output_type: console
---

```{r}
#| include: false
library(tidyverse)
library(rvest)
library(httr)
library(sf)
library(geogrid)
```


# 데이터셋

```{r}
#| eval: false
library(tidyverse)
library(rvest)
library(httr)
library(sf)
library(geogrid)
sf_use_s2(FALSE)
precinct_sf <- st_read("data/2020_21_elec_253.json")
sido_sf <- precinct_sf |>
# filter(SGG_1 == "부산") |>
calculate_grid(grid_type="hexagonal", learning_rate = 0.05, seed=20)
plot(sido_sf)
sido_hex <- assign_polygons(precinct_sf, sido_sf)
```

```{r}
# sido_hex |>
# st_write("data/precinct_21.geojson")
sido_hex <-
st_read("data/precinct_21.geojson")
sido_hex |>
st_geometry() |>
plot()
```

# 시도 경계

```{r}
sido_boundary_hex <- sido_hex |>
# ungroup() |>
group_by(SGG_1) |>
summarise(geometry = st_union(geometry))
sido_boundary_hex |>
ggplot() +
geom_sf(aes(geometry = geometry, fill = SGG_1))
```


# SVG to geojson

```{r}
svg_sf <- st_read("data/precinct_21/cartogram.geojson")
svg_sf |>
plot()
svg_shp <- st_read("data/precinct_21/2020_South_Korean_legislative_election_Results_Cartogram-polygon.shp")
svg_sf |>
plot()
```


# svg magick

```{r}
library(magick)
carto <- image_read("data/precinct_21/cartogram.svg")
```

4 changes: 4 additions & 0 deletions data/converted_geojson.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "FeatureCollection",
"features": []
}
260 changes: 260 additions & 0 deletions data/precinct_21.geojson

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UTF-8
Binary file not shown.
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,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions data/precinct_21/cartogram.geojson

Large diffs are not rendered by default.

Loading

0 comments on commit 05a3494

Please sign in to comment.