{"id":4168,"date":"2015-03-26T12:49:58","date_gmt":"2015-03-26T03:49:58","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=4168"},"modified":"2015-03-26T17:32:59","modified_gmt":"2015-03-26T08:32:59","slug":"post-4168","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/node-js\/4168","title":{"rendered":"[Turf.js]node.js\u3068turf\u3067\u91cd\u3044\u7d71\u8a08\u51e6\u7406\u3092\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u3067\u884c\u3046\u3002"},"content":{"rendered":"<p><a href=\"http:\/\/shimz.me\/example\/turf\/backend\/hex\/\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/kyoju000016.jpg\" alt=\"turf  and node test\" width=\"700\" height=\"498\" class=\"aligncenter size-full wp-image-4171 border\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/kyoju000016.jpg 700w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/kyoju000016-211x150.jpg 211w\" sizes=\"auto, (max-width: 700px) 100vw, 700px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/turf\/backend\/hex\/\">example<\/a><\/p>\n<p>\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u3067\u884c\u3046\u306b\u306f\u91cd\u3044\u7d71\u8a08\u51e6\u7406\u3092\u30d0\u30c3\u30af\u30a8\u30f3\u30c9\u3067\u884c\u3044\u3001\u51fa\u529b\u3055\u308c\u305f\u7d71\u8a08\u51e6\u7406\u6e08\u30c7\u30fc\u30bf\u3092\u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u3067\u8868\u793a\u3059\u308b\u3063\u3066\u306e\u3092\u3084\u3063\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n<h2>\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n<p>\u300cturf\u300d\u3068\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u3067\u306e\u5f15\u6570\u306e\u51e6\u7406\u3092\u884c\u3046\u30e9\u30a4\u30d6\u30e9\u30ea\u300cargv\u300d\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:sh decode:true \" >&gt; npm install turf\r\n&gt; npm install argv<\/pre>\n<p>\u4eca\u56de\u306f\u300c<a href=\"http:\/\/tenbou.nies.go.jp\/gis\/\">\u74b0\u5883GIS<\/a>\u300d\u304b\u3089\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u305f2013\u5e74\u5ea6\u306e\u300c\u5168\u56fd\u306e\u81ea\u52d5\u8eca\u4ea4\u901a\u9a12\u97f3\u306e\u6e2c\u5b9a\u7d50\u679c\u300d\u3092\u30dd\u30a4\u30f3\u30c8\u30c7\u30fc\u30bf\u306b\u5909\u63db\u3057\u30d8\u30c3\u30af\u30b9\u30b0\u30ea\u30c3\u30c9\u3092\u6577\u304d\u8a70\u3081\u3066\u5404\u30bb\u30eb\u306b\u542b\u307e\u308c\u308b\u30dd\u30a4\u30f3\u30c8\u306e\u300cLeq\u663c\u9593(dB)\u300d\u306e\u5024\u304b\u3089\u4e2d\u592e\u5024\u3092\u7b97\u51fa\u3057\u307e\u3059\u3002<\/p>\n<p>\u5bfe\u8c61\u3068\u3059\u308b\u30dd\u30a4\u30f3\u30c8\u30c7\u30fc\u30bf\u306f3531\u500b\u6240\u3001\u30d8\u30c3\u30af\u30b9\u3092\u6577\u304d\u8a70\u3081\u308b\u7bc4\u56f2\u306f\u672c\u5dde\u304a\u3088\u3073\u5317\u6d77\u5ea6\u304c\u542b\u307e\u308c\u308b\u7bc4\u56f2\u3067\u3059\u3002<\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/turf\/backend\/hex\/point.geojson\">point.geojson<\/a><\/p>\n<h2>\u30b5\u30f3\u30d7\u30eb<\/h2>\n<pre class=\"lang:js decode:true \" >var argv = require('argv');\r\nvar turf = require('turf');\r\nvar fs = require('fs');\r\n\r\n\/\/ -i \u8aad\u307f\u8fbc\u3080\u30dd\u30a4\u30f3\u30c8\u30c7\u30fc\u30bf\u3092\u6307\u5b9a\r\nargv.option({\r\n\tname: 'input',\r\n\tshort: 'i',\r\n\ttype : 'path',\r\n\tdescription :'\u8aad\u307f\u8fbc\u3080\u30d5\u30a1\u30a4\u30eb\u540d(point)\u3092\u6307\u5b9a\u3057\u307e\u3059',\r\n\texample: \"'script --option=value' or 'script -i filename(point)'\"\r\n});\r\n\r\n\/\/ -s \u30d8\u30c3\u30af\u30b9\u6bce\u306e\u30b5\u30a4\u30ba\u3092\u6307\u5b9a\r\nargv.option({\r\n\tname: 'size',\r\n\tshort: 's',\r\n\ttype : 'number',\r\n\tdescription :'\u30d8\u30c3\u30af\u30b9\u306e\u30b5\u30a4\u30ba(km)\u3092\u6307\u5b9a\u3057\u307e\u3059',\r\n\texample: \"'script --option=value' or 'script -s number'\"\r\n});\r\n\r\nvar argvv = argv.run();\r\nvar input = argvv.options.input;\r\nvar size = argvv.options.size;\r\n\r\n\/\/\u5f15\u6570\u30c1\u30a7\u30c3\u30af\r\nif (!input) {\r\n  console.log(\"\u5f15\u6570\u304c\u6b63\u3057\u304f\u5165\u529b\u3055\u308c\u3066\u3044\u307e\u305b\u3093:\" +\u3000\" \u8aad\u307f\u8fbc\u3080geojson\u30d5\u30a1\u30a4\u30eb\u3092-i\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u6307\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044\");\r\n  process.exit();\r\n}\r\nif (!size) {\r\n  console.log(\"\u5f15\u6570\u304c\u6b63\u3057\u304f\u5165\u529b\u3055\u308c\u3066\u3044\u307e\u305b\u3093:\" +\u3000\" \u30d8\u30c3\u30af\u30b9\u306e\u30b5\u30a4\u30ba\u3092\u3092-s\u30aa\u30d7\u30b7\u30e7\u30f3\u3067\u6307\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044\");\r\n  process.exit();\r\n}\r\n\r\n\r\n\r\nfs.readFile(input, 'utf8', function (err, data) {\r\n\tvar points = JSON.parse(data);\r\n\t\/\/hex\u3092\u6577\u304d\u8a70\u3081\u308b\u7bc4\u56f2\r\n\tvar extend = [126.5942359828125,29.685822563270666, 152.8295875453125, 45.59686948624793];\r\n\t\r\n\t\/\/\u7bc4\u56f2\u5185\u306bhexgrid\u3092\u6577\u304d\u8a70\u3081\u308b\r\n\tvar grid = turf.hexGrid(extend,  size, \"kilometers\");\r\n\t\r\n\t\/\/hexgrid\u306e\u30bb\u30eb\u6bce\u306b\u3001\u30bb\u30eb\u5185\u306b\u542b\u307e\u308c\u308b\u30dd\u30a4\u30f3\u30c8\u30c7\u30fc\u30bf\u306e\u7d71\u8a08\u51e6\u7406\u3092\u884c\u3046\u3002\r\n\t\/\/\u4eca\u56de\u306f\u3001\u5404\u30bb\u30eb\u5185\u306e\u30dd\u30a4\u30f3\u30c8\u30c7\u30fc\u30bf\u304b\u3089\u300cLeq\u663c\u9593(dB)\u300d\u306e\u4e2d\u592e\u5024\u3092\u7b97\u51fa\u3059\u308b\r\n\tvar grid = turf.median(grid, points, \"Leq\u663c\u9593(dB)\", \"pt_median\");\r\n\t\r\n\tconsole.log(JSON.stringify(grid))\t\r\n});\r\n<\/pre>\n<h2>\u5b9f\u884c<\/h2>\n<p>\u30b3\u30de\u30f3\u30c9\u30d7\u30ed\u30f3\u30d7\u30c8\u3067\u30dd\u30a4\u30f3\u30c8\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u8fbc\u307f\u30d8\u30c3\u30af\u30b9\u306e\u30b5\u30a4\u30ba(km)\u3092\u6307\u5b9a\u3057\u3066\u5b9f\u884c\u3057\u307e\u3059\u3002<br \/>\n\u4f8b\u3068\u3057\u306650km\u5358\u4f4d\u306e\u30d8\u30c3\u30af\u30b9\u3067\u7d71\u8a08\u51e6\u7406\u3092\u884c\u3046\u5834\u5408\u306f\u4ee5\u4e0b\u3068\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:sh decode:true \" >&gt; node hextest.js -i point.geojson -s 50 &gt; hex50.geojson<\/pre>\n<h2>\u51e6\u7406\u6642\u9593<\/h2>\n<p>\u30d8\u30c3\u30af\u30b9\u30b0\u30ea\u30c3\u30c9\u3092\u6577\u304d\u8a70\u3081\u308b\u7bc4\u56f2\u306b\u5bfe\u3057\u3066\u30d8\u30c3\u30af\u30b9\u306e\u30b5\u30a4\u30ba\u3092\u5c0f\u3055\u304f\u3059\u308b\u3068(\u30bb\u30eb\u306e\u6570\u304c\u5897\u3048\u308b\u3068)\u5f53\u7136\u3001\u7d71\u8a08\u51e6\u7406\u306b\u304b\u304b\u308b\u6642\u9593\u306f\u5897\u3048\u307e\u3059\u3002\u4ee5\u4e0b\u306f\u4eca\u56de\u8a66\u3057\u3066\u307f\u305f\u7d50\u679c\u3067\u3059\u3002<\/p>\n<pre class=\"lang:tex decode:true \" >\u30fb\u5bfe\u8c61\u30dd\u30a4\u30f3\u30c8\u6570\r\n3531 point\r\n\r\n\u30fb\u30b9\u30da\u30c3\u30af\r\nOS:  Windows 8.1\r\nCPU: intel Core i5-3470 3.20GHz\r\nRAM: 8.00 GB\r\n\r\n\r\n\r\n\u30fb\u5b9f\u884c\u7d50\u679c\r\n100km Hex\r\n 0.316 sec.\t\/\/hexgrid\u751f\u6210\u306b\u304b\u304b\u3063\u305f\u6642\u9593\r\n 0.84 sec.\t\/\/\u7d71\u8a08\u51e6\u7406\u306b\u304b\u304b\u3063\u305f\u6642\u9593\r\n output 235KB\t\/\/\u51fa\u529b\u3055\u308c\u308bhex\u30c7\u30fc\u30bf\u306e\u30b5\u30a4\u30ba\r\n\r\n\r\n50km Hex\r\n 0.318 sec.\r\n 2.215 sec.\r\n output 890KB\r\n\r\n25km Hex\r\n 0.324 sec.\r\n 7.795 sec.\r\n output 3,531KB\r\n\r\n\r\n10km Hex\r\n 0.372 sec.\r\n 45.525 sec.\r\noutput 21,818KB\r\n\r\n5km Hex\r\n 0.579 sec.\r\n 185.835 sec.\r\n output 87,101KB<\/pre>\n<h2>\u8868\u793a\u3057\u3066\u307f\u305f<\/h2>\n<p>100km HEX<br \/>\n<a href=\"http:\/\/shimz.me\/example\/turf\/backend\/hex\/hex100km.html\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/nodeandturf1503262.jpg\" alt=\"turf HexGrid 100km\" width=\"690\" height=\"488\" class=\"aligncenter size-full wp-image-4170 border\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/nodeandturf1503262.jpg 690w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/nodeandturf1503262-212x150.jpg 212w\" sizes=\"auto, (max-width: 690px) 100vw, 690px\" \/><\/a><br \/>\n<a href=\"http:\/\/shimz.me\/example\/turf\/backend\/hex\/hex100km.html\">example<\/a><\/p>\n<p>25km HEX<br \/>\n<a href=\"http:\/\/shimz.me\/example\/turf\/backend\/hex\/hex25km.html\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/nodeandturf1503261.jpg\" alt=\"turf HexGrid 25km\" width=\"690\" height=\"489\" class=\"aligncenter size-full wp-image-4169 border\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/nodeandturf1503261.jpg 690w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/nodeandturf1503261-212x150.jpg 212w\" sizes=\"auto, (max-width: 690px) 100vw, 690px\" \/><\/a><br \/>\n<a href=\"http:\/\/shimz.me\/example\/turf\/backend\/hex\/hex25km.html\">example<\/a><\/p>\n<h2>\u7d71\u8a08\u51e6\u7406\u3092\u77ed\u304f\u3059\u308b<\/h2>\n<p>\u6d77\u306e\u4e0a\u307e\u3067\u30d8\u30c3\u30af\u30b9\u3092\u6577\u304d\u8a70\u3081\u308b\u306e\u306f\u7121\u99c4\u304c\u591a\u3044\u3002\u4eca\u56de\u306e\u5834\u5408\u306a\u3089\u3001\u5148\u306b\u65e5\u672c\u306e\u5730\u5f62\u30c7\u30fc\u30bf(\u30dd\u30ea\u30b4\u30f3)\u3092\u7528\u610f\u3057\u3066\u304a\u3044\u3066\u30d8\u30c3\u30af\u30b9\u30b0\u30ea\u30c3\u30c9\u3068intersect\u3068\u3055\u305b\u3066\u3001\u65e5\u672c\u5217\u5cf6\u4e0a\u306e\u30d8\u30c3\u30af\u30b9\u3060\u3051\u53d6\u308a\u51fa\u3057\u3066\u304b\u3089\u7d71\u8a08\u51e6\u7406\u3092\u884c\u3048\u3070\u304b\u306a\u308a\u8a08\u7b97\u91cf\u304c\u6e1b\u3089\u305b\u308b\u3068\u601d\u3046\u306e\u3067\u3001\u3042\u3068\u3067\u8a66\u3057\u3066\u307f\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>example \u30d5\u30ed\u30f3\u30c8\u30a8\u30f3\u30c9\u3067\u884c\u3046\u306b\u306f\u91cd\u3044\u7d71\u8a08\u51e6&hellip;<\/p>\n","protected":false},"author":1,"featured_media":4171,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[55,5,62],"tags":[],"class_list":["post-4168","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-leaflet-js","category-node-js","category-turf-js","has-post-thumbnail-archive"],"_links":{"self":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/4168","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/comments?post=4168"}],"version-history":[{"count":0,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/4168\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/4171"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=4168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=4168"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=4168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}