![](/img/trans.png)
[英]create a FID column in shapefile in ogr or geopandas python
[英]Error reading shapefile with Geopandas in Python
我正在尝试使用geopandas读取shapefile,为此我使用了gp.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
它说路径无效。 我会尝试在您的路径中替换逗号:
之前:
fl="M:/rathore/vic_5km/L2_data/L2_data/DAMSELFISH_distributions,shp"
后:
fl="M:/rathore/vic_5km/L2_data/L2_data/DAMSELFISH_distributions.shp"
我认为这与fiona和geopandas的版本无关。 您能否通过命令提示符/终端找到文件的路径,并使用它来读取文件,如下所示
fl="/Users/xxxx/Downloads/Data/DAMSELFISH_distributions.shp"
希望这可以帮助
首先,在fiona\\collection.pyc
,将isinstance(your_path, ((str,), Path))
值评估为False
,这很奇怪。
此外, fiona / init .py模块中的这些行应注意路径是pathlib.Path
对象的情况,但显然不是……我不确定,这可能是fiona的问题。
我仍然认为问题来自fiona的parse_path(path)方法。
您应该尝试以下一些操作:
M:
是本地网络上的共享文件夹,请尝试用UNC路径替换“ M:/ ...”(例如:“ // local / folder / path / to / file”) parse_data
方法。 然后看看你的路径。 如果您不使用IDE,请考虑安装一个...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.