Skip to content

Instantly share code, notes, and snippets.

@kashitan
Last active January 29, 2016 07:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kashitan/58b931c08de8eef307cc to your computer and use it in GitHub Desktop.
Save kashitan/58b931c08de8eef307cc to your computer and use it in GitHub Desktop.
GeoJSON形式のファイルをelastic searchのBulk API用に変換
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