'将Geodataframe写入geopandas中的文件时出现'不支持的驱动程序'错误

问题描述 投票:0回答:1

我正在读取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:不支持的驱动程序:'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'

有人知道发生了什么吗?

python file anaconda geopandas
1个回答
0
投票

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'}
© www.soinside.com 2019 - 2024. All rights reserved.