If you need to read several common GIS data types, such as shapefiles, geojson, KML, and others, in addition to the OGR library, you can use Fiona library. Fiona is a python library for reading and writing spatial data files. It is built on top of OGR and is designed to be more user-friendly and pythonic.
Fiona provides a simple, pythonic API to read and write spatial data files. It allows you to read and write data in several formats such as shapefiles, geojson, kml, and others. It is easy to use, you can open a file using Fiona and access the data just like a Python dictionary.
Here is an example of how to read a shapefile using Fiona:
This example shows how easy it is to read a shapefile using Fiona, you can open a file, iterate over the features and access the data, and close the file using the “with” statement.
Fiona also supports other formats such as geojson, KML, and others, you can use the same approach to read these other formats, by simply changing the file path and extension when opening the file with the fiona.open() method. For example, to read a geojson file, you would use:
Fiona also allows you to specify the driver when opening a file, in case the file format is not recognized by the library, this can be done by passing the driver name as a second argument to the fiona.open() method.
For example, to open a KML file, you would use:
Fiona also allows you to access the metadata of the file, such as the crs, schema, and properties, in a similar way as the features, it also allows you to write data to a file, in the same way you read it, you can simply iterate over the features and write them to a file.
It’s worth noting that fiona, as well as OGR, are powerful libraries that can handle a wide range of GIS data types and formats, it’s recommended to consult the Fiona documentation for more detailed information on how to use it and to have a deeper understanding of the functionality it offers.