空間情報探索基礎論

 空間情報探索基礎論

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

http://yapcasia.org/2015/talk/show/e34fca9d-2ad1-11e5-aca1-525412004261

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

918b601dbd1297d58105508fb880b598?s=128

Kenta Kobayashi

August 22, 2015
Tweet

Transcript

  1. ۭؒ৘ใ୳ࡧجૅ࿦ YAPC::Asia 2015 Mobile Factory Lunch Session

  2. About me • kobaken (@kfly8) • Mobile Factory • Senior

    Engineer • like Perl, JS, Math • YAPC::Asia Staff (2013 - )
  3. ͝͸Μඒຯ͍͠Ͱ͔͢..ʁ

  4. ൃ஫ͨ͠ਓ ↓

  5. ඒຯ͔ͬͨ͠Β ౤ථ͍ͯͩ͘͠͞ʂ

  6. CM

  7. ͜ͷϥϯνηογϣϯ͸ ͷఏڙͰ͓ૹΓ͠·͢

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

    ࣗ෼͸ීஈҐஔ৘ใήʔϜͷ։ൃ
  9. None
  10. Ґஔ৘ใήʔϜͰ ར༻͍ͯ͠Δٕज़Λ جૅతͳ࿩͔Β͠·͢

  11. Agenda • Ґஔ৘ใѻ͍࣌ͷΑ͋͘Δ୳ࡧͷཁ݅ • ֨ࢠ্ͰͷϥϯΫ෇͚ • ஍ਤ্ͰͷϥϯΫ෇͚

  12. Α͋͘Δཁ݅

  13. Α͋͘Δཁ݅ • ݱࡏ஍͔Βɺ࠷୹ڑ཭ʹ͋ΔӺ͸Ͳ͔͜ʁ

  14. Α͋͘Δཁ݅ • ݱࡏ஍͔Βɺ࠷୹ڑ཭ʹ͋ΔӺ͸Ͳ͔͜ʁ • ޒ൓ాӺपล̏Ωϩݍ಺ͷITاۀ͸Ͳ͜ʁ

  15. Α͋͘Δཁ݅ • ݱࡏ஍͔Βɺ࠷୹ڑ཭ʹ͋ΔӺ͸Ͳ͔͜ʁ • ޒ൓ాӺपล̏Ωϩݍ಺ͷITاۀ͸Ͳ͜ʁ

  16. গ͠࿩Λ਺ֶΒ͘͢͠Δͱ…

  17. ɹɹɹ ɹɹA B ɹ ɹɹC ɹɹ ɹɹɹD P

  18. ɹɹɹ ɹɹA B ɹ ɹɹC ɹɹ ɹɹɹD P ఺P͔Β΋ͬͱ΋͍ۙ఺͸ʁ

  19. 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. ۙ๣ͷ໰͍߹Θͤ໰୊ʹͳΔ

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

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

    (x2,y2, …, z2) • ج఺͕มΘΔ • ౎౓ɺڑ཭ܭࢉ͢ΔΘ͚ʹ͸͍͔ͳ͍
  23. ࣅͨྫ໰୊ ࣗ෼ͷϥϯΫʹ͍ۙਓΛ10݅औΓग़͢

  24. ࣅͨྫ໰୊ ࣗ෼ͷϥϯΫʹ͍ۙਓΛ10݅औΓग़͢ ఺ͷදݱ͕ɺ̍ཁૉͷϦετ

  25. ࣅͨྫ໰୊ ࣗ෼ͷϥϯΫʹ͍ۙਓΛ10݅औΓग़͢ ج఺͕มΘΔ ఺ͷදݱ͕ɺ̍ཁૉͷϦετ

  26. ۙ๣ͷ໰͍߹Θͤ໰୊Λղ͘

  27. ؆୯ͳ໰୊͔Βղ͘

  28. Question. ࣗ෼ͷϥϯΫʹ͍ۙ10݅͸ʁ

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

    my.rank - 10 AND my.rank + 10 ORDER BY rank;
  30. sort { abs($a->score - $my->score) <=> abs($b->score - $my->score) }

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

    @ranks; ީิΛऔΓग़͠ߜΓࠐΉ
  32. ̎࣍ݩҎ্ͷۭؒͰ΋ ͜ͷΑ͏ͳ୳ࡧ΁ ؼணͤ͞Δ

  33. ࡯ͨ͠ਓ͸͜ΜͳࣄΛߟ͑Δʁ my $hash = murmur_hash( $json->encode([lat, lng]) );

  34. ΋͏গ͠޻෉͍ͨ͠ • ୯७ʹҢ౓ܦ౓ʹɺHashؔ਺Λ͔͚Δͱ̍఺ Ͱͷ৘ใ͸ಘΒΕΔ͕ɺۙ๣ͷ৘ใ͸ࣦΘΕ ͍ͯΔ • ఺ಉ͕࢜ۙ͘ʹ͋Δ͔ʁͱ͍ͬͨ໰͍߹Θ w w ͤʹ౴͑ΒΕΔϥϯΫ෇͚͕ྑ͍

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

    Code • ࠷খ֎઀୹ܗ(MBR) ͱ R-Tree
  36. ࠲ඪͷϥϯΫؔ਺ͷྫ • 2 x 2 ۭؒͰͷϥϯΫ෇͚    

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

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

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

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

    -> 0 • (0,1) -> 01 -> 1 • (1,0) -> 10 -> 2 • (1,1) -> 11 -> 3        
  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. ࠲ඪͷϥϯΫؔ਺ͷྫ • 2 x 2 ۭؒͰͷϥϯΫ෇͚ • (0,0) -> 00

    -> 0 • (0,1) -> 01 -> 1 • (1,0) -> 10 -> 2 • (1,1) -> 11 -> 3 1 3 2 0 ࠲ඪΛ ̎ਐ਺දݱͱΈͳͯ͠ ͞Βʹ̍̌ਐ਺දݱ͢Δ
  43. ࠲ඪͷϥϯΫؔ਺ͷྫ Q. (1,0) ͔Β ϥϯΫ1Ҏ಺ͷ࠲ඪ͸? 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. ࠲ඪͷϥϯΫؔ਺ͷྫ Q. (1,0) ͔Β ϥϯΫ1Ҏ಺ͷ࠲ඪ͸? A. (1,0) -> 10 ->

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

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

    4 5 6 7 8 ࠲ඪΛ ̏ਐ਺දݱͱΈͳͯ͠ ̍̌ਐ਺දݱ͢Δ
  48. ࠲ඪͷϥϯΫؔ਺ͷྫ • N x N ۭؒͷ৔߹ • Nਐ਺දهΛ10ਐ਺දه

  49. ࠲ඪͷϥϯΫؔ਺ͷྫ • N x N ۭؒͷ৔߹ • Nਐ਺දهΛ10ਐ਺දه • ͦͷଞͷϥϯΫؔ਺ͷྫ

    • Z-ordering
  50. ࣗવ਺ͷϦετͷ ϥϯΫ෇͚͸Ͱ͖ͨ

  51. ͔͠͠

  52. Ң౓ܦ౓ͷදݱ͸ίϨ ౦ژϏοΫαΠτ (latitude,longtitude) = (35.6295764, 139.794686)

  53. Ң౓ܦ౓ͷදݱ͸ίϨ

  54. Ң౓ܦ౓Λ ΋͏গࣗ͠વ਺ʹ ͍ۙܗʹ͢Δ

  55. ͭ·ΓҢ౓ܦ౓ͷ EncodeΛ͍ͨ͠

  56. Ң౓ܦ౓ͷ Encode ͢Δಓ۩ • GeoHex (v1,v2, v3) • GeoHash •

    Open Locatin Code https://github.com/google/open-location-code/ blob/master/docs/comparison.adoc
  57. GeoHex v3 • created by @sa2da • MIT License •

    http://geohex.net/
  58. 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 ϨϕϧΛ্͛Δͱਫ਼౓্͕ঢ
  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 ΄΅ࣗવ਺ͳܗͰ Encode w w
  61. 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. ۙ๣ͷ৘ใ͸Ͳ͏͔ʁ

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

    => $_ )->code for 0..10;
  64. 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
  65. XM XM4 XM48 XM488 XM4885 XM48853 XM488535 XM4885355 XM48853551 XM488535511

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

    XM4885355114 ֦େϨϕϧʢਫ਼౓ʣΛ্͛Δ ͱɺίʔυ͕ܻ͚̍ͩ૿͑Δ
  67. ۙ๣΋େৎ෉ʂ

  68. ͳͷͰ

  69. ݱࡏ஍͔Β΋ͬͱ΋͍ۙӺ͸ʁ

  70. None
  71. None
  72. SELECT name FROM station WHERE geohex LIKE ‘XM4885355114’ # =>

    Empty set
  73. SELECT name FROM station WHERE geohex LIKE ‘XM488535511_’ # =>

    Empty set
  74. SELECT name FROM station WHERE geohex LIKE ‘XM48853551__’ # =>

    Empty set
  75. SELECT name FROM station WHERE geohex LIKE ‘XM4885355___’ # =>

    Empty set
  76. SELECT name FROM station WHERE geohex LIKE ‘XM488535____’ # =>

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

    テレコムセンター 船の科学館 青海 国際展示場正門 新木場
  78. ݱࡏ஍͔Β΋ͬͱ΋͍ۙӺ͸ʁ A. ࠃࡍలࣔ৔ਖ਼໳

  79. GeoHex v3 Encodeʹ͍ͭͯ

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

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

    = longtitude * R / 180; y = ln(tan((90 + latitude) * pi / 360)) * (pi / 180) * R / 180 R = ஍ٿͷ൒ܘ = 20037508.34
  82. GeoHex v3 Encodeʹ͍ͭͯ

  83. None
  84. None
  85. None
  86. None
  87. None
  88. None
  89. GeoHex v3 ͷ࠾൪ϧʔϧ

  90. GeoHex v3 ͷ࠾൪ϧʔϧ 3x3ͷਖ਼࿡֯ܗ͕ ࠾൪ͷܻ̍ΛܾΊΔ

  91. GeoHex v3 ͷ࠾൪ϧʔϧ

  92. GeoHex v3 ͷ࠾൪ϧʔϧ

  93. GeoHex v3 ͷ࠾൪ϧʔϧ ࠲ඪΛ 3ਐ਺දهͱΈͳͯ͠ ̍̌ਐ਺දݱ

  94. GeoHex v3 ͷϨϕϧࠩ

  95. GeoHex v3 ͷϨϕϧࠩ ̏ഒͷαΠζͷਖ਼࿡֯ܗ͕ ্̍ͭͷϨϕϧʹͳΔ

  96. GeoHex v3 ͷಛ௃ • Ϛεͷݸ਺Ͱڑ཭දݱͰ͖Δ • ྡΓ߹͏Ϛε໨͕දݱ͠΍͍͢

  97. ·ͱΊ

  98. ·ͱΊ • ۙ๣ͷ໰͍߹Θ͕ͤయܕతͳཁ݅ • Ң౓ܦ౓ͷϥϯΫ෇͚ͷख๏঺հ • ਐ਺ͷಡΈସ͑ • GeoHex

  99. ϞόΠϧϑΝΫτϦʔ͸ ۭؒ৘ใʹڵຯͷ͋Δ ΤϯδχΞืूதͰ͢!