kml2geojson is a Python 3.4+ package to convert KML files to GeoJSON files. Most of its code is a translation into Python of the Node.js package togeojson, but kml2geojson also adds the following features.
- Preserve KML object styling, such as color and opacity
- Optionally write one JSON file cataloging all the KML styles used
- Optionally create several GeoJSON files of FeatureCollections, one for each KML folder
pip install kml2geojson
At the command line type k2g --help
for instructions.
You can also use kml2geojson as a library.
In docs
and on RawGit here.
- Development status: Alpha
- This project uses semantic versioning (major.minor.micro), where each breaking feature or API change is considered a major change
- Alex Raichev (2015-10-03)
If you want to help develop this project, here is some background reading.
- The KML reference
- Python's Minimal DOM implementation, which this project uses to parse KML files
- Fixed the bug where
setup.py
could not find the license file.
- Stopped making FeatureCollections with top-level 'properties' attributes, because RFC 7946 says that's not allowed. Moved FeatureCollection names into a top-level 'name' attribute.
- Stripped leading and trailing whitespace from text content to avoid cluttered or blank name and description attribute values
- Switched to pytest for testing
- Moved command line functionality to separate module
- Renamed some functions
Disambiguated filenames in main()
.
Improved to_filename()
again.
Improved to_filename()
and removed the lowercasing.
Tweaked to_filename()
to lowercase and underscore results.
Forgot to do that last time.
Changed the output of build_layers()
and moved layer names into the GeoJSON FeatureCollections
- Replaced underscores with dashes in command line options
- Set default border style for colored polygons
- Added documentation
- Tweaked the command line tool options
- Changed some names
- Added lots of tests
Fixed packaging to find README.rst
First