-
Notifications
You must be signed in to change notification settings - Fork 0
/
99-參照資料庫.Rmd
103 lines (76 loc) · 6 KB
/
99-參照資料庫.Rmd
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# 參照資料庫
***
這邊放的都是參照資料庫,包含有
1. 內政部地政司**全國段代碼表**整合
2. 休耕轉作補貼作物代碼表
## 內政部地政司**全國段代碼**整合
### 背景說明{-}
* 地段地號的資料格式為14或15碼的英數組合,組合方式為`6或7碼的地段代碼` + `8碼的地號代碼 `,農委會資訊中心已統一將`6+8碼的地段地號格式`定為標準的資料交換格式,但是部分單位提供的地段地號資料為7+8碼的組合,因此需要一個對照表能將6+8與7+8的代碼互相轉換。
* 本資料庫用於製作全國段代碼表,可用於段代碼6碼與7碼間的轉換,亦可用於段代碼與縣市鄉鎮之碰檔
#### 製作方式 {-}
* 連線至[內政部地政司土地段名查詢系統](https://www.land.moi.gov.tw/ngis/chhtml/query1.asp)。
* 下載`段名代碼表`與`縣市及鄉鎮市區代碼表快速下載`,選擇全國與csv檔,並更名為`全國段名代碼表_西元年.csv`與`全國縣市及鄉鎮市區代碼表_西元年.csv`。
[截圖](https://trello-attachments.s3.amazonaws.com/5a0117d243de779b5875b2b7/5a093a56592649e22f6bebda/8e5e0745a03470f1596307288f47133a/%E6%95%99%E5%AD%B81.png)
* 新增欄位地段:將段名代碼表的"段" + "小段"並以"-"相連,需注意若小段為空則只要保存"段"
* 新增所區碼:將全國縣市鄉鎮市區代碼表的事務所代碼+補到2位數的鄉鎮市區代碼(1→01, 2→02, 13→13)
* **使用所區碼結合段名.csv與鄉鎮市區.csv**
* 新增6碼段代碼:所區碼前兩碼+補到4位數的代碼(1→0001, 11→0011, 111→0111)
* 新增7碼段代碼:縣市代碼+鄉鎮代碼+補到4位數的代碼(1→0001, 11→0011, 111→0111)
* 新增最後更新日期:製作更新之當天
* 欄位更名:段→大段
* 輸出並匯入資料庫
> 另有使用python介接國土測繪中心API的方式,請參閱 [這裡](https://github.com/travishen/sectw)
### 處理流程 {-}
```{r eval=FALSE, message=FALSE, warning=FALSE}
rm(list=ls())
library(stringr)
library(lubridate)
setwd("D:\\sw\\00-整合資料庫\\00-整合資料庫\\10全國段代碼(內政部地政司)")
code_list <- read.csv(paste0("全國段名代碼表_", year(Sys.Date()), ".csv"), header=T, stringsAsFactors=F)
country_list <- read.csv(paste0("全國縣市鄉鎮市區代碼表_", year(Sys.Date()), ".csv"), header=T, stringsAsFactors=F)
code_list$縣市代碼 <- substr(code_list$所區碼, 1, 1) #
code_list$縣市 <- country_list$縣市名稱[match(code_list$縣市代碼, country_list$縣市代碼)]
code_list$鄉鎮代碼 <- substr(code_list$所區碼, 3,4)
code_list$地段 <- ifelse(code_list$小段=="", code_list$地段 <- code_list$段, code_list$地段 <- paste(code_list$段, code_list$小段, sep="-"))
#Use所區碼 to merge two table, then get the 鄉鎮市區----
country_list$所區碼 <- paste0(country_list$事務所代碼, str_sub(paste0("0", country_list$鄉鎮市區代碼), -2, -1))
code_list$鄉鎮市區 <- country_list$鄉鎮市區名稱[match(code_list$所區碼, country_list$所區碼)]
#Use所區碼 to merge two table, then get the 鄉鎮市區
code_list$段代碼_6 <- paste0(substr(code_list$所區碼, 1,2), str_sub(paste0("000", code_list$代碼), -4, -1))
code_list$段代碼_7 <- paste0(code_list$縣市代碼, code_list$鄉鎮代碼, substr(code_list$段代碼_6, 3, 6))
code_list$最後更新日期 <- Sys.Date()
code_list <- code_list[,c("縣市", "縣市代碼", "鄉鎮市區", "鄉鎮代碼", "地段", "段", "小段", "代碼", "所區碼", "段代碼_6", "段代碼_7", "備註", "最後更新日期")] #rearrange column
names(code_list) <- c("縣市", "縣市代碼", "鄉鎮市區", , "鄉鎮代碼", "地段", "大段", "小段", "代碼", "所區碼", "段代碼6碼", "段代碼7碼", "備註", "最後更新日期")
write.csv(code_list, "106整合全國地段代碼表.csv", row.names=F, quote=F) # output to [ReferenceDB].[dbo].[106_landCode]
```
### 結果 {-}
![](https://trello-attachments.s3.amazonaws.com/5a0117d243de779b5875b2b7/5a093a56592649e22f6bebda/b7e748c98dd30f4504712d2227244494/test.png "全國段代碼表")
## 休耕轉作補貼 - 作物代碼表
### 背景說明 {-}
*製作包含作物代碼(細項)、作物中文(細項)、作物代碼(大類)、作物中文(大類)的對照表
### 製作方式{-}
1. 索取`農糧代碼對照表_20180424(楊老師提供).xlsx`:每年向楊老師索取休耕轉作補貼清冊後,一併索取,[檔案位置請點我](Z:\03-調查統計科\001_農業統計整合資料庫\001_農業統計整合資料庫\01--休耕、耕鋤、災害\原始資料\清冊檔)。
* 檔案欄位
*
cdtyp | cdno | cdexp | cdexp2
-------- |-------------------|----------------|----------------
各種代碼 | 作物代碼(細項3碼) | 作物中文(細項) | 作物代碼(大類1碼)
* `各種代碼說明`
*
各種代碼 | 定義
---------|-------
01 | 縣市碼
02 | 縣市鄉鎮碼
05 | 7碼地段碼
08 | 作物代碼
2. 使用`補助作物種類.xlsx`:[檔案位置請點我](Z:\03-調查統計科\001_農業統計整合資料庫\001_農業統計整合資料庫\01--休耕、耕鋤、災害\原始資料\清冊檔\補助作物種類.xlsx)。
* 檔案欄位:
*
作物代碼(大類1碼) | 作物中文(大類)
------------------| ------------
3. 把1與2結合,產出`106作物代碼表.xlsx`,[檔案請點我](Z:\03-調查統計科\001_農業統計整合資料庫\001_農業統計整合資料庫\01--休耕、耕鋤、災害\原始資料\清冊檔\106作物代碼表.xlsx)。
4. 結果
cdtyp | codeSmall | nameSmall | codeBig | nameBig | update
-------- |-------------------|----------------|-------------------|----------------|---------
作物代碼 | 作物代碼(細項3碼) | 作物中文(細項) | 作物代碼(大類1碼) | 作物中文(大類) | 製表日期
![](https://trello-attachments.s3.amazonaws.com/5a0117d243de779b5875b2b7/5a093a56592649e22f6bebda/88a3c7c0331b68c1bcebcde22dde2674/test.png "作物代碼整合結果")