Once you have read the data from a GIS file using Fiona, you can save it to another file format using the fiona.open() method and the ‘w’ mode. You can also use the fiona.open() method to save the data to a new file, by specifying the file path and format, and passing the ‘w’ mode as the second argument.
Here is an example of how to save the data from a shapefile to a geojson file:
In this example, the data is read from a shapefile and written to a geojson file. The properties, crs, and schema of the new file are defined from the source file using the src.schema and src.crs attributes.
It’s important to note that when saving the data to a new file, the file format and the driver must be specified correctly, and the schema and properties must match the data being written. You can also use the same approach to save the data to other file formats such as KML, CSV, or any other format supported by Fiona. You just need to change the driver and the file path and extension accordingly.
For example, to save the data to a CSV file:
This example uses the built-in csv library to write the data to a CSV file. It writes the header of the file using the keys of the properties from the source file and then it writes the values of the properties for each feature.
It’s worth noting that this is a basic example that can be extended and customized to suit the specific requirements of your project, and it’s recommended to consult the documentation of Fiona for more detailed information on how to use it and to have a deeper understanding of the functionality it offers.
Additionally, it’s important to thoroughly test your code and ensure that the data is being written correctly before deploying it.