forked from tkrajina/srtm.py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpx_sample_images.py
49 lines (36 loc) · 1.57 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
import gpxpy as mod_gpxpy
import cartesius.main as mod_cartesius
import cartesius.charts as mod_charts
import cartesius.elements as mod_elements
import logging as mod_logging
import srtm as mod_srtm
mod_logging.basicConfig(level=mod_logging.DEBUG,
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
def get_line(gpx, color, transparency_mask=None):
def f():
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():
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')