{"id":4280,"date":"2015-05-28T19:16:09","date_gmt":"2015-05-28T10:16:09","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=4280"},"modified":"2015-05-28T19:59:41","modified_gmt":"2015-05-28T10:59:41","slug":"post-4280","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/d3-js\/4280","title":{"rendered":"\u3010D3.js\u3011\u4e16\u754c\u5730\u56f3\u753b\u50cf\u3092\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30b5\u30a4\u30c9\u3067\u518d\u6295\u5f71\u51e6\u7406\u3059\u308b"},"content":{"rendered":"<p><a href=\"http:\/\/shimz.me\/example\/d3js\/geo_example3\/ReProjections\/\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/05\/reprojection150528.jpg\" alt=\"reprojection\" width=\"552\" height=\"619\" class=\"aligncenter size-full wp-image-4281\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/05\/reprojection150528.jpg 552w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/05\/reprojection150528-134x150.jpg 134w\" sizes=\"auto, (max-width: 552px) 100vw, 552px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/d3js\/geo_example3\/ReProjections\/\">example<\/a><\/p>\n<p>\u6b63\u8ddd\u5186\u7b52\u56f3\u6cd5\u3067\u4f5c\u6210\u3055\u308c\u305f\u4e16\u754c\u5730\u56f3\u753b\u50cf\u3092\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074\u3067\u4ed6\u306e\u6295\u5f71\u6cd5\u3078\u5909\u63db\u3057\u51fa\u529b\u3057\u307e\u3059\u3002<br \/>\n\u7d50\u69cb\u8ca0\u8377\u304c\u9ad8\u3044\u3067\u3059\u3002<\/p>\n<h2>\u30b5\u30f3\u30d7\u30eb<\/h2>\n<p>\u6982\u8981\u3092\u7c21\u5358\u306b\u8aac\u660e\u3059\u308b\u3068\u3001d3.geo.projection\u306e\u7def\u5ea6\u7d4c\u5ea6\u21d4pixcel\u5ea7\u6a19\u306e\u5909\u63db\u6a5f\u80fd\u3092\u4f7f\u3063\u3066\u4ee5\u4e0b\u306e\u51e6\u7406\u3092\u884c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\uff11\uff0e\u6295\u5f71\u6cd5\uff21\u3092\u4f7f\u3063\u3066\u30bd\u30fc\u30b9\u753b\u50cf\u306epixcel\u5ea7\u6a19\u3092\u3059\u3079\u3066\u7def\u5ea6\u7d4c\u5ea6\u306b\u5909\u63db\u3002<br \/>\n\uff12\uff0e\u5909\u63db\u3057\u305f\u7def\u5ea6\u7d4c\u5ea6\u3092\u6295\u5f71\u6cd5\uff22\u3092\u4f7f\u3063\u3066\u30bf\u30fc\u30b2\u30c3\u30c8\u753b\u50cf\u306epixcel\u306e\u5ea7\u6a19\u306b\u5909\u63db\u3002<br \/>\n\uff13\uff0e\u30bd\u30fc\u30b9\u753b\u50cf\u306epixcel\u5ea7\u6a19\u304b\u3089\u8272\u60c5\u5831\u3092\u53d6\u5f97\u3057\u3001\u30bf\u30fc\u30b2\u30c3\u30c8\u753b\u50cf\u306epixcel\u306e\u5ea7\u6a19\u306b\u30b3\u30d4\u30fc\u3059\u308b\u3002<br \/>\n\uff14\uff0e\u30bf\u30fc\u30b2\u30c3\u30c8\u753b\u50cf\u3092\u51fa\u529b\u3002<\/p>\n<pre class=\"lang:js decode:true \" >d3.select(\"#projection\").on(\"change\", function(){\r\n\tdraw(this.value);\r\n});\r\n\r\nvar width = 540;\r\nvar height = 270;\r\n\r\nvar div = d3.select('#reprojection_output');\r\nvar canvas = div.append('canvas')\r\n\t.attr('width', width)\r\n\t.attr('height', height);\r\n\r\nvar context = canvas.node().getContext('2d');\r\n\r\nvar sourceProjection  = d3.geo.equirectangular()\r\n\t.scale(width \/ (2 * Math.PI))\r\n\t.translate([width \/ 2, height \/ 2]);\r\n\r\n \r\n \/\/ \u753b\u50cf\u8981\u7d20\u8aad\u307f\u8fbc\u307f\r\nvar image = new Image(width, height);\r\nimage.onload = function(){\r\n\tdocument.querySelector(\"#projection\").dispatchEvent(new Event('change'));\r\n};\r\nimage.src = 'readme-blue-marble.jpg';\r\n\r\n\r\nfunction draw(select_projection) {\r\n\t var targetProjection = d3.geo[select_projection]()\r\n\t\t .scale(Math.sqrt(1) * height \/ Math.PI )\r\n\t\t .translate([width \/ 2, height \/ 2])\r\n\r\n\t \/\/ \u30ad\u30e3\u30f3\u30d0\u30b9\u306b\u753b\u50cf\u3092\u30b3\u30d4\u30fc\u3059\u308b\r\n\t context.drawImage(image, 0, 0, image.width, image.height);\r\n\r\n\t \/\/ \u30ad\u30e3\u30f3\u30d0\u30b9\u304b\u3089\u30a4\u30e1\u30fc\u30b8\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\r\n\t var sourceData = context.getImageData(0, 0, image.width, image.height).data;\r\n\r\n\t \/\/\u7a7a\u306e\u30bf\u30fc\u30b2\u30c3\u30c8\u30a4\u30e1\u30fc\u30b8\u3092\u751f\u6210\r\n\t var target = context.createImageData(image.width, image.height),\r\n\t\t targetData = target.data;\r\n\r\n\t \/\/ \u30bf\u30fc\u30b2\u30c3\u30c8\u753b\u50cf\u3092ipixcel\u6bce\u306b\u5909\u63db\u51e6\u7406\u3092\u884c\u3046\r\n\t for (var x = 0, w = image.width; x &lt; w; x += 1) {\r\n\t\tfor (var y = 0, h = image.height; y &lt; h; y += 1) {\r\n\r\n\t\t\t \/\/ \u5909\u63db\u3059\u308b\u6295\u5f71\u6cd5\u3092\u7528\u3044\u3066\u30ab\u30ec\u30f3\u30c8\u30d4\u30af\u30bb\u30eb\u306e\u5730\u7406\u5ea7\u6a19\u3092\u8a08\u7b97\r\n\t\t\t var coords = targetProjection.invert([x, y]);\r\n\r\n\t\t\t var targetIndex;\r\n\t\t\t var sourceIndex;\r\n\t\t\t var pixels;\r\n\r\n\t\t\t \/\/ \u5730\u7406\u5ea7\u6a19\u304c\u672a\u5b9a\u7fa9\u3067\u8fd4\u3063\u3066\u304d\u305f\u5834\u5408\u306f\u30b9\u30eb\u30fc\r\n\t\t\t if ((!isNaN(coords[0])) &amp;&amp; (!isNaN(coords[1]))) {\r\n\t\t\t\t \/\/\u7bc4\u56f2\u5916\u3092\u5857\u308a\u3064\u3076\u3055\u306a\u3044\u3088\u3046\u306b\u3068\u3070\u3059\r\n\t\t\t\t var \u03bb = coords[0], \u03c6 = coords[1];\r\n\t\t\t\t if (\u03bb &gt; 180 || \u03bb &lt; -180 || \u03c6 &gt; 90 || \u03c6 &lt; -90) { continue; }\r\n\r\n\r\n\t\t\t\t \/\/ \u5143\u306e\u6295\u5f71\u6cd5\u3092\u7528\u3044\u3066\u5730\u7406\u5ea7\u6a19\u3092\u8a08\u7b97\r\n\t\t\t\t pixels = sourceProjection (coords);\r\n\r\n\t\t\t\t \/\/ \u30bd\u30fc\u30b9\uff06\u30bf\u30fc\u30b2\u30c3\u30c8\u30d4\u30af\u30bb\u30eb\u306e\u30ec\u30c3\u30c9\u30c1\u30e3\u30cd\u30eb\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u8a08\u7b97\r\n\t\t\t\t sourceIndex = 4 * (Math.floor(pixels[0]) + w * Math.floor(pixels[1]));\r\n\t\t\t\t sourceIndex = sourceIndex - (sourceIndex % 4);\r\n\t\t\t\t targetIndex = 4 * (x + w * y);\r\n\t\t\t\t targetIndex = targetIndex - (targetIndex % 4);\r\n\r\n\t\t\t\t \/\/\u8d64\u3001\u7dd1\u3001\u9752\u3001\u30a2\u30eb\u30d5\u30a1\u30c1\u30e3\u30f3\u30cd\u30eb\u3092\u30b3\u30d4\u30fc\u3059\u308b\r\n\t\t\t\t targetData[targetIndex]     = sourceData[sourceIndex];\t\/\/\u30ec\u30c3\u30c9\u30c1\u30e3\u30f3\u30cd\u30eb\r\n\t\t\t\t targetData[targetIndex + 1] = sourceData[sourceIndex + 1];\r\n\t\t\t\t targetData[targetIndex + 2] = sourceData[sourceIndex + 2];\r\n\t\t\t\t targetData[targetIndex + 3] = sourceData[sourceIndex + 3];\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t \/\/ canvas\u8981\u7d20\u3092\u30af\u30ea\u30a2\u3057\u3066\u3001\u5bfe\u8c61\u753b\u50cf\u3092\u30b3\u30d4\u30fc\u3059\u308b\r\n\tcontext.clearRect(0, 0, image.width, image.height);\r\n\tcontext.putImageData(target, 0, 0);\r\n}<\/pre>\n<h2>\u304a\u307e\u3051<\/h2>\n<p>NASA\u304c\u63d0\u4f9b\u3057\u3066\u3044\u308b\u96f2\u91cf\u5730\u56f3\u753b\u50cf\u3067\u3082\u3084\u3063\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\n<a href=\"http:\/\/neo.sci.gsfc.nasa.gov\/view.php?datasetId=MODAL2_M_CLD_FR\">Cloud Fraction (1 month &#8211; Terra\/MODIS) | NASA<\/a><\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/d3js\/geo_example3\/ReProjections\/cloud_fraction.html\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/05\/cloud_fraction150528.jpg\" alt=\"cloud fraction\" width=\"548\" height=\"637\" class=\"aligncenter size-full wp-image-4282\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/05\/cloud_fraction150528.jpg 548w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/05\/cloud_fraction150528-129x150.jpg 129w\" sizes=\"auto, (max-width: 548px) 100vw, 548px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/d3js\/geo_example3\/ReProjections\/cloud_fraction.html\">example<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>example \u6b63\u8ddd\u5186\u7b52\u56f3\u6cd5\u3067\u4f5c\u6210\u3055\u308c\u305f\u4e16\u754c\u5730\u56f3\u753b&hellip;<\/p>\n","protected":false},"author":1,"featured_media":4281,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[56,18],"tags":[],"class_list":["post-4280","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-canvas","category-d3-js","has-post-thumbnail-archive"],"_links":{"self":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/4280","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=4280"}],"version-history":[{"count":0,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/4280\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/4281"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=4280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=4280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=4280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}