More Related Content
Similar to Web+GISという視点から見たGISの方向性
Similar to Web+GISという視点から見たGISの方向性 (20)
More from Hidenori Fujimura
More from Hidenori Fujimura (8)
Web+GISという視点から見たGISの方向性
- 43. $KCODE = 'u'
require 'rubygems'
require 'sequel'
require 'geo_ruby'
DB = Sequel::connect('postgres://fitter:happier@localhost/more_productive',
:encoding => 'UTF-8')
DB.create_table!(:japan_highway) do
primary_key :gid
String :type
String :name
boolean :oneway
real :lanes
end
DB["SELECT AddGeometryColumn('', 'japan_highway', 'the_geom', '4326', 'MULTILINESTRING', 2);"].first
DB.transaction {
GeoRuby::Shp4r::ShpFile.open('japan_highway.shp') {|shp|
shp.each {|r|
DB[:japan_highway].insert({
:type => r.data['TYPE'],
:name => r.data['NAME'],
:oneway => r.data['ONEWAY'] == 'yes',
:lanes => r.data['LANES'].to_f,
:the_geom => :ST_GeomFromText.sql_function(r.geometry.as_wkt, 4326)
})
}
}
}
- 44. class App < Sinatra::Base
DB = Sequel::connect('postgres://fitter:happier@localhost/more_productive')
get '/geohash/:file_name' do
content_type 'text/html'
geohash = params[:file_name].sub('.html', '')
extent = GeoHash.decode(geohash)
...
bbox = "ST_GeomFromText('POLYGON ((#{lng0} #{lat0}, #{lng1} #{lat0}, #{lng1} #{lat1}, #{lng0} #{lat1}, #{lng0} #{lat0}))', 4326)"
@dataset = DB["SELECT ST_AsSVG(ST_Affine(ST_Intersection(the_geom, #{bbox}), #{a}, #{b}, #{d}, #{e}, #{x_off}, #{y_off}), 0, 0),
type, name FROM japan_highway WHERE ST_Intersects(the_geom, #{bbox});"]
instr = []
@dataset.each {|r|
instr << " r.path('#{r[:st_assvg]}').attr('stroke', '#{color}');n"
}
s = haml <<-EOS
!!!XML
%html
...
%body
:javascript
window.onload = function() {
...
});
window.document.addEventListener('touchstart', function(evt) {
...
}, false);
...
}
EOS
File.open("public/geohash/#{geohash}.html", 'w') {|w|
w.print s
}
s
end
end
App.run! :port => 2010
- 45. require 'app'
run Sinatra::Application
require 'rubygems'
require 'sinatra'
get '/' do
redirect '/geohash/xn77n.html'
end
require 'rubygems'
require 'pr_geohash'
require 'open-uri'
ALPHABET = "0123456789bcdefghjkmnpqrstuvwxyz"
def get(geohash)
url = "http://localhost:2010/geohash/#{geohash}.html"
print url, "n"
open url
end
%w{xn7 xnk}.each {|seed|
ALPHABET.each_char {|c1|
ALPHABET.each_char {|c2|
get(seed + c1 + c2)
}
}
}
$ sudo gem install heroku
$ heroku create degree-zero-web-mapping
$ git init
$ git add .
$ git commit
$ git push heroku master