我想将一个墨西哥市镇的shapefile转换为topojson,并使用d3.js显示,使用这个教程:http://bost.ocks.org/mike/map/#converting-data。我已经成功地将其转换,但是无法显示。非常感谢任何帮助。
到目前为止,我的工作流程如下:
1)下载并解压缩shapefile
wget http://mapserver.inegi.org.mx/MGN/mgm2010v5_0a.zip
unzip mgm2010v5_0a.zip
2) 转换为JSON格式,重投影为经纬度坐标并从shapefile中子集选取
ogr2ogr -f GeoJSON -t_srs EPSG:4326 -where "CVE_ENT IN ('09')" df.json Municipios_2010_5A.shp
3) 转换为 topojson
topojson --id-property OID -p name=OID -p name -o df2.json df.json
4) 并创建HTML代码
<!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);
d3.json("df2.json", function(error, df2) {
svg.append("path")
.datum(topojson.feature(df2, df2.objects.df))
.attr("d", d3.geo.path().projection(d3.geo.mercator()));
});
</script>
如果我运行HTML代码,只能看到一个空白页面。你有什么想法吗?可能是我的操作有误?
</body>
结束标签。 - Martin