我想使用文森特显示一个 topojson 文件。我使用以下命令将 shapefile 转换为 topojson:
topojson -o /path/to/output/file.topo.json -- /path/to/input/file.shp
为了显示它,我使用了这段代码(在 Ipython Notebook 中):
import vincent
vincent.core.initialize_notebook()
world_topo = r'scot.topo.json'
geo_data = [{'name': 'countries',
'url': world_topo,
'feature': 'scot'}]
vis = vincent.Map(geo_data=geo_data, scale=1000)
vis.display()
然而,结果如下:
有谁知道为什么我使用文森特得到太多空白空间?这也发生在不使用 Ipython Notebook 的情况下。
我还验证了 QGIS 中的 shapefile,它看起来是正确的,因此原始文件中没有多余的空格。
更新:
我能够使图像居中并减少空白空间的数量,但我不确定它为什么会起作用。这是代码:
import vincent
vincent.core.initialize_notebook()
world_topo = r'scot.topo.json'
geo_data = [{'name': 'countries',
'url': world_topo,
'feature': 'scot'}]
vis = vincent.Map(geo_data=geo_data, scale=6000, center=[0,57])
vis.display()
有谁知道获得正确参数的想法是什么?我首先尝试让它在 D3 中工作,尽管代码中有相似之处,但 vincent 和 d3 似乎并没有使用相同的参数产生相同的结果。这是 d3 代码:
var width = 350,
height = 450;
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
d3.json("scot.topo.json", function(error, s) {
if (error) return console.error(error);
var subunits = topojson.feature(s, s.objects.scot);
var projection = d3.geo.albers()
.center([0, 57])
.rotate([4.4, 0])
.parallels([50,60])
.scale(4000)
.translate([width / 2, height / 2]);
var path = d3.geo.path()
.projection(projection);
svg.append("path")
.datum(subunits)
.attr("d", path);
});