【问题标题】:GeoPandas loses .crs info across notebooksGeoPandas 跨笔记本丢失 .crs 信息
【发布时间】:2019-02-07 18:20:35
【问题描述】:

我遇到了一个奇怪的问题:使用 GeoPandas(在 Jupyter Notebooks 中)时,.crs 数据在我的第一个笔记本中运行良好,然后在我的第二个笔记本中丢失。

只要看看图书馆附带的一张世界地图,运行这个单元......

world = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
world.crs

...在我的第一个笔记本中返回...

{'init': 'epsg:4326'}

...,而在我的第二个笔记本中,我得到...

{}

除此之外(或因此),匹配 crs 在第一个笔记本中有效,但在第二个笔记本中无效。在笔记本 1...

mal0 = gpd.read_file('./bird-species/E00039600_mallard.gdb', layer=0)
mal0 = mal0.to_crs(world.crs)
mal0.crs

返回...

{'init': 'epsg:4326'}

...正如预期的那样,但在笔记本 2 中它会引发错误:

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-10-fd67623093a6> in <module>
      1 mal0 = gpd.read_file('./bird-species/E00039600_mallard.gdb', layer=0)
----> 2 mal0 = mal0.to_crs(world.crs)
      3 mal0.crs

~/anaconda3/lib/python3.6/site-packages/geopandas/geodataframe.py in to_crs(self, crs, epsg, inplace)
    441         else:
    442             df = self.copy()
--> 443         geom = df.geometry.to_crs(crs=crs, epsg=epsg)
    444         df.geometry = geom
    445         df.crs = geom.crs

~/anaconda3/lib/python3.6/site-packages/geopandas/geoseries.py in to_crs(self, crs, epsg)
    303                 raise TypeError('Must set either crs or epsg for output.')
    304         proj_in = pyproj.Proj(self.crs, preserve_units=True)
--> 305         proj_out = pyproj.Proj(crs, preserve_units=True)
    306         project = partial(pyproj.transform, proj_in, proj_out)
    307         result = self.apply(lambda geom: transform(project, geom))

~/anaconda3/lib/python3.6/site-packages/pyproj/__init__.py in __new__(self, projparams, preserve_units, **kwargs)
    360         # on case-insensitive filesystems).
    361         projstring = projstring.replace('EPSG','epsg')
--> 362         return _proj.Proj.__new__(self, projstring)
    363 
    364     def __call__(self, *args, **kw):

_proj.pyx in _proj.Proj.__cinit__()

RuntimeError: b'no arguments in initialization list'

有人知道这是怎么回事吗?

【问题讨论】:

  • 作为旁注,我查了一下 RuntimeError 是否有合理的解决方案,但我发现的只是这个线程 - github.com/jswhit/pyproj/issues/134 -,其中看起来每个人都设法通过了它做了一些完全不同的事情。我尝试通过那里建议的几个修复程序,到目前为止无济于事:(
  • 什么是gpd.read_file('./bird-species/E00039600_mallard.gdb', layer=0).crs?如果图层还没有 CRS,则无法转换为新的 CRS
  • 我正在使用的一个数据文件,来自sciencebase.gov/catalog/item/55897deae4b0b6d21dd61c9d 同样,我从第一个笔记本中的数据中获得(不同格式的)crs 信息,但不是第二个笔记本。这是最疯狂的事情。
  • 我正在尝试复制您的问题,但没有任何成功。如何打开第二个笔记本?你用的是同一个内核吗?它按预期对我有用。
  • 是的,奇怪的是,事实证明这有时可以通过重新启动 Jupyter 来解决。我猜问题解决了?

标签: python gis geopandas


【解决方案1】:

我遇到了完全相同的问题。我可以在没有 jupyter 的情况下使用 geopandas 0.6.1 重现这个。

这是一个无用的错误消息的情况。实际的错误是 geopandas 不支持您的 crs。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-16
    • 1970-01-01
    • 1970-01-01
    • 2023-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多