Commit 0afc1719 authored by Wit, Allard de's avatar Wit, Allard de
Browse files

Added writing KML files

parent 3433a997
......@@ -4,6 +4,7 @@
import click
from .csv2db import process_csv
from .csv2kml import generate_KML"With csvtools you can operate on CSV files")
......@@ -15,19 +16,21 @@ def cli():
@click.argument("csv_fname", type=click.Path(exists=True))
@click.argument("sqlite_fname", type=click.Path())
def cmd_csv2db(csv_fname, sqlite_fname):
"""Function for the commandline interface for csv2db
process_csv(csv_fname, sqlite_fname)
:param csv_fname: the CSV input filename
:param sqlite_fname: the SQLite output filename
process_csv(csv_fname, sqlite_fname)
@click.argument("csv_fname", type=click.Path(exists=True))
@click.argument("kml_fname", type=click.Path())
def cmd_csv2kml(csv_fname, kml_fname):
generate_KML(csv_fname, kml_fname)
def main():
if __name__ == "__main__":
if __name__ == '__main__':
\ No newline at end of file
from pathlib import Path
import datetime as dt
import simplekml
import pandas
def generate_KML(fname_csv, fname_kml):
fname_csv = Path(fname_csv).absolute()
fname_kml = Path(fname_kml).absolute()
df = pandas.read_csv(fname_csv)
kml = simplekml.Kml()
failures = 0
for i, row in enumerate(df.itertuples()):
pnt = kml.newpoint(, coords=[(row.longitude, row.latitude)], description=row.comments)
occurred = dt.datetime.strptime(row.datetime, "%m/%d/%Y %H:%M").date()
pnt.timestamp.when = occurred.isoformat()
except ValueError as e:
failures += 1
if i == 1000:
if failures:
print(f"{failures} points failed to convert to KML.")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment