Created
May 6, 2015 20:57
-
-
Save handygeospatial/4377b310ff4afc3806a8 to your computer and use it in GitHub Desktop.
Shapefile を tippecanoe でベクトルタイル変換して tessera 経由でブラウザ確認するまで ref: http://qiita.com/handygeospatial/items/eda4c6305d6d042c8178
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
$ ruby togeojson.rb | gzip -9 > some.geojson.gz |
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
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 |
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
$ brew install tippecanoe |
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
$ gzcat some.geojson.gz | tippecanoe -z 18 -Z 15 -t . some.mbtiles |
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
$ npm install mbtiles tilelive tilelive-mapnik |
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
$ npm install tessera |
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
$ npm install tilelive-vector tilelive-xray |
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
$ npm find tilelive |
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
$ tessera mbtiles://./some.mbtiles |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment