-
-
Save dersteppenwolf/6354494 to your computer and use it in GitHub Desktop.
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
# | |
# converts a shapefile to an elasticsearch geo_point type with this mapping: | |
# | |
# { | |
# "zipcode" : { | |
# "properties" : { | |
# "geometry": { | |
# "properties": { | |
# "coordinates": { | |
# "type": "geo_point" | |
# } | |
# } | |
# } | |
# } | |
# } | |
# } | |
# | |
# writes to stdout, can redirect to a file: | |
# | |
# ruby shapefile2elasticsearch.rb > outfile.json | |
# | |
require 'rubygems' | |
require 'rgeo' | |
require 'rgeo/shapefile' | |
iter = 0 | |
RGeo::Shapefile::Reader.open('zipcode10.shp') do |file| | |
file.each do |record| | |
geom = record.geometry | |
attr = record.attributes | |
load = { | |
"index" => { | |
"_index"=>"geo", | |
"_type"=>"zipcode", | |
"_id" => iter | |
} | |
} | |
data = { | |
"geometry" => { | |
"coordinates" => { | |
"lat" => geom.y(), | |
"lon" => geom.x() | |
} | |
} | |
} | |
data.merge!(attr) | |
iter +=1 | |
puts load.to_json | |
puts data.to_json | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment