Calculates the centroid of a polygon from a given KML file
- Python 3
shapely
libraryfastkml
librarypygeoif
library
Install dependencies via pip:
pip install shapely fastkml pygeoif
To run the script, use the following command:
./polygon_centroid_computer.py <path_to_kml_file>
The script prints the centroid coordinates (x, y)
of the first polygon found in the KML file.
./polygon_centroid_computer.py example.kml
Centroid: (longitude, latitude)
- If no polygon is found, a
ValueError
is raised. - If an incorrect number of arguments is provided, usage instructions are printed.
- The script examines KML files for Placemarks containing polygon geometry and computes the centroid of the first polygon found.
This project is licensed under the MIT License. See the LICENSE file for details.