Last active
January 29, 2016 07:46
-
-
Save kashitan/58b931c08de8eef307cc to your computer and use it in GitHub Desktop.
GeoJSON形式のファイルをelastic searchのBulk API用に変換
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(dplyr) | |
library(jsonlite) | |
l <- read.csv("shapes.csv", header = TRUE, colClasses = c("character", "character", "character")) | |
fix_str <- '{"index":{"_index":"towns", "_type":"town"}}' | |
for(i in 1:nrow(l)) { | |
s <- fromJSON(paste0("geojson/", l$city_cd[i], ".json")) | |
f <- s$features | |
for(i in 1:nrow(f)) { | |
json_str <- toJSON(f[i, ]) %>% | |
gsub(pattern = "^\\[|\\]$", replacement = "", .) | |
txt[i] <- paste0(fix_str, "\n", json_str) | |
} | |
write(txt, file=paste0("4bulkapi/", l$city_cd, ".json")) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment