KML (Keyhole Markup Language) and shapefiles are two different file formats used for storing geographical data. While how to spot fake nike dunks KML is used for representing spatial information for display in Google Earth, shapefiles are commonly used for GIS applications. There might be a need Женские кроссовки adidas campus новинка! — цена 2599 грн в каталоге Кроссовки ✓ Купить женские вещи по доступной цене на Шафе , adidas krampon predator black people women ugly , Украина #161888213 to convert KML files to shapefiles for use in a GIS application or vice versa. This can be easily achieved using python programming language.
In this article, we will demonstrate how to convert a KML file to a shapefile using Python.
Prerequisites
Before we begin, make sure that you have the following python libraries installed:
- Fiona
- geopandas
- pyproj
If you don’t have these libraries installed, you can install them by running the following command in your terminal:
pip install fiona geopandas pyproj
Converting KML to shapefile
The process of converting a KML file to a shapefile involves the following steps:
- Read the KML file into a
GeoDataFrame. - Write the
GeoDataFrameto a shapefile.
Here is the code that implements these steps:
import geopandas as gpd
# Read the KML file into a GeoDataFrame
kml_file = "path/to/kml/file.kml"
gdf = gpd.read_file(kml_file, driver='KML')
# Write the GeoDataFrame to a shapefile
shp_file = "path/to/shapefile/file.shp"
gdf.to_file(shp_file, driver='ESRI Shapefile')
That’s it! Now you have successfully converted a KML file to a shapefile using python.
Conclusion
In this article, we demonstrated how to convert a KML file to a shapefile using Python. The process involves reading the KML file into a GeoDataFrame and writing the GeoDataFrame to a shapefile. By using the geopandas and fiona libraries, the process is straightforward and easy to implement. With these tools, you can now integrate KML data into your GIS workflow or vice versa.
Kumbirai is a GIS & MEAL specialist using geospatial analytics to advance global health and social impact. A certified Data Protection Officer (DPO), an open-data advocate and self-taught software developer, he builds web GIS tools that turn field data into decisions. He lectures in GIS/Remote Sensing and mentors emerging practitioners. Founder of a geospatial startup and nonprofit, he believes, “Real geospatial innovation happens when we empower communities with the right tools and knowledge.” Open to consulting and collaborations.

I am receiving this error, when I run your code:
Traceback (most recent call last):
File “c:\Users\Social Media\Desktop\python\Desktop\python\.ipynb_checkpoints\kml2shp”, line 7, in
gdf = gpd.read_file(kml_file, driver=’KML’)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Social Media\Desktop\python\charting\Lib\site-packages\geopandas\io\file.py”, line 297, in _read_file
return _read_file_fiona(
^^^^^^^^^^^^^^^^^
File “C:\Users\Social Media\Desktop\python\charting\Lib\site-packages\geopandas\io\file.py”, line 338, in _read_file_fiona
with reader(path_or_bytes, **kwargs) as features:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\Social Media\Desktop\python\charting\Lib\site-packages\fiona\env.py”, line 457, in wrapper
return f(*args, **kwds)
^^^^^^^^^^^^^^^^
File “C:\Users\Social Media\Desktop\python\charting\Lib\site-packages\fiona\__init__.py”, line 305, in open
colxn = Collection(
^^^^^^^^^^^
File “C:\Users\Social Media\Desktop\python\charting\Lib\site-packages\fiona\collection.py”, line 252, in __init__
self.guard_driver_mode()
File “C:\Users\Social Media\Desktop\python\charting\Lib\site-packages\fiona\collection.py”, line 273, in guard_driver_mode
raise DriverError(“unsupported driver: %r” % driver)
fiona.errors.DriverError: unsupported driver: ‘KML’
Hi Huzaifa, I am sorry to hear about your experience. After the article was published there have been a number of changes to Python libraries and versions. Can you try out the following if the issue has not yet been resolved:
pip install libkmlAfter installing ‘libkml’, modify your code to use the ‘libkml’ driver for reading KML files. Here’s the updated code:
import geopandas as gpd
# Read the KML file into a GeoDataFrame using libkml driver
kml_file = "path/to/kml/file.kml"
gdf = gpd.read_file(kml_file, driver='libkml')
# Write the GeoDataFrame to a shapefile
shp_file = "path/to/shapefile/file.shp"
gdf.to_file(shp_file, driver='ESRI Shapefile')
I hope this will resolve your issue.
I am having the same problem using Python 3.11. Fiona no longer has a KML driver. When I tried to pip install libkml in the Spyder IDE I got this error:
ERROR: Could not find a version that satisfies the requirement libkml (from versions: none)
ERROR: No matching distribution found for libkml
These are the current fiona drivers:
print(fiona.supported_drivers)
{‘DXF’: ‘rw’, ‘CSV’: ‘raw’, ‘OpenFileGDB’: ‘raw’, ‘ESRIJSON’: ‘r’, ‘ESRI Shapefile’: ‘raw’, ‘FlatGeobuf’: ‘raw’, ‘GeoJSON’: ‘raw’, ‘GeoJSONSeq’: ‘raw’, ‘GPKG’: ‘raw’, ‘GML’: ‘rw’, ‘OGR_GMT’: ‘rw’, ‘GPX’: ‘rw’, ‘Idrisi’: ‘r’, ‘MapInfo File’: ‘raw’, ‘DGN’: ‘raw’, ‘PCIDSK’: ‘raw’, ‘OGR_PDS’: ‘r’, ‘S57’: ‘r’, ‘SQLite’: ‘raw’, ‘TopoJSON’: ‘r’}