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
2.3k
GIS(地理情報システム) - MongoDBによるジオメディア開発
Kengo Imamura
October 05, 2016
Tweet
Share
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.7k
Marketing to machines
jonoalderson
1
4.7k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
3.9k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
32
2.1k
Code Review Best Practice
trishagee
74
20k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
470
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
11
830
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Done Done
chrislema
186
16k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Speed Design
sergeychernyshev
33
1.5k
Building the Perfect Custom Keyboard
takai
2
690
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/
ご清聴ありがとうございます。