Esempio n. 1
0
    def draw(self, referential_race_name, comparison_race_name, segment_type, filename):
        """Draw both races and the corresponding best segment"""
        race_manager = self.race_inferer.race_manager
        referential_race = race_manager.races[referential_race_name]
        comparison_race = race_manager.races[comparison_race_name]

        deniv_segment, length_segment, density_segment = self.get_best_segment(referential_race_name)
        segments = deniv_segment + length_segment + density_segment

        segment = None

        for segment_tuple in segments:
            if segment_tuple[0] == comparison_race_name and segment_tuple[1].segment_type == segment_type:
                segment = segment_tuple[1]
                break

        if GOOGLE_MAP_API_KEY is None:
            gmap3 = GoogleMapPlotter(46.98, 6.89, 14)
        else:
            gmap3 = GoogleMapPlotter(46.98, 6.89, 14, apikey=GOOGLE_MAP_API_KEY)

        gmap3.plot(referential_race.df.position_lat, referential_race.df.position_long, 'cornflowerblue',
                   edge_width=2.5)
        gmap3.plot(comparison_race.df.position_lat, comparison_race.df.position_long, 'limegreen',
                   edge_width=2.5)

        segment.draw('red', gmap3)

        gmap3.draw(filename)
Esempio n. 2
0
def main(args):

    path = get_path(args[0])
    date = args[0].strip().split('/')

    airports, commands = handle_args(args)
    print 'Airports: ' + str(airports)
    flightdata = sc.textFile(path).map(parse_flights)
    airportdata = get_airport_data(airports)
    i = 0.5
    if len(airports) == 1:
        i = 1.5
    (lat_range, lon_range) = get_area(airportdata,i)


    flightdata = flightdata.filter(lambda x: x['lat'] >= (lat_range['min']-1) and x['lat'] <= (lat_range['max']+1)
                        and x['lon'] >= (lon_range['min']-1) and x['lon'] <= (lon_range['max']+1))

    boundary_paths = get_boundary_paths({'lat': lat_range, 'lon': lon_range})
    ctr_lat = (lat_range['min']+lat_range['max'])/2
    ctr_lon = (lon_range['min']+lon_range['max'])/2

    gmap = GoogleMapPlotter(ctr_lat, ctr_lon, 8)
    for path in boundary_paths:
        gmap.plot(path['lat_range'], path['lon_range'], 'cornflowerblue', edge_width=10)


    if len(airports) >= 2:
        alldata = flightdata.filter(lambda x: x['arr_airport'] in airports and x['dep_airport'] in airports)
    else:
        alldata = flightdata.filter(lambda x: x['arr_airport'] in airports)

    alldata.cache()
    detect_info = detect_delay(alldata,airports,gmap)
Esempio n. 3
0
    def draw_race_and_matches(self, race, matches):
        if GOOGLE_MAP_API_KEY is None:
            gmap3 = GoogleMapPlotter(46.98, 6.89, 14)
        else:
            gmap3 = GoogleMapPlotter(46.98, 6.89, 14, apikey=GOOGLE_MAP_API_KEY)

        gmap3.plot(race.df.position_lat, race.df.position_long, 'cornflowerblue', edge_width=2.5)

        for (race_name, match) in matches:
            match.draw('yellow', gmap3=gmap3)

        return gmap3
Esempio n. 4
0
    def draw(self, color='cornflowerblue', gmap3=None):
        if gmap3 is None:
            if GOOGLE_MAP_API_KEY is None:
                gmap3 = GoogleMapPlotter(46.98, 6.89, 14)
            else:
                gmap3 = GoogleMapPlotter(46.98,
                                         6.89,
                                         14,
                                         apikey=GOOGLE_MAP_API_KEY)

        gmap3.plot(self.df.position_lat,
                   self.df.position_long,
                   color,
                   edge_width=2.5)

        filename = os.path.join(st.files["output_folder"], f"{self.name}.html")
        gmap3.draw(filename)
Esempio n. 5
0
    def service_cb(self, request):
        dt = (rospy.Time.now() - self.last_called_stamp).to_sec()
        if dt < self.MIN_TIME_BETWEEN_CALLS:
            raise rospy.ServiceException(
                "Minimum time between plot requests is %f seconds.  It's only been %f seconds"
                % (self.MIN_TIME_BETWEEN_CALLS, dt))

        if len(request.points) == 0:
            raise rospy.ServiceException('No points present in request')

        # Sort points into sequential groups of like types
        plot_groups = []
        for p in request.points:
            added_to_group = False
            # See if next point belongs in an existing group
            for group in plot_groups:
                added_to_group = group.add_to_group(p)

            # Create new plotting group if current point hasn't been added
            # to an existing one
            if not added_to_group:
                plot_groups.append(PlotGroup(p))

        # Initialize Google Maps plot
        map_type = 'satellite' if request.satellite_view else None
        gplot = GoogleMapPlotter(request.center_lat,
                                 request.center_lon,
                                 request.zoom,
                                 map_type=map_type)

        # Loop through plotting groups to add plots to map
        for group in plot_groups:
            lats = [p.lat for p in group.members]
            lons = [p.lon for p in group.members]
            colors = [p.color for p in group.members]
            texts = [p.text for p in group.members]

            if group.type == PlotPoint.SCATTER_POINT:
                gplot.scatter(lats,
                              lons,
                              group.color,
                              size=group.size,
                              marker=False)
            elif group.type == PlotPoint.LINE:
                gplot.plot(lats, lons, group.color, edge_width=group.size)
            elif group.type == PlotPoint.MARKER:
                gplot.scatter(lats, lons, group.color, marker=True)
            elif group.type == PlotPoint.TEXT_LABEL or group.type == PlotPoint.MARKER_WITH_TEXT:
                for i in xrange(len(group.members)):
                    gplot.text(
                        lats[i],
                        lons[i],
                        colors[i],
                        text=texts[i],
                        marker=(group.type == PlotPoint.MARKER_WITH_TEXT))
            else:
                raise rospy.ServiceException(
                    'Tried to plot an unsupported type')

        self.last_called_stamp = rospy.Time.now()
        if request.save_map:
            # Just write map to designated file and be done
            gplot.draw(request.filename, self.api_key)
            rospy.loginfo('Saving map to: %s' % request.filename)
        else:
            # Write the map to the temporary file and immediately open default
            # browser to view it
            gplot.draw(self.tmp.name, self.api_key)
            os.system('xdg-open ' + self.tmp.name)

        return PlotMapResponse()
Esempio n. 6
0
# import gmplot
from gmplot import GoogleMapPlotter

mymap = GoogleMapPlotter(37.428, -122.145, 16)
# mymap.marker(37.427, -122.145, "yellow")
# mymap.marker(37.428, -122.146, "cornflowerblue")
path = [(37.429, 37.428, 37.427, 37.427, 37.427),
             (-122.145, -122.145, -122.145, -122.146, -122.146)]
path2 = [[i+.01 for i in path[0]], [i+.02 for i in path[1]]]
path3 = [(37.433302 , 37.431257 , 37.427644 , 37.430303), (-122.14488, -122.133121, -122.137799, -122.148743)]
path4 = [(37.423074, 37.422700, 37.422410, 37.422188, 37.422274, 37.422495, 37.422962, 37.423552, 37.424387, 37.425920, 37.425937),
     (-122.150288, -122.149794, -122.148936, -122.148142, -122.146747, -122.14561, -122.144773, -122.143936, -122.142992, -122.147863, -122.145953)]
# mymap.plot(path[0], path[1], "plum", edge_width=10)
# mymap.plot(path2[0], path2[1], "red")
# mymap.polygon(path3[0], path3[1], edge_color="cyan", edge_width=5, face_color="blue", face_alpha=0.1)
# mymap.heatmap(path4[0], path4[1], threshold=10, radius=40)
# mymap.heatmap(path3[0], path3[1], threshold=10, radius=40, dissipating=False, gradient=[(30,30,30,0), (30,30,30,1), (50, 50, 50, 1)])
# mymap.scatter(path4[0], path4[1], c='r', marker=True)
# mymap.scatter(path4[0], path4[1], s=90, marker=False, alpha=0.1)

edge = [(37.429, 37.428),(-122.145, -122.145)]
mymap.plot(edge[0], edge[1], "plum", edge_width=20)

mymap.draw("mymap.html")