-
Notifications
You must be signed in to change notification settings - Fork 21
/
dist.py
executable file
·60 lines (47 loc) · 1.86 KB
/
dist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
import argparse
import copy
import logging
import math
import os
logging.basicConfig(
format='%(asctime)s | %(levelname)s | %(message)s', level=logging.INFO)
_log = logging.getLogger(__name__)
logging.getLogger('geotiler').setLevel(logging.INFO)
logging.getLogger('geotiler.map').setLevel(logging.INFO)
logging.getLogger('geotiler.tilenet').setLevel(logging.INFO)
import cairocffi as cairo
import geotiler
import gpxpy
import numpy
import geo
import gfx
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('gpx_file', type=argparse.FileType('r'))
parser.add_argument('even', type=int, default=20)
parser.add_argument('-d', '--debug', action='store_true')
args = parser.parse_args()
if args.debug:
_log.setLevel(logging.DEBUG)
logging.getLogger('geotiler.tilenet').setLevel(logging.DEBUG)
gpx = gpxpy.parse(args.gpx_file)
# Join all the points from all segments for the track into a single list
gpx_points = [p for s in gpx.tracks[0].segments for p in s.points]
# Calculate map bounding box with padding
padding_pct = 10
bounds = gpx.get_bounds()
bbox = gfx.add_padding((bounds.min_longitude, bounds.min_latitude,
bounds.max_longitude, bounds.max_latitude), 10)
# Draw the original track
gpx_surface = gfx.draw_track(gpx_points, bbox)
gpx_img_filename = "original.png"
_log.info("Saving original track to '{}'".format(gpx_img_filename))
gpx_surface.write_to_png(gpx_img_filename)
# Evenly distribute the points
gpx_points = geo.interpolate_distance(gpx_points, args.even)
# Draw the distributed track
gpx_surface = gfx.draw_track(gpx_points, bbox)
gpx_img_filename = "even.png"
_log.info("Saving original track to '{}'".format(gpx_img_filename))
gpx_surface.write_to_png(gpx_img_filename)