Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
GIS(地理情報システム) - MongoDBによるジオメディア開発
Search
Kengo Imamura
October 05, 2016
0
2k
GIS(地理情報システム) - MongoDBによるジオメディア開発
Kengo Imamura
October 05, 2016
Tweet
Share
Featured
See All Featured
Debugging Ruby Performance
tmm1
73
12k
Pencils Down: Stop Designing & Start Developing
hursman
119
11k
Teambox: Starting and Learning
jrom
132
8.7k
WebSockets: Embracing the real-time Web
robhawkes
59
7.4k
Bash Introduction
62gerente
608
210k
What the flash - Photography Introduction
edds
67
11k
How To Stay Up To Date on Web Technology
chriscoyier
787
250k
Happy Clients
brianwarren
97
6.7k
Being A Developer After 40
akosma
84
590k
How GitHub (no longer) Works
holman
311
140k
Scaling GitHub
holman
458
140k
Speed Design
sergeychernyshev
22
490
Transcript
GIS( 地理情報システム) MongoDB によるジオメディア開発 @chocoken517
保育園探し 保育園一覧だと場所がわかりにくい 地図上で保育園の場所がわかるようにしたい 通勤経路にある保育園を知りたい
GIS とは GIS(Geographic Information System: 地理情報シス テム) とは、 位置や空間に関する様々 な情報を、
コン ピュー タを用いて重ね合わせ、 情報の分析・ 解析をお こなったり、 情報を視覚的に表示させるシステム。 [ 参照] GIS ポー タルサイト http://www.gis.go.jp/contents/whatisgis.html
どうやるの?
位置参照デー タベー ス PostGIS PostgreSQL デー タベー スで地理空間情報を扱う ための拡張 MySQL
5.7 からInnoDB での空間インデックス可 MongoDB 地理空間インデックス
MongoDB の位置情報
MongoDB のサポー ト 地理空間インデックス 平面空間(2d) 球面空間(2dsphere) geoNear 指定ポイントから近い順に返すコマンド 空間インデックスが必要 GeoJSON
JavaScript Object Notation (JSON) を基にした 地理空間デー タ交換フォー マット
Ruby on Rails
gem geocoder ジオコー ディング( 住所を地理的座標に変換) mongoid Object-Document-Mapper MongoDB のDSL を提供
geocoder class Place include Mongoid::Document include Geocoder::Model::Mongoid field :address, type:
String field :coordinates, type: Array geocoded_by :address after_validation :geocode end address をもとにジオコー ド取得し coordinates に入れる
index geocoder で最初から設定されているインデックスは 平面空間(2d) で作成されるのでスキップする geocoded_by :address, skip_index: true 球面空間(2dsphere)
インデックス作成されるように設 定する index(coordinates: '2dsphere') index 作成 $ rake db:mongoid:create_indexes
MongoDB で確認 > db.places.getIndexes() [ ~~~ 省略 ~~~ { "v"
: 1, "key" : { "coordinates" : "2dsphere" }, "name" : "coordinates_2dsphere", "ns" : "meeful_development.places", "2dsphereIndexVersion" : 3 } ] >
登録 > Place.new(address: ' 墨田区亀沢一丁目27 番5 号').save => true coordinates
にジオコー ドが入ってることを確認 > Place.where(address: ' 墨田区亀沢一丁目27 番5 号').first .coordinates => [139.7994141, 35.698556]
指定場所から近い順に取得 Place.geo_near(Geocoder.coordinates(' 場所').reverse) .spherical Speee から近い駅順にソー ト > Place .geo_near(Geocoder.coordinates('
東京都港区六本木4-1-4') .reverse) .spherical.each { |a| puts a.address } 六本木駅 麻布十番駅 青山一丁目駅 国立競技場駅 代々 木駅 新宿駅
池袋駅から近い駅順ソー ト > Place.geo_near(Geocoder.coordinates(' 池袋駅').reverse) .spherical.each { |a| puts a.address
} 新宿駅 代々 木駅 国立競技場駅 青山一丁目駅 六本木駅 麻布十番駅
最大距離指定し近い順に取得 max_distance で最大距離指定 会社から2km 以内の駅を取得 km からラジアンに変換 > Place .geo_near(Geocoder.coordinates('
東京都港区六本木4-1-4') .reverse) .spherical .max_distance(Geocoder::Calculations .distance_to_radians(2)) .each { |a| puts a.addres } 六本木駅 麻布十番駅 青山一丁目駅
指定場所から最大距離指定し map に表示するジオメディア 作ってみました
デモ https://meeful.com/
ご清聴ありがとうございます。