【发布时间】:2013-05-31 06:42:56
【问题描述】:
我正在尝试将 shapefile 转换为 GeoJSON,然后转换为 Let's Make a Map 中所述的 TopoJSON。沿着链条的某个地方,某些东西被破坏了,我得到的图像如下所示:
我的工作流程如下:
- 从以下位置下载 shapefile:http://vcgi.vermont.gov/warehouse/search_tools - 我正在处理Master Town Boundary 数据,特别是“Boundary_BNDHASH_region_towns.shp”文件。
-
将 shapefile 转换为 GeoJSON
ogr2ogr -f GeoJSON vt_towns.json Boundary_BNDHASH_region_towns.shp -
将 GeoJSON 转换为 TopoJSON
topojson -p TOWNNAME -p CNTY -o vt.json vt_towns.json -
对 Mike Bostock 的示例稍作修改,插入基本模板
<!DOCTYPE html> <meta charset="utf-8"> <style> /* CSS goes here. */ </style> <body> <script src="http://d3js.org/d3.v3.min.js"></script> <script src="http://d3js.org/topojson.v1.min.js"></script> <script> var width = 960, height = 1160; var svg = d3.select("body").append("svg") .attr("width", width) .attr("height", height); var projection = d3.geo.transverseMercator() .rotate([72.57, -44.20]) .translate([175,185]) .scale([100]); // Define path generator var path = d3.geo.path() .projection(projection); d3.json("vt.json", function(error, vt) { var vermont = topojson.feature(vt, vt.objects.vt_towns); svg.append("path") .datum(vermont) .attr("d", path); }); </script>
这不是我的第一张 d3 地图(这是我的第二张地图!)但我非常不知道出了什么问题。我最好的猜测是它与包含许多 shapefile 及其随附文件的解压缩数据集有关。
【问题讨论】:
-
对于初学者,请将
.attr("fill", "none").attr("stroke", "#000")添加到您正在创建的路径中。这要么解决问题,要么至少让你更好地了解问题所在。 -
首先,我想说,为了更好地衡量,将 shapefile 和相关的支持文件(prj、dbf 等)放在他们自己的目录中。其次,您能否链接到您引用的示例。我最好的猜测是它与投影以及您使用 d3 重新投影的方式有关。
-
将文件移动到自己的目录中会稍微改变生成的图像,但它仍然是一个大黑盒子。我之前成功的 d3 地图也是佛蒙特州的地图,尽管来源不同。
标签: d3.js shapefile geojson topojson