Python 使用Vincent读取topojson文件时画布太大
我想使用Vincent显示topojson文件。我使用以下命令将shapefile转换为topojson:Python 使用Vincent读取topojson文件时画布太大,python,shapefile,topojson,vincent,Python,Shapefile,Topojson,Vincent,我想使用Vincent显示topojson文件。我使用以下命令将shapefile转换为topojson: topojson -o /path/to/output/file.topo.json -- /path/to/input/file.shp 为了显示它,我在Ipython笔记本中使用以下代码: import vincent vincent.core.initialize_notebook() world_topo = r'scot.topo.json' geo_data = [{'nam
topojson -o /path/to/output/file.topo.json -- /path/to/input/file.shp
为了显示它,我在Ipython笔记本中使用以下代码:
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()
然而,结果是:
有人知道为什么我用Vincent得到了太多的空白吗?在不使用Ipython笔记本的情况下也会发生这种情况
我还验证了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);
});
可能您的SHP未使用正确的投影。有时候,在我得到我想要的功能之前,只需摆弄缩放和转换比试图解决shp/json问题更容易。这是可能的。你知道vincent中有哪些关键字可以用来做这件事吗?我正在d3中尝试,要把它做好有些困难。