Skip to content

Instantly share code, notes, and snippets.

@tkrajina
Created March 9, 2014 06:57
Show Gist options
  • Save tkrajina/9443878 to your computer and use it in GitHub Desktop.
Save tkrajina/9443878 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import logging as mod_logging
import cartesius.main as mod_cartesius
import cartesius.charts as mod_charts
import cartesius.colors as mod_colors
import srtm as mod_srtm
import gpxpy.geo as mod_geo
mod_logging.basicConfig(level=mod_logging.DEBUG,
format='%(asctime)s %(name)-12s %(levelname)-8s %(message)s')
def get_smoothed_chart_data(data):
result = []
for i in range(len(data)):
angle = data[i][0]
value = data[i][1]
if value <= -1000 or value >= 9000:
value = 0
else:
value = data[i - 2][1] * .1 \
+ data[i - 1][1] * .25 \
+ data[i][1] * .4 \
+ data[(i + 1) % len(data)][1] * .25 \
+ data[(i + 2) % len(data)][1] * .1
chart_data = mod_charts.data(angle, value)
result.append(chart_data)
return result
def get_image(center, bounds, image_dimensions, distance_from, distance_to, distance_step):
elevation_data = mod_srtm.get_data()
coordinate_system = mod_cartesius.CoordinateSystem(bounds=bounds)
center.elevation = elevation_data.get_elevation(center.latitude, center.longitude)
max_angle = {}
color_from, color_to = (200, 200, 200), (0, 7, 232)
angle_steps = 720
for distance in range(distance_from, distance_to, distance_step):
elevations_and_angles = []
print 'distance:', distance
data = []
for i in range(angle_steps):
angle = i / float(angle_steps) * 360
location = center + mod_geo.LocationDelta(angle=angle, distance=distance)
location.elevation = elevation_data.get_elevation(location.latitude, location.longitude)
elevation_angle = center.elevation_angle(location) or 0
if elevation_angle in max_angle:
if elevation_angle > max_angle:
max_angle = elevation_angle
else:
elevation_angle = 0
else:
max_angle[angle] = elevation_angle
data.append((angle, elevation_angle, ))
elevations_and_angles = get_smoothed_chart_data(data)
color = mod_colors.get_color_between(color_to, color_from, (distance - distance_from) / float(distance_to - distance_from))
coordinate_system.add(mod_charts.LineChart(data=elevations_and_angles, fill_color=color, color=(100, 100, 100)))
#print elevations_and_angles
return coordinate_system.draw(image_dimensions[0], image_dimensions[1])
if __name__ == '__main__':
# Dol:
#get_image(mod_geo.Location(45.40070, 14.192807), (0, 360, 0, 40), (800, 300), 100, 20000, 200).show()
# Brest
#get_image(mod_geo.Location(45.4558867, 14.0061431), (0, 360, 0, 40), (800, 300), 100, 20000, 100).show()
# Pod Triglavom
get_image(mod_geo.Location(46.408999, 13.84340), (0, 360, 0, 40), (800, 300), 100, 20000, 300).save('triglav.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment