'Unsupported driver' error when writing Geodataframe to file in geopandas
I am reading in a GeoJson file, applying some functions to it and then want to save the GeoDataFrame to another file.
Here's my code:
import geopandas as gpd
df=gpd.read_file('C:/in_folder/data.json')
df.to_file(driver='C:/out_folder', filename='df.json')
But this yields the following error:
DriverError: unsupported driver: 'C:/out_folder'
Here's the traceback:
---------------------------------------------------------------------------
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'
Does anyone know what's going on?
The driver
keyword needs to be a file format, like "ESRI Shapefile", or "GeoJSON", etc.
To see all supported drivers, you can run (the exact output depends on your installation):
>>> 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'}