Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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