Kenta Kobayashi
August 22, 2015
2.7k

# 空間情報探索基礎論

YAPC::Asia 2015 のモバイルファクトリーランチセッション

※ランチセッションはベストトークの対象ではないです

August 22, 2015

## Transcript

2. ### About me • kobaken (@kﬂy8) • Mobile Factory • Senior

Engineer • like Perl, JS, Math • YAPC::Asia Staff (2013 - )

8. ### About Mobile Factory • ޒ൓ాͷWebܥITاۀ • ࠷্ۙ৔ͨ͠! • ओʹϞόΠϧήʔϜ΍ΞϓϦͷ։ൃ •

ࣗ෼͸ීஈҐஔ৘ใήʔϜͷ։ൃ

18. ### A B C D P ఺P͔Β΋ͬͱ΋͍ۙ఺͸ʁ ڑ཭ a = ఺A

- ఺P ڑ཭ b = ఺B - ఺P ڑ཭ c = ఺C - ఺P ڑ཭ d = ఺D - ఺P shift sort { \$a <=> \$b } (a,b,c,d)

20. ### ۭؒ৘ใʹ͓͚Δ ۙ๣ͷ໰͍߹Θͤ໰୊ͷಛ௃ • ۭؒʹ഑ஔ͞ΕΔ఺ʢྖҬʣͷදݱ͕Ϧετ • ྫ: (x1,y1, … z1) ,

(x2,y2, …, z2)
21. ### ۭؒ৘ใʹ͓͚Δ ۙ๣ͷ໰͍߹Θͤ໰୊ͷಛ௃ • ۭؒʹ഑ஔ͞ΕΔ఺ʢྖҬʣͷදݱ͕Ϧετ • ྫ: (x1,y1, … z1) ,

(x2,y2, …, z2) • ج఺͕มΘΔ • ౎౓ɺڑ཭ܭࢉ͢ΔΘ͚ʹ͸͍͔ͳ͍

28. ### my @ranks = SELECT * FROM ranking WHERE rank BETWEEN

my.rank - 10 AND my.rank + 10 ORDER BY rank;

@ranks;
30. ### sort { abs(\$a->score - \$my->score) <=> abs(\$b->score - \$my->score) }

@ranks; ީิΛऔΓग़͠ߜΓࠐΉ

34. ### Ґஔ৘ใʹ͓͚Δݕࡧํ๏ • ࠲ඪͷϥϯΫ෇͚ͷྫ • Ң౓ܦ౓ͷ࠾൪ • GeoHex, GeoHash, Open Location

Code • ࠷খ֎઀୹ܗ(MBR) ͱ R-Tree

   
36. ### ࠲ඪͷϥϯΫؔ਺ͷྫ • 2 x 2 ۭؒͰͷϥϯΫ෇͚ • (0,0) -> 00

-> 0        
37. ### ࠲ඪͷϥϯΫؔ਺ͷྫ • 2 x 2 ۭؒͰͷϥϯΫ෇͚ • (0,0) -> 00

-> 0 • (0,1) -> 01 -> 1        
38. ### ࠲ඪͷϥϯΫؔ਺ͷྫ • 2 x 2 ۭؒͰͷϥϯΫ෇͚ • (0,0) -> 00

-> 0 • (0,1) -> 01 -> 1 • (1,0) -> 10 -> 2        
39. ### ࠲ඪͷϥϯΫؔ਺ͷྫ • 2 x 2 ۭؒͰͷϥϯΫ෇͚ • (0,0) -> 00

-> 0 • (0,1) -> 01 -> 1 • (1,0) -> 10 -> 2 • (1,1) -> 11 -> 3        
40. ### ࠲ඪͷϥϯΫؔ਺ͷྫ • 2 x 2 ۭؒͰͷϥϯΫ෇͚ • (0,0) -> 00

-> 0 • (0,1) -> 01 -> 1 • (1,0) -> 10 -> 2 • (1,1) -> 11 -> 3 1 3 2 0
41. ### ࠲ඪͷϥϯΫؔ਺ͷྫ • 2 x 2 ۭؒͰͷϥϯΫ෇͚ • (0,0) -> 00

