{"id":4131,"date":"2015-03-10T12:38:42","date_gmt":"2015-03-10T03:38:42","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=4131"},"modified":"2015-03-12T22:22:49","modified_gmt":"2015-03-12T13:22:49","slug":"post-4131","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/d3-js\/4131","title":{"rendered":"GeoJSON\u3092\u8efd\u304f\u3059\u308b\u3060\u3051\u3058\u3083\u306a\u3044\uff01\u3000TopoJSON\u30af\u30e9\u30a4\u30a2\u30f3\u30c8 TIPS"},"content":{"rendered":"<p>\u5358\u7d14\u306b\u3001GeoJSON\u5f62\u5f0f\u306e\u30c7\u30fc\u30bf\u3092\u52b9\u7387\u3088\u304f\u5727\u7e2e\u3057\u3066\u30d5\u30a1\u30a4\u30eb\u30b5\u30a4\u30ba\u3092\u8efd\u304f\u3059\u308b\u3082\u306e\u3068\u3089\u3048\u3089\u308c\u304c\u3061\u306eTopoJSON\u3067\u3059\u304c\u3001\u5b9f\u306fTopoJSON\u306b\u306f\u69d8\u3005\u306a\u6a5f\u80fd\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u4eca\u56de\u306f\u305d\u306e\u4e2d\u304b\u3089\u3001\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074\u300ctopojson.js\u300d\u3067\u5229\u7528\u3067\u304d\u308b\u6a5f\u80fd\u306e\u4e00\u90e8\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/github.com\/mbostock\/topojson\/wiki\">Home \u00b7 mbostock\/topojson Wiki<\/a><\/p>\n<h2>topojson.neighbors<\/h2>\n<p>neighbors\u30e1\u30bd\u30c3\u30c9\u306b\u3064\u3044\u3066\u306f\u4ee5\u524d\u8a18\u4e8b\u306b\u3057\u305f\u306e\u3067\u7701\u7565\u3002\u57fa\u672c\u7684\u306b\u306f\u3001\u3053\u306e\u30e1\u30bd\u30c3\u30c9\u306bTopoJSON\u306e\u30c7\u30fc\u30bf\u3092\u6e21\u3057\u3066\u3042\u3052\u308b\u3068\u3001\u5404\u30dd\u30ea\u30b4\u30f3\u6bce\u306b\u96a3\u63a5\u3059\u308b\u30dd\u30ea\u30b4\u30f3\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306e\u5024\u3092\u914d\u5217\u3068\u3057\u3066\u8fd4\u3057\u3066\u304f\u308c\u307e\u3059\u3002<br \/>\n<a href=\"https:\/\/gunmagisgeek.com\/blog\/d3-js\/3489\">\u3010D3.js\u3011\u96a3\u63a5\u3059\u308b\u533a\u753b\u3092\u8868\u793a\u3059\u308b <\/a><\/p>\n<h2>topojson.mesh<\/h2>\n<p>\u304b\u3044\u3064\u307e\u3093\u3067\u8a00\u3046\u3068\u3001TopoJSON\u306e\u30c7\u30fc\u30bf\u3092\u53d7\u3051\u53d6\u3063\u3066\u4e00\u672c\u306e\u30d1\u30b9\u30b9\u30c8\u30ea\u30f3\u30b0(svg\/path\u306ed\u8981\u7d20\u306b\u6e21\u3059\u5024)\u3068\u3057\u3066\u8fd4\u3059\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002<br \/>\n\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u3092\u4f7f\u3063\u3066\u30d5\u30a3\u30eb\u30bf\u30ea\u30f3\u30b0\u3092\u884c\u3046\u3053\u3068\u3067\u3001\u96a3\u63a5\u3059\u308b\u30d1\u30b9\u3068\u5358\u72ec\u306e\u30d1\u30b9\u3092\u5206\u3051\u3066\u51fa\u529b\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u5730\u5f62\u306e\u5916\u5468\u3068\u5883\u754c\u3067\u8868\u73fe\u3092\u5909\u3048\u305f\u3044\u3068\u304d\u306b\u7b49\u4fbf\u5229\u3002<br \/>\n\u4e0b\u8a18\u306f\u5916\u5468\u3092\u9752\u3001\u5883\u754c\u3092\u8d64\u3067\u8868\u793a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/d3js\/topojson\/mesh\/index.html\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/topojsontips15031011.jpg\" alt=\"topojson \u30e1\u30c3\u30b7\u30e5\" width=\"590\" height=\"439\" class=\"alignnone size-full wp-image-4135 border\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/topojsontips15031011.jpg 590w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/topojsontips15031011-202x150.jpg 202w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/d3js\/topojson\/mesh\/index.html\">example<\/a><\/p>\n<pre class=\"lang:js decode:true \" >d3.json(\"..\/..\/_geodata\/ken.topojson\", function(json) {\r\n\tdraw(json);\r\n});\r\n\r\n\r\nfunction draw(json){\r\n\t\r\n\tvar projection = d3.geo\r\n\t\t.mercator()\t\t\/\/\u6295\u5f71\u6cd5\u306e\u6307\u5b9a\r\n\t\t.scale(2000)\t\/\/\u30b9\u30b1\u30fc\u30eb\uff08\u30ba\u30fc\u30e0\uff09\u306e\u6307\u5b9a\r\n\t\t.translate([500,450]) \/\/\u8868\u793a\u4f4d\u7f6e\u8abf\u6574\r\n\t\t.center([139.0032936, 36.3219088]); \/\/\u4e2d\u5fc3\u306e\u5ea7\u6a19\u3092\u6307\u5b9a\r\n\r\n\tvar path = d3.geo.path().projection(projection);\u3000\/\/\u30d1\u30b9\u30b8\u30a7\u30cd\u30ec\u30fc\u30bf\u30fc\r\n\r\n\tvar svg = d3.select(\"svg\");\r\n\t\t\t\t\r\n\t\/\/\u5916\u5468\u8981\u7d20\u8ffd\u52a0\r\n\tsvg.append(\"path\")\r\n      .datum(topojson.mesh(json, json.objects.ken, function(a, b) { return a == b; }))\r\n      .attr({\r\n\t\t\"d\": path,\r\n\t\t\"fill\": \"none\",\r\n\t\t\"stroke\": \"blue\"\r\n\t  });\r\n\r\n\t  \/\/\u5883\u754c\u8981\u7d20\u8ffd\u52a0\r\n\tsvg.append(\"path\")\r\n\t\t.datum(topojson.mesh(json, json.objects.ken, function(a, b) { return a !== b; }))\r\n\t\t.attr({\r\n\t\t  \"d\": path,\r\n\t\t   \"fill\": \"none\",\r\n\t\t   \"stroke\": \"red\"\r\n\t  });\r\n\r\n}<\/pre>\n<h2>topojson.merge<\/h2>\n<p>\u30dd\u30ea\u30b4\u30f3\u3068\u30dd\u30ea\u30b4\u30f3\u3092\u5408\u6210\u3057\u3066\u4e00\u3064\u306e\u30dd\u30ea\u30b4\u30f3\u3068\u3057\u3066\u8868\u793a\u3057\u307e\u3059\u3002<br \/>\n\u4e0b\u8a18\u306f\u65b0\u6f5f\u770c\u3001\u7fa4\u99ac\u770c\u3001\u57fc\u7389\u770c\u3001\u6771\u4eac\u90fd\u3001\u795e\u5948\u5ddd\u770c\u3092\u30de\u30fc\u30b8\u3057\u3066\u4e00\u3064\u306e\u30a8\u30ea\u30a2\u3068\u3057\u3066\u8868\u793a\u3057\u307e\u3059\u3002<br \/>\n\u30e6\u30fc\u30b6\u30fc\u306e\u64cd\u4f5c\u306b\u5bfe\u3057\u3066\u3001\u52d5\u7684\u306b\u30dd\u30ea\u30b4\u30f3\u306e\u30de\u30fc\u30b8\u3092\u884c\u3046\u306a\u3069\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/d3js\/topojson\/merge\/index.html\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/topojsontips15031021.jpg\" alt=\"topojson \u30de\u30fc\u30b8\" width=\"589\" height=\"444\" class=\"alignnone size-full wp-image-4136\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/topojsontips15031021.jpg 589w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/topojsontips15031021-199x150.jpg 199w\" sizes=\"auto, (max-width: 589px) 100vw, 589px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/d3js\/topojson\/merge\/index.html\">example<\/a><\/p>\n<pre class=\"lang:js decode:true \" >d3.json(\"..\/..\/_geodata\/ken.topojson\", function(json) {\r\n\tdraw(json);\r\n});\r\n\r\n\r\nfunction draw(json){\r\n\r\n\tvar projection = d3.geo\r\n\t\t.mercator()\t\t\/\/\u6295\u5f71\u6cd5\u306e\u6307\u5b9a\r\n\t\t.scale(2000)\t\/\/\u30b9\u30b1\u30fc\u30eb\uff08\u30ba\u30fc\u30e0\uff09\u306e\u6307\u5b9a\r\n\t\t.translate([500,450]) \/\/\u8868\u793a\u4f4d\u7f6e\u8abf\u6574\r\n\t\t.center([139.0032936, 36.3219088]); \/\/\u4e2d\u5fc3\u306e\u5ea7\u6a19\u3092\u6307\u5b9a\r\n\r\n\tvar path = d3.geo.path().projection(projection);\u3000\/\/\u30d1\u30b9\u30b8\u30a7\u30cd\u30ec\u30fc\u30bf\u30fc\r\n\r\n\tvar svg = d3.select(\"svg\");\r\n\t\r\n\t\/\/\u30de\u30fc\u30b8\u3055\u305b\u308b\u30dd\u30ea\u30b4\u30f3\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u3002\u4eca\u56de\u306fObjName_1\u8981\u7d20\u3092\u4f7f\u3046\r\n\tvar selected = d3.set([\r\n\t\t\"Gunma\", \"Saitama\", \"Nigata\", \"Tokyo\", \"Kanagawa\"\r\n\t]);\r\n\t\t\r\n\t\r\n\t\/\/\u5730\u5f62\u8981\u7d20\u8ffd\u52a0\r\n\tsvg.append(\"path\")\r\n      .datum(topojson.mesh(json, json.objects.ken, function(a, b) { return a == b; }))\r\n      .attr({\r\n\t\t\"d\": path,\r\n\t\t\"fill\": \"#ccc\"\r\n\t  });\r\n\r\n\t  \/\/\u5883\u754c\u8981\u7d20\u8ffd\u52a0\r\n\tsvg.append(\"path\")\r\n\t\t.datum(topojson.mesh(json, json.objects.ken, function(a, b) { return a !== b; }))\r\n\t\t.attr({\r\n\t\t  \"d\": path,\r\n\t\t   \"fill\": \"none\",\r\n\t\t   \"stroke\": \"#fff\"\r\n\t  });\r\n\r\n\r\n\t \/\/\u30de\u30fc\u30b8\u30a8\u30ea\u30a2\u8ffd\u52a0\r\n\tsvg.append(\"path\")\r\n\t\t.datum(topojson.merge(json, json.objects.ken.geometries.filter(function(d) { return selected.has(d.properties[\"ObjName_1\"]); })))\r\n\t\t.attr({\r\n\t\t  \"d\": path,\r\n\t\t  \"fill\": \"orange\",\r\n\t\t  \"stroke\": \"none\",\t\t\r\n\t  });\r\n\r\n\t\t\r\n\r\n}<\/pre>\n<h2>\u305d\u306e\u4ed6<\/h2>\n<p>GeoJSON\u3067\u306f\u96e3\u3057\u304b\u3063\u305f\u3001\u4ea4\u5dee\u30dd\u30a4\u30f3\u30c8\u306e\u62bd\u51fa\u306a\u3069\u3082TopoJSON\u5f62\u5f0f\u306e\u30c7\u30fc\u30bf\u3067\u3042\u308c\u3070\u6bd4\u8f03\u7684\u7c21\u5358\u306b\u884c\u3048\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/d3js\/topojson\/Junction\/index.html\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/topojsontips15031031.jpg\" alt=\"topojson \u30b8\u30e3\u30f3\u30af\u30b7\u30e7\u30f3\" width=\"590\" height=\"445\" class=\"alignnone size-full wp-image-4137\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/topojsontips15031031.jpg 590w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2015\/03\/topojsontips15031031-199x150.jpg 199w\" sizes=\"auto, (max-width: 590px) 100vw, 590px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/shimz.me\/example\/d3js\/topojson\/Junction\/index.html\">example<\/a><\/p>\n<pre class=\"lang:js decode:true \" >d3.json(\"..\/..\/_geodata\/ken.topojson\", function(json) {\r\n\tdraw(json);\r\n});\r\n\r\n\r\nfunction draw(json){\r\n\r\n\tvar projection = d3.geo\r\n\t\t.mercator()\t\t\/\/\u6295\u5f71\u6cd5\u306e\u6307\u5b9a\r\n\t\t.scale(2000)\t\/\/\u30b9\u30b1\u30fc\u30eb\uff08\u30ba\u30fc\u30e0\uff09\u306e\u6307\u5b9a\r\n\t\t.translate([500,450]) \/\/\u8868\u793a\u4f4d\u7f6e\u8abf\u6574\r\n\t\t.center([139.0032936, 36.3219088]); \/\/\u4e2d\u5fc3\u306e\u5ea7\u6a19\u3092\u6307\u5b9a\r\n\r\n\tvar path = d3.geo.path().projection(projection);\u3000\/\/\u30d1\u30b9\u30b8\u30a7\u30cd\u30ec\u30fc\u30bf\u30fc\r\n\t\t\r\n\tvar svg = d3.select(\"svg\");\r\n\r\n\t\/\/\u5730\u5f62\u8981\u7d20\u8ffd\u52a0\r\n\tsvg.append(\"path\")\r\n      .datum(topojson.mesh(json))\r\n      .attr({\r\n\t\t\"d\": path,\r\n\t\t\"fill\": \"none\",\r\n\t\t\"stroke\":\"gray\"\r\n\t  });\t\r\n\r\n\tvar junctionByPoint = d3.map();\r\n\tvar arcCountsByPoint = d3.map();\r\n\r\n\tjson.arcs.forEach(function(arc) {\t\r\n\t\tvar start = arc[0];\r\n\t\tvar startCount = arcCountsByPoint.get(start) || 0;\r\n\t\tvar end = arc.reduce(function(p, v) { return [p[0] + v[0], p[1] + v[1]]; });\r\n\t\tvar endCount = arcCountsByPoint.get(end) || 0;\r\n\t\tif (arcCountsByPoint.set(start, startCount + 1) &gt; 1) junctionByPoint.set(start, start);\r\n\t\tif (arcCountsByPoint.set(end, endCount + 1) &gt; 1) junctionByPoint.set(end, end);\r\n\t});\r\n\r\n\tsvg.selectAll(\".junction\")\r\n\t\t.data(junctionByPoint.values())\r\n\t\t  .enter()\r\n\t\t  .append(\"circle\")\r\n\t\t  .attr({\r\n\t\t\t  \"class\": \"junction\",\r\n\t\t\t  \"transform\": function(d) { return \"translate(\" + transform(d) + \")\"; },\r\n\t\t\t  \"r\":2.5,\r\n\t\t\t  \"fill\": \"red\"\r\n\t\t  })\r\n\r\n\tfunction transform(point) {\r\n\t\t  var p = projection([\r\n\t\t\t  point[0] * json.transform.scale[0] + json.transform.translate[0],\r\n\t\t\t  point[1] * json.transform.scale[1] + json.transform.translate[1]\t\r\n\t\t  ]);\r\n\t\t  return p;\r\n\t}\r\n  \r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5358\u7d14\u306b\u3001GeoJSON\u5f62\u5f0f\u306e\u30c7\u30fc\u30bf\u3092\u52b9\u7387\u3088\u304f\u5727\u7e2e\u3057&hellip;<\/p>\n","protected":false},"author":1,"featured_media":4136,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-4131","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-d3-js","has-post-thumbnail-archive"],"_links":{"self":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/4131","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=4131"}],"version-history":[{"count":0,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/4131\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/4136"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=4131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=4131"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=4131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}