【问题标题】:geopandas cannot read a geojson properlygeopandas 无法正确读取 geojson
【发布时间】:2019-05-22 06:36:38
【问题描述】:

我正在尝试以下方法:

下载后http://eric.clst.org/assets/wiki/uploads/Stuff/gz_2010_us_050_00_20m.json

In [2]: import geopandas
In [3]: geopandas.read_file('./gz_2010_us_050_00_20m.json')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-3-83a1d4a0fc1f> in <module>
----> 1 geopandas.read_file('./gz_2010_us_050_00_20m.json')

~/miniconda3/envs/ml3/lib/python3.6/site-packages/geopandas/io/file.py in read_file(filename, **kwargs)
     24         else:
     25             f_filt = f
---> 26         gdf = GeoDataFrame.from_features(f_filt, crs=crs)
     27 
     28         # re-order with column order from metadata, with geometry last

~/miniconda3/envs/ml3/lib/python3.6/site-packages/geopandas/geodataframe.py in from_features(cls, features, crs)
    207 
    208         rows = []
--> 209         for f in features_lst:
    210             if hasattr(f, "__geo_interface__"):
    211                 f = f.__geo_interface__

fiona/ogrext.pyx in fiona.ogrext.Iterator.__next__()

fiona/ogrext.pyx in fiona.ogrext.FeatureBuilder.build()

TypeError: startswith first arg must be bytes or a tuple of bytes, not str

在页面http://eric.clst.org/tech/usgeojson/的20m列下有4个geojson文件,上面的文件对应于美国县行,是4个中唯一无法读出的文件。错误信息不是很丰富,请问是什么原因?

【问题讨论】:

  • 例如 QGIS 可以读取文件吗?
  • 是的,QGIS可以打开文件
  • 错误信息是否看起来像“多边形和多多边形应该遵循右手法则”?因为如果是这样,则意味着您应该对 Polygons/MultiPolygons 中的坐标进行排序。
  • @oriash,我不确定这是否是问题所在。但是如何按 lat 或 lng 对坐标进行排序?
  • 顺时针。 mapster.me/right-hand-rule-geojson-fixer 应该可以工作。

标签: pandas geojson geopandas


【解决方案1】:

如果您的错误消息看起来像“多边形和多多边形应遵循右手规则”,则意味着这些地理对象中的坐标顺序应该是顺时针的。

这是一个“修复”对象的在线工具,并附有简短说明:

https://mapster.me/right-hand-rule-geojson-fixer/

【讨论】:

  • 你知道更可扩展的修复程序吗?
【解决方案2】:

可能是到达此页面的人的答案,我收到了相同的错误,并且由于编码问题而引发了错误。

尝试使用 utf-8 对初始文件进行编码或尝试使用您认为适用于文件的编码打开文件。这解决了我的错误。

更多信息here

【讨论】:

    猜你喜欢
    • 2020-07-04
    • 2019-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-07
    • 2012-04-11
    • 2019-11-13
    • 2012-02-20
    相关资源
    最近更新 更多