Last active
January 29, 2016 06:47
-
-
Save kashitan/8116b853f208ce1c40fe to your computer and use it in GitHub Desktop.
ShapeファイルからGeoJSONに変換するサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rgdal) | |
library(sp) | |
library(maptools) | |
l <- read.csv("shapes.csv", header = TRUE, colClasses = c("character", "character", "character")) | |
P4S.latlon <- CRS("+proj=longlat +datum=WGS84") | |
for(i in 1:nrow(l)) { | |
shp <- readShapePoly(paste0("shapes/", l$dir[i], "/", l$shape[i]) , | |
verbose = TRUE, proj4string = P4S.latlon) | |
# 不要な項目が多いので住所の文字列のみを選択 | |
shp <- shp[, c("KEN_NAME", "GST_NAME", "CSS_NAME", "MOJI")] | |
# Why are you using SJIS? 案件 | |
shp$KEN_NAME <- iconv(shp$KEN_NAME, "CP932", "UTF8") | |
shp$GST_NAME <- iconv(shp$GST_NAME, "CP932", "UTF8") | |
shp$CSS_NAME <- iconv(shp$CSS_NAME, "CP932", "UTF8") | |
shp$MOJI <- iconv(shp$MOJI, "CP932", "UTF8") | |
geojson_file <- paste0("geojson/", l$city_cd[i], ".json") | |
writeOGR(shp, geojson_file, layer = "geojson", driver = "GeoJSON") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment