Skip to content

Instantly share code, notes, and snippets.

@handygeospatial
Created May 6, 2015 20:57
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 handygeospatial/4377b310ff4afc3806a8 to your computer and use it in GitHub Desktop.
Save handygeospatial/4377b310ff4afc3806a8 to your computer and use it in GitHub Desktop.
Shapefile を tippecanoe でベクトルタイル変換して tessera 経由でブラウザ確認するまで ref: http://qiita.com/handygeospatial/items/eda4c6305d6d042c8178
$ ruby togeojson.rb | gzip -9 > some.geojson.gz
require 'rubygems'
require 'find'
require 'json'
require 'georuby'
require 'geo_ruby/shp'
#require 'geo_ruby/geojson'
def process(shp_path)
$stderr.print "processing #{shp_path}.\n"
geojson_path = shp_path.sub(/shp$/, 'geojson')
s = []
GeoRuby::Shp4r::ShpFile.open(shp_path) {|shp|
shp.each {|r|
r.data.attributes.each{|k,v|
if v.class == String
# 属性の文字コードを Shift_JIS から UTF-8 に変換する
r.data.attributes[k] = v.encode('UTF-8', 'CP932')
end
}
if $first
$first = false
else
print ",\n"
end
r.geometry.with_m = false
r.geometry.with_z = false
print JSON.dump({
"type" => "Feature",
"geometry" => r.geometry,
"properties" => r.data.attributes
})
}
}
end
$first = true
print <<-EOS
{"type": "FeatureCollection", "features": [
EOS
count = 0
Find.find('.') {|path|
next unless /shp$/.match path
next unless /RdCL/.match path # "RdCL" がファイル名に入っている場合のみ処理
next if /(NNFPt|NRPt|CSPt|PFPt|DEM)/.match path # 属性・分量の問題で後回し
count += 1
process(path)
#break if count == 100
}
print <<-EOS
]}
EOS
$ brew install tippecanoe
$ gzcat some.geojson.gz | tippecanoe -z 18 -Z 15 -t . some.mbtiles
$ npm install mbtiles tilelive tilelive-mapnik
$ npm install tessera
$ npm install tilelive-vector tilelive-xray
$ npm find tilelive
$ tessera mbtiles://./some.mbtiles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment