示例#1
0
    def format_output(self, data):
        routes = []
        for r in data['routes']:
            duration = sum(leg['duration']['value'] for leg in r['legs'])
            distance = sum(leg['distance']['value'] for leg in r['legs'])

            maneuvers = []
            latlons = []
            # Legs are the spans of the route between waypoints desired. If
            # there are no waypoints, there will only be 1 leg
            for leg in r['legs']:
                for step in leg['steps']:
                    loc = step['start_location']
                    m = Maneuver((loc['lng'], loc['lat']),
                                 text=step['html_instructions'])
                    maneuvers.append(m)
                    d = step['polyline']['points'].encode('utf-8')
                    latlons.append(polycomp.decompress(d))

            # latlons is a list of list of lat/lon coordinate pairs. The end
            # point of each list is the same as the first point of the next
            # list. Get rid of the duplicates
            lines = [x[:-1] for x in latlons]
            lines.append([latlons[-1][-1]])  # Add the very last point
            points = itertools.chain(*lines)

            # Reverse lat/lon to be lon/lat for GeoJSON
            coords = [tuple(reversed(c)) for c in points]

            route = Route(coords, distance, duration, maneuvers=maneuvers)
            routes.append(route)

        return routes
示例#2
0
    def format_output(self, data):
        routes = []
        for r in data['routes']:
            duration = sum(leg['duration']['value'] for leg in r['legs'])
            distance = sum(leg['distance']['value'] for leg in r['legs'])

            latlons = []
            # Legs are the spans of the route between waypoints desired. If
            # there are no waypoints, there will only be 1 leg
            for leg in r['legs']:
                for step in leg['steps']:
                    latlons.append(
                        polycomp.decompress(step['polyline']['points']))

            # latlons is a list of list of lat/lon coordinate pairs. The end
            # point of each list is the same as the first point of the next
            # list. Get rid of the duplicates
            lines = [x[:-1] for x in latlons]
            lines.append([latlons[-1][-1]])  # Add the very last point
            points = itertools.chain(*lines)

            coords = [tuple(c) for c in points]
            route = {"coords": coords,"distance":distance,"duration":duration}
            routes.append(route)

        return routes
示例#3
0
    def format_output(self, data):
        routes = []
        for r in data['routes']:
            duration = sum(leg['duration']['value'] for leg in r['legs'])
            distance = sum(leg['distance']['value'] for leg in r['legs'])

            maneuvers = []
            latlons = []
            # Legs are the spans of the route between waypoints desired. If
            # there are no waypoints, there will only be 1 leg
            for leg in r['legs']:
                for step in leg['steps']:
                    loc = step['start_location']
                    m = Maneuver((loc['lng'], loc['lat']),
                                 text=step['html_instructions'])
                    maneuvers.append(m)
                    latlons.append(
                        polycomp.decompress(step['polyline']['points']))

            # latlons is a list of list of lat/lon coordinate pairs. The end
            # point of each list is the same as the first point of the next
            # list. Get rid of the duplicates
            lines = [x[:-1] for x in latlons]
            lines.append([latlons[-1][-1]])  # Add the very last point
            points = itertools.chain(*lines)

            # Reverse lat/lon to be lon/lat for GeoJSON
            coords = [tuple(reversed(c)) for c in points]

            route = Route(coords, distance, duration, maneuvers=maneuvers)
            routes.append(route)

        return routes
示例#4
0
    def format_output(self, data):
        routes = []
        for r in data['routes']:
            duration = sum(leg['duration']['value'] for leg in r['legs'])
            distance = sum(leg['distance']['value'] for leg in r['legs'])

            latlons = []
            # Legs are the spans of the route between waypoints desired. If
            # there are no waypoints, there will only be 1 leg
            for leg in r['legs']:
                for step in leg['steps']:
                    latlons.append(
                        polycomp.decompress(step['polyline']['points']))

            # latlons is a list of list of lat/lon coordinate pairs. The end
            # point of each list is the same as the first point of the next
            # list. Get rid of the duplicates
            lines = [x[:-1] for x in latlons]
            lines.append([latlons[-1][-1]])  # Add the very last point
            points = itertools.chain(*lines)

            coords = [tuple(c) for c in points]
            route = {
                "coords": coords,
                "distance": distance,
                "duration": duration
            }
            routes.append(route)

        return routes
示例#5
0
    def format_output(self, data):
        latlons = polycomp.decompress(data['route']['shape']['shapePoints'])
        coords = [tuple(reversed(c)) for c in latlons]
        duration = data['route']['time']
        distance = data['route']['distance'] * 1000  # km to m

        maneuvers = []
        for leg in data['route']['legs']:
            for m_in in leg['maneuvers']:
                loc = m_in['startPoint']
                m = Maneuver((loc['lng'], loc['lat']), text=m_in['narrative'])
                maneuvers.append(m)
        r = Route(coords, distance, duration, maneuvers=maneuvers)

        return [r]
示例#6
0
    def format_output(self, data):
        latlons = polycomp.decompress(data["route"]["shape"]["shapePoints"])
        coords = [tuple(reversed(c)) for c in latlons]
        duration = data["route"]["time"]
        distance = data["route"]["distance"] * 1000  # km to m

        maneuvers = []
        for leg in data["route"]["legs"]:
            for m_in in leg["maneuvers"]:
                loc = m_in["startPoint"]
                m = Maneuver((loc["lng"], loc["lat"]), text=m_in["narrative"])
                maneuvers.append(m)
        r = Route(coords, distance, duration, maneuvers=maneuvers)

        return [r]
示例#7
0
    def format_output(self, data):
        latlons = polycomp.decompress(data['route']['shape']['shapePoints'])
        coords = [tuple(reversed(c)) for c in latlons]
        duration = data['route']['time']
        distance = data['route']['distance'] * 1000  # km to m

        maneuvers = []
        for leg in data['route']['legs']:
            for m_in in leg['maneuvers']:
                loc = m_in['startPoint']
                m = Maneuver((loc['lng'], loc['lat']),
                             text=m_in['narrative'])
                maneuvers.append(m)
        r = Route(coords, distance, duration, maneuvers=maneuvers)

        return [r]
示例#8
0
 def runTest(self):
     points = [(35.6, -82.55), (35.59985, -82.55015)]
     enc = compress(points)
     dec = decompress(enc)
     self.assertEqual(points, dec)
示例#9
0
 def runTest(self):
     dec = decompress(COMPRESSED_POLY)
     self.assertEqual(dec, DECOMPRESSED_POLY)
示例#10
0
from polycomp import (
    compress,
    decompress,
)


with open("cross_country.txt") as f:
    cross_country_poly = f.read().rstrip()

print("Length of cross-country polyline: {0}".format(len(cross_country_poly)))

#import profile
#pr = profile.Profile()
#for i in range(5):
#    print(pr.calibrate(100000))

cProfile.Profile.bias = 5.00374496255e-06

wow = decompress(cross_country_poly)
print("Number of points: {0}".format(len(wow)))

cProfile.run('decompress(cross_country_poly)', 'prof')
p = pstats.Stats('prof')
p.sort_stats('cumulative').print_stats(10)

bam = compress(wow)

cProfile.run('compress(wow)', 'prof')
p = pstats.Stats('prof')
p.sort_stats('cumulative').print_stats(10)