【问题标题】:Json layer on folium map is missing, but there are no errorsfolium map上的Json层丢失,但没有错误
【发布时间】:2019-10-23 22:21:21
【问题描述】:

我正在尝试将 Voronoi 图覆盖在 folium 网络地图上。我正在使用 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')

我的目标是让多边形覆盖在网络地图上

【问题讨论】:

    标签: python geojson folium


    【解决方案1】:

    尝试在我的 folium 地图上绘制 geoJSON 文件时,我遇到了完全相同的问题。我发现我的问题是缺少/错误的坐标系。

    由于我将数据从 shapefile 转换为 geoJSON,因此我使用 QGIS 将数据投影到正确的坐标系中(我相信 EPSG:4326 - WGS84 通常可以工作)。

    【讨论】:

      猜你喜欢
      • 2012-12-20
      • 1970-01-01
      • 2020-07-15
      • 1970-01-01
      • 2017-10-18
      • 1970-01-01
      • 2010-12-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多