GeoJSON数据未显示在Python folium地图中 [英] GeoJSON data not displaying in Python folium map

查看:169
本文介绍了GeoJSON数据未显示在Python folium地图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Python的叶子地图中显示以下geojson文件,但它仅显示一个空地图,其中没有任何数据.

I am trying to display the following geojson file in a folium map in Python but it just shows an empty map with none of the data.

这是我尝试过的步骤:

  1. 我尝试使用下面的python代码,但未显示任何内容.

  1. I tried using the python code below but nothing shows up.

我使用相同的代码在下面的github存储库中尝试了其他geojson文件,并且数据显示没有问题,所以看起来我的python代码很好

I tried other geojson files in the github repository below using the same code and the data show up without any issue, so it looks like my python code is fine

我在github和 Mapshaper 中打开了"census_tracts_2010.geojson"文件,数据显示得非常完美没有任何问题,因此看起来geojson文件似乎没有损坏

I opened the "census_tracts_2010.geojson" file in github and Mapshaper, the data showed up perfectly without any issue, so it doesn't look like the geojson file is corrupted

任何人都可以让我知道如何解决此问题吗?

Could anyone please let me know how I can fix it?

Geojson文件: https://github.com/dwillis/nyc-maps/blob/master/census_tracts_2010.geojson

Geojson file: https://github.com/dwillis/nyc-maps/blob/master/census_tracts_2010.geojson

Python代码:

import folium
m = folium.Map(location=[40.66393072,-73.93827499], zoom_start=13)
m.choropleth(geo_path="census_tracts_2010.geojson")
m.save(outfile='datamap.html')

非常感谢!

推荐答案

该文件不是GeoJson,而是TopoJson.您需要改用folium.TopoJson.

That file is not a GeoJson it is a TopoJson. You need to use folium.TopoJson instead.

import folium

m = folium.Map(location=[40.66393072,-73.93827499], zoom_start=13)

folium.TopoJson(
    open('census_tracts_2010.geojson'),
    object_path='objects.nyct2010',
).add_to(m)

m

这篇关于GeoJSON数据未显示在Python folium地图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