我正在尝试将Voronoi图覆盖在大叶草网络地图上。我正在用SciPy创建voronoi地图,然后将其转换为Json。当我生成地图时,除了Voronoi图层,整个地图都在那里,但是该图层确实显示在“图层控制”中。
我猜测该错误是Json文件的创建方式中的某个地方。我一直在搜索,但是没有错误,我什么也找不到
福利地图生成
m = folium.Map(location=[43.521, -120.587],
zoom_start = 7.45,
tiles = 'Mapbox Bright')
tooltip = 'Click for detailed information'
for point in range(len(locationList)):
folium.Marker(locationList[point], popup = labels[point], icon = folium.Icon(color = colors[point]), parse_html=True).add_to(m)
m.save('index.html')
Voronoi图生成
### Create volonai map
points = np.array(df[["geo_long","geo_lat"]].values.tolist()) # Create points, each point is a hospital
vor = Voronoi(points) #Create voronoi object
voronoi_plot_2d(vor) # Create voronoi plot object
转换为Json
vorJSON = open('libVor.json', 'w')
point_voronoi_list = []
feature_list = []
for region in range(len(vor.regions)-1):
vertex_list = []
for x in vor.regions[region]:
if x == -1:
break;
else:
vertex = vor.vertices[x]
vertex = (vertex[1], vertex[0])
vertex_list.append(vertex)
polygon = Polygon([vertex_list])
feature = Feature(geometry=polygon, properties={})
feature_list.append(feature)
feature_collection = FeatureCollection(feature_list)
print (feature_collection, file=vorJSON)
vorJSON.close()
在地图上添加图层
vorGeoJson = json.load(open('libVor.json'))
folium.GeoJson(vorGeoJson,
name = 'geojson'
).add_to(m)
folium.LayerControl().add_to(m)
print(m)
m.save(outfile='libVor.html')
我的目标是使多边形覆盖在网络地图上
答案 0 :(得分:0)
尝试在我的地图上绘制geoJSON文件时遇到了完全相同的问题。我发现我的问题是缺少/错误的坐标系。
因为我将数据从shapefile转换为geoJSON,所以我使用QGIS将数据投影到正确的坐标系中(我相信EPSG:4326-WGS84通常可以工作)。