0

我正在尝试使用我使用的 geopandas 读取 shapefilegp.read_file

import geopandas as gp
fl="M:/rathore/vic_5km/L2_data/L2_data/DAMSELFISH_distributions.shp"
data=gp.read_file(fl)

我收到以下错误: TypeError: invalid path: UnparsedPath(path='M:/rathore/vic_5km/L2_data/L2_data/DAMSELFISH_distributions.shp')

问题的追溯是:

----> 1 data=gp.read_file(fl)

c:\python27\lib\site-packages\geopandas\io\file.pyc in read_file(filename, bbox, **kwargs)
     75 
     76     with fiona_env():
---> 77         with reader(path_or_bytes, **kwargs) as features:
     78 
     79             # In a future Fiona release the crs attribute of features will

c:\python27\lib\site-packages\fiona\fiona\env.pyc in wrapper(*args, **kwargs)
    395     def wrapper(*args, **kwargs):
    396         if local._env:
--> 397             return f(*args, **kwargs)
    398         else:
    399             if isinstance(args[0], str):

c:\python27\lib\site-packages\fiona\__init__.pyc in open(fp, mode, driver, schema, crs, encoding, layer, vfs, enabled_drivers, crs_wkt, **kwargs)
    255         if mode in ('a', 'r'):
    256             c = Collection(path, mode, driver=driver, encoding=encoding,
--> 257                            layer=layer, enabled_drivers=enabled_drivers, **kwargs)
    258         elif mode == 'w':
    259             if schema:

c:\python27\lib\site-packages\fiona\fiona\collection.pyc in __init__(self, path, mode, driver, schema, crs, encoding, layer, vsi, archive, enabled_drivers, crs_wkt, ignore_fields, ignore_geometry, **kwargs)
     54 
     55         if not isinstance(path, (string_types, Path)):
---> 56             raise TypeError("invalid path: %r" % path)
     57         if not isinstance(mode, string_types) or mode not in ('r', 'w', 'a'):
     58             raise TypeError("invalid mode: %r" % mode)

TypeError: invalid path: UnparsedPath(path='M:/rathore/vic_5km/L2_data/L2_data/DAMSELFISH_distributions.shp')

我猜fiona有一些问题,但我不太了解。我已经在我的系统中安装fiona 1.8.6并安装了版本。geopandas 0.5.0我正在使用 python 2.7

4

3 回答 3

0

我认为这与 fiona 和 geopandas 的版本无关。您可以通过命令提示符/终端找到文件的路径,并使用它来读取文件,如下所示

fl="/Users/xxxx/Downloads/Data/DAMSELFISH_distributions.shp"

希望这可以帮助

于 2019-06-21T07:29:30.027 回答
0

首先,isinstance(your_path, ((str,), Path))被评估为Falsein fiona\collection.pyc,这很奇怪。

此外, fiona/ init .py模块中的那些行应该处理路径是pathlib.Path对象的情况,但显然不是......我不确定,这可能是 fiona 的问题。

我仍然认为问题来自 fiona 的parse_path(path)方法。

以下是您应该尝试的一些事情:

  1. 如果M:是本地网络上的共享文件夹,请尝试将 'M:/...' 替换为 UNC 路径(例如:“//local/folder/path/to/file”)
  2. 如果您使用 IDE(如 Pycharm、Eclipse 或 VsCode),请在第三行添加一个断点,使用调试器并深入了解该parse_data方法。然后看看你的路径是什么样的。如果您不使用 IDE,请考虑安装一个...
  3. 如果可以,请尝试将 shapefile 复制到与您的 python 脚本相同的驱动器上,并检查错误是否仍然出现。
于 2019-06-21T08:23:50.900 回答
0

它说路径无效。我会尝试在您的路径中替换逗号:

前:

fl="M:/rathore/vic_5km/L2_data/L2_data/DAMSELFISH_distributions,shp"

后:

fl="M:/rathore/vic_5km/L2_data/L2_data/DAMSELFISH_distributions.shp"
于 2019-06-21T05:18:46.210 回答