# Path: map/printing.py
# def svg_string_to_png(svg_string):
#     io_buffer = StringIO()
#     cairosvg.svg2png(bytestring=svg_string.encode('utf-8'), write_to=io_buffer)
#     return Image.open(StringIO(io_buffer.getvalue()))
# 
# Path: routing/mathfunctions.py
# def haversine(lon1, lat1, lon2, lat2):
#     """
#     Calculate the great circle distance between two points
#     on the earth (specified in decimal degrees)
#     """
#     # convert decimal degrees to radians
#     lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
#     # haversine formula
#     dlon = lon2 - lon1
#     dlat = lat2 - lat1
#     a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
#     c = 2 * asin(sqrt(a))
#     km = 6378.137 * c
#     return km


from numpy import *
from django.utils.translation import ugettext as _
from .printing import svg_string_to_png
from django.conf import settings
from routing.mathfunctions import haversine
import zipfile
            dist = haversine(nodes[i].lon, nodes[i].lat, nodes[i+1].lon, nodes[i+1].lat)
            sumdist += dist
            nodes[i+1].dist = dist
        return sumdist

    def _insert_nodes(self, nodes):
        """
        Adds some nodes if the distance between the given nodes is too long.
        """
        # Threshold defines which nodes should be divided.
        # If the overall distance is less than 50 km, threshold is 100m, because of
        # the granularity of height data.
        if self.sumdist < 50:
            threshold = 0.1
        else:
            threshold = self.sumdist/500
        analyzed_nodes = [nodes[0]]
        previous = nodes[0]
        for node in nodes[1:]:
            # if distance between current and previous node is greater than threshold
            if node.dist > threshold:
                # steps is the number of added nodes
                steps = int(math.floor(node.dist/threshold))
                dlat = (node.lat - previous.lat)/steps
                dlon = (node.lon - previous.lon)/steps
                # add nodes
                for step in range(steps):
                    newlat = analyzed_nodes[-1].lat + dlat
                    newlon = analyzed_nodes[-1].lon + dlon
                    new_node = ProfileNode(newlat, newlon)

# Path: map/printing.py
# def svg_string_to_png(svg_string):
#     io_buffer = StringIO()
#     cairosvg.svg2png(bytestring=svg_string.encode('utf-8'), write_to=io_buffer)
#     return Image.open(StringIO(io_buffer.getvalue()))
# 
# Path: routing/mathfunctions.py
# def haversine(lon1, lat1, lon2, lat2):
#     """
#     Calculate the great circle distance between two points
#     on the earth (specified in decimal degrees)
#     """
#     # convert decimal degrees to radians
#     lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
#     # haversine formula
#     dlon = lon2 - lon1
#     dlat = lat2 - lat1
#     a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
#     c = 2 * asin(sqrt(a))
#     km = 6378.137 * c
#     return km


# Path: map/altitude.py
from numpy import *
from django.utils.translation import ugettext as _
from .printing import svg_string_to_png
from django.conf import settings
from routing.mathfunctions import haversine
import zipfile

            dist = haversine(nodes[i].lon, nodes[i].lat, nodes[i+1].lon, nodes[i+1].lat)
            sumdist += dist
            nodes[i+1].dist = dist
        return sumdist

    def _insert_nodes(self, nodes):
        """
        Adds some nodes if the distance between the given nodes is too long.
        """
        # Threshold defines which nodes should be divided.
        # If the overall distance is less than 50 km, threshold is 100m, because of
        # the granularity of height data.
        if self.sumdist < 50:
            threshold = 0.1
        else:
            threshold = self.sumdist/500
        analyzed_nodes = [nodes[0]]
        previous = nodes[0]
        for node in nodes[1:]:
            # if distance between current and previous node is greater than threshold
            if node.dist > threshold:
                # steps is the number of added nodes
                steps = int(math.floor(node.dist/threshold))
                dlat = (node.lat - previous.lat)/steps
                dlon = (node.lon - previous.lon)/steps
                # add nodes
                for step in range(steps):
                    newlat = analyzed_nodes[-1].lat + dlat
                    newlon = analyzed_nodes[-1].lon + dlon
                    new_node = ProfileNode(newlat, newlon)

                    new_node.dist = haversine(analyzed_nodes[-1].lon, analyzed_nodes[-1].lat, newlon, newlat)