【问题标题】:Unable to open geojson file with geopandas, getting TypeError无法使用 geopandas 打开 geojson 文件,出现 TypeError
【发布时间】:2020-12-08 01:17:43
【问题描述】:

我正在尝试在 geopandas 中打开 geojson 文件,但收到以下错误消息:

 Traceback (most recent call last):
 File "C:\Users\arobe\Anaconda3\envs\test_env\lib\site-packages\geopandas\io\file.py", line 95, in read_file
 gdf = GeoDataFrame.from_features(f_filt, crs=crs, columns=columns)
 File "C:\Users\arobe\Anaconda3\envs\test_env\lib\site-packages\geopandas\geodataframe.py", line 283, in from_features
 for f in features_lst:
 File "fiona/ogrext.pyx", line 1369, in fiona.ogrext.Iterator.__next__
 File "fiona/ogrext.pyx", line 232, in fiona.ogrext.FeatureBuilder.build
 TypeError: startswith first arg must be bytes or a tuple of bytes, not str

geopandas cannot read a geojson properly_ 这里的解决方案对我不起作用,我尝试了各种编码方式。数据来自英国 MSOA 数据集 (https://geoportal.statistics.gov.uk/datasets/f341dcfd94284d58aba0a84daf2199e9_2/geoservice?page=720)。

数据下载正常,在 Tableau 中运行良好。在记事本++中打开时看起来也不错,所以它似乎不是数据问题,但我是新手,所以真的不知道我在做什么!

任何帮助将不胜感激。

代码sn-p:

 gdf=gpd.read_file("https://opendata.arcgis.com/datasets/f341dcfd94284d58aba0a84daf2199e9_2.geojson")
 print(gdf.head(10))

 gdf.to_file("msoa.geojson", driver='GeoJSON')

 gdf2=gpd.read_file("msoa.geojson"
             ,driver='GeoJSON'
             )

 print(gdf2.head(10))

【问题讨论】:

    标签: python geopandas fiona


    【解决方案1】:

    我使用 geopandas v0.8.1、fiona v1.8.17 在 Linux 上运行您的代码。一切都好。简单的情节如下。

    【讨论】:

    • 非常感谢。这似乎是一个 windows/anaconda 问题,也许因为一些人似乎遇到了麻烦,我开始认为这可能与 Fiona 并建立了一个新的环境并按照这里的步骤stackoverflow.com/questions/50876702/… 但到目前为止没有任何好处,因为仍然有同样的问题。
    • 你是对的 - 问题是一些奇怪的字符,请参阅上面的答案
    【解决方案2】:

    由于某种原因,下载的数据中出现了一些奇怪的字符。我手动删除了它们,因为它们用于我不感兴趣的区域,现在它可以工作了。解决方案在这里找到https://github.com/geopandas/geopandas/issues/621

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-22
      • 2021-10-04
      • 2019-11-15
      • 2022-09-25
      • 2021-03-11
      • 1970-01-01
      • 1970-01-01
      • 2019-07-07
      相关资源
      最近更新 更多