-
Notifications
You must be signed in to change notification settings - Fork 58
/
gpx_sample_images.py
51 lines (37 loc) · 1.69 KB
/
gpx_sample_images.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
import gpxpy as mod_gpxpy # type: ignore
import cartesius.main as mod_cartesius # type: ignore
import cartesius.charts as mod_charts # type: ignore
import cartesius.elements as mod_elements # type: ignore
import logging as mod_logging
import srtm as mod_srtm
from typing import *
mod_logging.basicConfig(level=mod_logging.DEBUG,
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
def get_line(gpx: Any, color: Any, transparency_mask: Any=None) -> Any:
def f() -> Any:
previous_point = None
length = 0
for point in gpx.walk(only_points=True):
if previous_point:
length += previous_point.distance_2d(point)
previous_point = point
yield mod_charts.data(length, point.elevation)
return mod_charts.LineChart(data=f, color=color, transparency_mask=transparency_mask)
def sample_gpx() -> Any:
return mod_gpxpy.parse(open('sample_files/setnjica-kod-karojbe.gpx'))
coordinate_system = mod_cartesius.CoordinateSystem(bounds=(-300, 6800, -40, 480))
coordinate_system.add(mod_elements.Grid(20, 100))
gpx = sample_gpx()
coordinate_system.add(get_line(gpx, color=(0, 0, 0)))
data = mod_srtm.get_data()
gpx = sample_gpx()
data.add_elevations(gpx)
coordinate_system.add(get_line(gpx, color=(0, 0, 255), transparency_mask=150))
gpx = sample_gpx()
data.add_elevations(gpx, smooth=True)
coordinate_system.add(get_line(gpx, color=(255, 0, 0)))
coordinate_system.add(mod_elements.Axis(horizontal=True, labels=500, points=100))
coordinate_system.add(mod_elements.Axis(vertical=True, labels=100, points=20))
image = coordinate_system.draw(600, 400, antialiasing=True)
#image.show()
image.save('gpx_elevations.png')