gpt4 book ai didi

python - 将 Geodataframe 写入 geopandas 文件时出现“不支持的驱动程序”错误

转载 作者:行者123 更新时间:2023-12-02 02:59:55 25 4
gpt4 key购买 nike

我正在读取 GeoJson 文件,对其应用一些函数,然后想将 GeoDataFrame 保存到另一个文件。

这是我的代码:

import geopandas as gpd
df=gpd.read_file('C:/in_folder/data.json')
df.to_file(driver='C:/out_folder', filename='df.json')

但这会产生以下错误:

DriverError: unsupported driver: 'C:/out_folder'

这是回溯:

---------------------------------------------------------------------------
DriverError Traceback (most recent call last)
<ipython-input-75-4209247a0f42> in <module>
1 import geopandas as gpd
2 df=gpd.read_file('C:/in_folder/data.json')
3 df.to_file(driver='C:/out_folder', filename='df.json')

~\.conda\envs\ox\lib\site-packages\geopandas\geodataframe.py in to_file(self, filename, driver, schema, **kwargs)
513 from geopandas.io.file import to_file
514
--> 515 to_file(self, filename, driver, schema, **kwargs)
516
517 def to_crs(self, crs=None, epsg=None, inplace=False):

~\.conda\envs\ox\lib\site-packages\geopandas\io\file.py in to_file(df, filename, driver, schema, **kwargs)
125 schema = infer_schema(df)
126 with fiona_env():
--> 127 with fiona.open(
128 filename, "w", driver=driver, crs=df.crs, schema=schema, **kwargs
129 ) as colxn:

~\.conda\envs\ox\lib\site-packages\fiona\env.py in wrapper(*args, **kwargs)
396 def wrapper(*args, **kwargs):
397 if local._env:
--> 398 return f(*args, **kwargs)
399 else:
400 if isinstance(args[0], str):

~\.conda\envs\ox\lib\site-packages\fiona\__init__.py in open(fp, mode, driver, schema, crs, encoding, layer, vfs, enabled_drivers, crs_wkt, **kwargs)
260 else:
261 this_schema = None
--> 262 c = Collection(path, mode, crs=crs, driver=driver, schema=this_schema,
263 encoding=encoding, layer=layer, enabled_drivers=enabled_drivers, crs_wkt=crs_wkt,
264 **kwargs)

~\.conda\envs\ox\lib\site-packages\fiona\collection.py in __init__(self, path, mode, driver, schema, crs, encoding, layer, vsi, archive, enabled_drivers, crs_wkt, ignore_fields, ignore_geometry, **kwargs)
126 raise DriverError("no driver")
127 elif driver not in supported_drivers:
--> 128 raise DriverError(
129 "unsupported driver: %r" % driver)
130 elif self.mode not in supported_drivers[driver]:

DriverError: unsupported driver: 'C:/out_folder'

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

最佳答案

driver 关键字需要是一种文件格式,如“ESRI Shapefile”或“GeoJSON”等。

要查看所有支持的驱动程序,您可以运行(确切的输出取决于您的安装):

>>> import fiona
>>> fiona.supported_drivers
{'AeronavFAA': 'r',
'ARCGEN': 'r',
'BNA': 'raw',
'DXF': 'raw',
'CSV': 'raw',
'OpenFileGDB': 'r',
'ESRIJSON': 'r',
'ESRI Shapefile': 'raw',
'GeoJSON': 'rw',
'GeoJSONSeq': 'rw',
'GPKG': 'rw',
'GML': 'raw',
'GPX': 'raw',
'GPSTrackMaker': 'raw',
'Idrisi': 'r',
'MapInfo File': 'raw',
'DGN': 'raw',
'PCIDSK': 'r',
'S57': 'r',
'SEGY': 'r',
'SUA': 'r',
'TopoJSON': 'r'}

关于python - 将 Geodataframe 写入 geopandas 文件时出现“不支持的驱动程序”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60214181/

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