How do I write a GeoPandas dataframe into a single file (preferably JSON or GeoPackage)?
To write to GeoJSON:
dataframe.to_file("output.json", driver="GeoJSON")
To write to GeoPackage:
dataframe.to_file("output.gpkg", driver="GPKG")
Documentation is here, though somewhat sparse.
@toms' answer is perfect -- which I've used for creating my geopackage, btw. Now that I've learned, I want to add to the discussion:
GeoDataFrame's to_file
method has the following signature:
>>> help(dataframe.to_file)
to_file(filename, driver='ESRI Shapefile', schema=None, **kwargs)
...
And it follows:
...
A dictionary of supported OGR
providers is available via:
>>> import fiona
>>> fiona.supported_drivers
As of fiona.__version__ == 1.8.6
those are the supported drivers:
{'AeronavFAA': 'r',
'ARCGEN': 'r',
'BNA': 'raw',
'DXF': 'raw',
'CSV': 'raw',
'OpenFileGDB': 'r',
'ESRIJSON': 'r',
'ESRI Shapefile': 'raw',
'GeoJSON': 'rw',
'GPKG': 'rw',
'GML': 'raw',
'GPX': 'raw',
'GPSTrackMaker': 'raw',
'Idrisi': 'r',
'MapInfo File': 'raw',
'DGN': 'raw',
'S57': 'r',
'SEGY': 'r',
'SUA': 'r',
'TopoJSON': 'r'}
Which is a pretty interesting list, btw. It is just not clear the relation between file-formats extension/name, which may look a bit "noisy" for newcomers (like me), but a second round of googles will do it.