gpt4 book ai didi

python - 从不同目录导入文件后 Geopandas 不工作

转载 作者:行者123 更新时间:2023-12-01 06:37:28 25 4
gpt4 key购买 nike

我正在尝试使用从bbike.org下载的shapefiles在python中制作 map 。 。这是我的代码:

import geopandas as gpd
import os
import sys
import matplotlib.pyplot as plt

bos_files_list = ['buildings.shx', 'landuse.shx', 'natural.shx', 'places.shx', 'points.shx', 'railways.shx', 'roads.shx']
cur_path = os.path.dirname(__file__)

def maps_of_bos(files):
for x in range(len(files)):
os.chdir(f'location/of/file')
f = open(f'{files[x]}', 'r')
gpd.read_file(f)


z = maps_of_bos(bos_files_list)

z.plot()

plt.show()

但是,我的错误输出如下:

Traceback (most recent call last):
File "test.py", line 16, in <module>
z = maps_of_bos(bos_files_list)
File "test.py", line 13, in maps_of_bos
gpd.read_file(f)

File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/geopandas/io/f
ile.py", line 76, in read_file
with reader(path_or_bytes, **kwargs) as features:
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/contextlib.py", line 113, in
__enter__
return next(self.gen)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/fiona/__init__
.py", line 206, in fp_reader
dataset = memfile.open()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/fiona/io.py",
line 63, in open
return Collection(vsi_path, 'w', crs=crs, driver=driver,
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/fiona/collecti
on.py", line 126, in __init__
raise DriverError("no driver")
fiona.errors.DriverError: no driver

我对 python 比较陌生,并且不太理解我的错误。有人可以帮我吗?

最佳答案

根据docs read_file 应采用文件路径而不是对象。

gpd.read_file(f'{files[x]}')

你不需要

f = open(f'{files[x]}', 'r')

关于python - 从不同目录导入文件后 Geopandas 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59606163/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com