-> 0 • (0,1) -> 01 -> 1 • (1,0) -> 10 -> 2 • (1,1) -> 11 -> 3 1 3 2 0 ࠲ඪΛ ̎ਐ਺දݱͱΈͳͯ͠ ͞Βʹ̍̌ਐ਺දݱ͢Δ
42. ### ࠲ඪͷϥϯΫؔ਺ͷྫ Q. (1,0) ͔Β ϥϯΫ1Ҏ಺ͷ࠲ඪ͸? 1 3 2 0 

      
43. ### ࠲ඪͷϥϯΫؔ਺ͷྫ Q. (1,0) ͔Β ϥϯΫ1Ҏ಺ͷ࠲ඪ͸? A. (1,0) -> 10 ->

2. SELECT * FROM cord WHERE rank BETWEEN 1 AND 3 1 3 2 0        
44. ### ࠲ඪͷϥϯΫؔ਺ͷྫ Q. (1,0) ͔Β ϥϯΫ1Ҏ಺ͷ࠲ඪ͸? A. (1,0) -> 10 ->

2. SELECT * FROM cord WHERE rank BETWEEN 1 AND 3 1 3 2 0        
45. ### ࠲ඪͷϥϯΫؔ਺ͷྫ • 3 x 3 ۭؒͷ৔߹ 0,0 0,1 0,2 1,0

1,1 1,2 2,0 2,1 2,2
46. ### ࠲ඪͷϥϯΫؔ਺ͷྫ • 3 x 3 ۭؒͷ৔߹ 0 1 2 3

4 5 6 7 8 ࠲ඪΛ ̏ਐ਺දݱͱΈͳͯ͠ ̍̌ਐ਺දݱ͢Δ

• Z-ordering

56. ### GeoHex v3 • created by @sa2da • MIT License •

http://geohex.net/
57. ### use Geo::Hex::V3::XS; my \$zone = Geo::Hex::V3::XS->new( lat => 35.6295764, lng

=> 139.794686, level => 10 ); \$zone->code # => XM4885355114
58. ### GeoHex v3 encode example use Geo::Hex::V3::XS; my \$zone = Geo::Hex::V3::XS->new(

lat => 35.6295764, lng => 139.794686, level => 10 ); \$zone->code # => XM4885355114 ϨϕϧΛ্͛Δͱਫ਼౓্͕ঢ
59. ### GeoHex v3 encode example use Geo::Hex::V3::XS; my \$zone = Geo::Hex::V3::XS->new(

lat => 35.6295764, lng => 139.794686, level => 10 ); \$zone->code # => XM4885355114 ΄΅ࣗવ਺ͳܗͰ Encode w w
60. ### GeoHex v3 encode example use Geo::Hex::V3::XS; my \$zone = Geo::Hex::V3::XS->new(

lat => 35.6295764, lng => 139.794686, level => 10 ); \$zone->code # => XM4885355114 ಄ͷ30ਐ਺දهͷ࢓༷Λআ͚͹ɺ ׬શͳࣗવ਺දه

62. ### use Geo::Hex::V3::XS; Geo::Hex::V3::XS->new( lat => 35.6295764, lng => 139.794686, level

=> \$_ )->code for 0..10;
63. ### use Geo::Hex::V3::XS; Geo::Hex::V3::XS->new( lat => 35.6295764, lng => 139.794686, level

=> \$_ )->code for 0..10; # => XM XM4 XM48 XM488 XM4885 XM48853 XM488535 XM4885355 XM48853551 XM488535511 XM4885355114

XM4885355114
65. ### XM XM4 XM48 XM488 XM4885 XM48853 XM488535 XM4885355 XM48853551 XM488535511

XM4885355114 ֦େϨϕϧʢਫ਼౓ʣΛ্͛Δ ͱɺίʔυ͕ܻ͚̍ͩ૿͑Δ

Empty set

Empty set

Empty set

Empty set

国際展示場正門
74. ### SELECT name FROM station WHERE geohex LIKE ‘XM48853_____’ # =>

テレコムセンター 船の科学館 青海 国際展示場正門 新木場

78. ### GeoHex v3 Encodeʹ͍ͭͯ • Web ϝϧΧτϧ஍ਤΛਖ਼࿡֯ܗͰ۠෼ • WebϝϧΧτϧͱ͸ɺϝϧΧτϧ஍ਤΛϒϥ ΢βͷpositionදݱʹࣹӨͨ͠΋ͷ x

= longtitude * R / 180; y = ln(tan((90 + latitude) * pi / 360)) * (pi / 180) * R / 180 R = ஍ٿͷ൒ܘ = 20037508.34