python-geohex
- 3. python-geohex GeoHex v2 の Python ポート aita 作成 https://bitbucket.org/__aita__/python-geohex からダウンロード出来るよ PyPI には上がってないよ ......
- 5. GeoHex twitter id: @sa2da により作られた仕様 JavaScript が用意されている aita がポートしたのは v2 の JavaScript 仕様自体がクリエイティブ?コモンズ 詳しくは、ぐぐれ。。
- 10. v2 の特徴 日本地図のみだった v1 の世界地図対応版 レベル(ヘックスサイズ)が大陸クラスの広範囲( Level:0 )?約 1m クラス 60cm の小範囲( Level:24 )まで 25 段階 各レベル間のヘックスサイズ(直径)は常に二分割(面積比 1:4 )で変化する コードは 3 桁? 1311 桁。広範囲ほど桁数が少なくなる
- 11. GeoHex 注意点 バージョンが v1, v2, v3 ってあるよ バージョン同士で互換性がないよ python-geohex は v2 しか無いよ v1 はもういらねんじゃね? v3 はまだ JavaScript 版に不具合があった(ポートした当時) 緯度が高すぎるとだめだよ ( v2 の場合 85 度くらいまで) v1, v2 と v3 でコーディングの仕方が違うよ
- 14. (function (win) { // グローバルを汚さないように関数化 // namspace GeoHex; if (!win.GeoHex) win.GeoHex = function(){}; // version: 2.03 GeoHex.version = "2.03"; // *** Share with all instances *** var h_key = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; var h_base = 20037508.34; var h_deg = Math.PI*(30/180); var h_k = Math.tan(h_deg); // private static var _zoneCache = {};
- 15. var h_l = xy2loc(h_x - 2 * h_size, h_y).lon; var h_r = xy2loc(h_x + 2 * h_size, h_y).lon; var h_cl = xy2loc(h_x - 1 * h_size, h_y).lon; var h_cr = xy2loc(h_x + 1 * h_size, h_y).lon; return [ {lat: h_lat, lon: h_l}, {lat: h_top, lon: h_cl}, {lat: h_top, lon: h_cr}, {lat: h_lat, lon: h_r}, {lat: h_btm, lon: h_cr}, {lat: h_btm, lon: h_cl} ]; };
- 16. // var h_x_100000 = Math.floor(h_x_abs/777600000); var h_x_10000 = Math.floor((h_x_abs%777600000)/12960000); var h_x_1000 = Math.floor((h_x_abs%12960000)/216000); var h_x_100 = Math.floor((h_x_abs%216000)/3600); var h_x_10 = Math.floor((h_x_abs%3600)/60); var h_x_1 = Math.floor((h_x_abs%3600)%60); // var h_y_100000 = Math.floor(h_y_abs/777600000); var h_y_10000 = Math.floor((h_y_abs%777600000)/12960000); var h_y_1000 = Math.floor((h_y_abs%12960000)/216000); var h_y_100 = Math.floor((h_y_abs%216000)/3600); var h_y_10 = Math.floor((h_y_abs%3600)/60); var h_y_1 = Math.floor((h_y_abs%3600)%60); if(h_max >=60/2) h_code += h_key.charAt(h_x_10) + h_key.charAt(h_y_10); h_code += h_key.charAt(h_x_1) + h_key.charAt(h_y_1); if (!!_zoneCache[h_code]) return _zoneCache[h_code]; return (_zoneCache[h_code] = new Zone(z_loc_y, z_loc_x, h_x, h_y, h_code));
- 17. if (h_max >= 12960000 / 2) { h_x = h_key.indexOf(code.charAt(1)) * 12960000 + h_key.indexOf(code.charAt(3)) * 216000 + h_key.indexOf(code.charAt(5)) * 3600 + h_key.indexOf(code.charAt(7)) * 60 + h_key.indexOf(code.charAt(9)); h_y = h_key.indexOf(code.charAt(2)) * 12960000 + h_key.indexOf(code.charAt(4)) * 216000 + h_key.indexOf(code.charAt(6)) * 3600 + h_key.indexOf(code.charAt(8)) * 60 + h_key.indexOf(code.charAt(10)); } else if (h_max >= 216000 / 2) { h_x = h_key.indexOf(code.charAt(1)) * 216000 + h_key.indexOf(code.charAt(3)) * 3600 + h_key.indexOf(code.charAt(5)) * 60 + h_key.indexOf(code.charAt(7)); h_y = h_key.indexOf(code.charAt(2)) * 216000 + h_key.indexOf(code.charAt(4)) * 3600 + h_key.indexOf(code.charAt(6)) * 60 + h_key.indexOf(code.charAt(8));
- 24. ここがだめだよ python-geohex aita が GeoHex のコーディングで何やってるかわかってない。 関数の名前がきもいかも __eq__ のどうさがおかしくなるかも。。 ドキュメントがない。。。
- 27. class RandomZoneTest(unittest.TestCase): def testLocationToCode(self): for i in range(10000): lat = 85 * random.random() lon = 85 * random.random() level = random.randint(0,24) zone = geohex2.get_zone_by_location(lat, lon, level) code_zone = geohex2.get_zone_by_code(zone.code) self.assertEqual(zone, code_zone) def testLocationToXY(self): for i in range(10000): lat = 90 * random.random() lon = 90 * random.random() level = random.randint(0,24) zone = geohex2.get_zone_by_location(lat, lon, level) xy_zone = geohex2.get_zone_by_xy(zone.x, zone.y, zone.level) self.assertEqual(zone, xy_zone) こんなかんじ de