Last active
November 21, 2017 14:41
-
-
Save sourceperl/712b7ad5a506791206b5136882913cd1 to your computer and use it in GitHub Desktop.
Convert Placemark from google address KML to CSV like output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
# KML converter for "google address" | |
import argparse | |
# from here https://github.com/martinblech/xmltodict | |
import xmltodict | |
# parse args | |
parser = argparse.ArgumentParser() | |
parser.add_argument('kml_file', type=str, help='KML file to parse') | |
args = parser.parse_args() | |
# open XML and decode | |
with open(args.kml_file, 'rb') as f: | |
kml_dict = xmltodict.parse(f) | |
for pm in kml_dict['kml']['Document']['Folder']['Placemark']: | |
name = pm['name'] | |
coordinates = pm['Point']['coordinates'] | |
data = coordinates.split(',') | |
long, lat, _ = map(float, data) | |
print('"%50s", "%.8f", "%.8f"' % (name, lat, long)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment