인코딩 설정에 따라 아래와 같이 한글이 깨지는현상이 발생한다.
setwd('Y:/shp/SIG_201703')
shp=readOGR('TL_SCCO_SIG.shp',encoding = 'cp949')
## OGR data source with driver: ESRI Shapefile
## Source: "Y:\shp\SIG_201703\TL_SCCO_SIG.shp", layer: "TL_SCCO_SIG"
## with 250 features
## It has 3 fields
head(shp@data)
## SIG_CD SIG_ENG_NM SIG_KOR_NM
## 0 11110 Jongno-gu 醫낅줈援\xac
## 1 11140 Jung-gu 以묎뎄
## 2 11170 Yongsan-gu \xec슜\xec궛援\xac
## 3 11200 Seongdong-gu \xec꽦\xeb룞援\xac
## 4 11215 Gwangjin-gu 愿묒쭊援\xac
## 5 11230 Dongdaemun-gu \xeb룞\xeb\x8c\u0080臾멸뎄
setwd('Y:/shp/SIG_201703')
shp=readOGR('TL_SCCO_SIG.shp',encoding = 'utf-8')
## OGR data source with driver: ESRI Shapefile
## Source: "Y:\shp\SIG_201703\TL_SCCO_SIG.shp", layer: "TL_SCCO_SIG"
## with 250 features
## It has 3 fields
head(shp@data)
## SIG_CD SIG_ENG_NM SIG_KOR_NM
## 0 11110 Jongno-gu 종로구
## 1 11140 Jung-gu 중구
## 2 11170 Yongsan-gu 용산구
## 3 11200 Seongdong-gu 성동구
## 4 11215 Gwangjin-gu 광진구
## 5 11230 Dongdaemun-gu 동대문구
head(shp@data)
## SIG_CD SIG_ENG_NM SIG_KOR_NM
## 0 11110 Jongno-gu 종로구
## 1 11140 Jung-gu 중구
## 2 11170 Yongsan-gu 용산구
## 3 11200 Seongdong-gu 성동구
## 4 11215 Gwangjin-gu 광진구
## 5 11230 Dongdaemun-gu 동대문구
plot(shp)
plot(shp[1,])
특정 시군구 추출이 가능하다.
par(mfrow=c(1,2))
plot(shp[shp@data$SIG_KOR_NM%in%c('종로구','용산구'),])
library(raster)
plot(union(shp[shp@data$SIG_KOR_NM%in%c('종로구'),], shp[shp@data$SIG_KOR_NM%in%c('용산구'),]))
## Loading required namespace: rgeos
자료를 merge 하면 정렬이 바뀐다.
par(mfrow=c(1,3))
setwd('Y:/shp/CTPRVN_201703')
shp2=readOGR('TL_SCCO_CTPRVN.shp')
## OGR data source with driver: ESRI Shapefile
## Source: "Y:\shp\CTPRVN_201703\TL_SCCO_CTPRVN.shp", layer: "TL_SCCO_CTPRVN"
## with 17 features
## It has 3 fields
shp2@data$index=1:nrow(shp2@data)
plot(shp2,col=shp2@data$CTP_KOR_NM%in%'강원도')
shp2@data=merge(shp2@data,data.frame(CTP_KOR_NM='강원도',del=1),by='CTP_KOR_NM',all=T)
plot(shp2,col=shp2@data$CTP_KOR_NM=='강원도')
shp2@data=shp2[order(shp2@data$index),]@data
plot(shp2,col=shp2@data$CTP_KOR_NM=='강원도')
지적도의 위경도 값을 보면 우리가 아는 long ,lat 구조로 이루어지지 않은걸 볼 수 있다. 따라서 좌표계를 바꾸어 준다.
좌표계 링크[https://m.blog.naver.com/dw2613/220491869384]
shp2@bbox
## min max
## x 746110.3 1387950
## y 1458754.0 2066200
from.crs = "+proj=tmerc +lat_0=38 +lon_0=127.5 +k=0.9996 +x_0=1000000 +y_0=2000000 +ellps=GRS80 +units=m +no_defs"
to.crs = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs"
proj4string(shp2)<-CRS(from.crs)
shp2<-spTransform(shp2,CRS(to.crs))
shp2@bbox
## min max
## x 124.60971 131.87278
## y 33.11371 38.59339