你好我正试图在一个jupyter笔记本中用Folium渲染这个地图。
https://github.com/kthotav/TopoJSON-Maps/blob/master/usa/usa-states/colorado/colorado-counties.json
由于这是TopoJson,它应该非常简单
m = folium.Map([39, -105], zoom_start=7)
folium.TopoJson(
open('./data/colorado-counties.json'),
object_path='objects.colorado-counties'
).add_to(m)
m
这会渲染基础层,但不会为县绘制多边形。
我找到了this other example on stackoverflow,它使用基本相同的代码渲染得很好。
m = folium.Map(location=[40.7,-74], zoom_start=10)
folium.TopoJson(
open('./data/nyc_census_tracts_2010.geojson'),
object_path='objects.nyct2010',
).add_to(m)
m
我无法找到两个文件之间的任何大规模差异。是否有一些topojson版本不兼容?
答案 0 :(得分:2)
好的,明白了。 folium无法解析其中包含-
的对象名称。可能是一个javascript翻译的东西?
有趣的测试
作品
m = folium.Map([0, 0], zoom_start=7)
folium.TopoJson(
{
"type":"Topology",
"transform":{
"scale": [1,1],
"translate": [0,0]
},
"objects":{
"two_squares":{
"type": "GeometryCollection",
"geometries":[
{"type": "Polygon", "arcs":[[0,1]],"properties": {"name": "Left_Polygon" }},
{"type": "Polygon", "arcs":[[2,-1]],"properties": {"name": "Right_Polygon" }}
]
}
},
"arcs": [
[[1,2],[0,-2]],
[[1,0],[-1,0],[0,2],[1,0]],
[[1,2],[1,0],[0,-2],[-1,0]]
]
},
object_path='objects.two_squares'
).add_to(m)
m
不起作用
m = folium.Map([0, 0], zoom_start=7)
folium.TopoJson(
{
"type":"Topology",
"transform":{
"scale": [1,1],
"translate": [0,0]
},
"objects":{
"two-squares":{
"type": "GeometryCollection",
"geometries":[
{"type": "Polygon", "arcs":[[0,1]],"properties": {"name": "Left_Polygon" }},
{"type": "Polygon", "arcs":[[2,-1]],"properties": {"name": "Right_Polygon" }}
]
}
},
"arcs": [
[[1,2],[0,-2]],
[[1,0],[-1,0],[0,2],[1,0]],
[[1,2],[1,0],[0,-2],[-1,0]]
]
},
object_path='objects.two-squares'
).add_to(m)
m