Web+GISという視点から見たGISの方向性

2,740 views

Published on

Published in: Technology, Education

Web+GISという視点から見たGISの方向性

  1. 1. http://en.wikipedia.org/wiki/ File:Bundesarchiv_Bild_102-08759,_Flugzeug_Junkers_G-24.jpg Attribution: Bundesarchiv, Bild 102-08759 / Unknown / CC-BY-SA
  2. 2. No. 386
  3. 3. $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) }) } } }
  4. 4. 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
  5. 5. 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
  6. 6. Demo

×