Ejemplo n.º 1
0
def group():
    sortedArr = []
    centLondon = [51.5074, 0.1277]
    #without tiles="Stamen Watercolor"
    map = folium.Map(location=centLondon, zoom_start=10)
    fg = FeatureGroup(name="FG")
    for Team in teamList:
        # print("%s : x = %s , y = %s " % (Team, latList[teamList.index(str(Team))],longList[teamList.index(str(Team))] ))
        sortedArr.append([
            Team, latList[teamList.index(str(Team))],
            longList[teamList.index(str(Team))]
        ])

        fg.add_child(
            folium.Marker([
                latList[teamList.index(str(Team))], longList[teamList.index(
                    str(Team))]
            ],
                          popup=Team,
                          icon=folium.Icon(color='pink')))

        print([
            latList[teamList.index(str(Team))],
            longList[teamList.index(str(Team))]
        ])
    map.add_child(fg)
    # print(len(sortedArr))
    map.save("ftMap.html")
    webbrowser.open("ftMap.html")
Ejemplo n.º 2
0
    def test_feature_group(self):
        """Test FeatureGroup."""

        map = folium.Map()
        feature_group = FeatureGroup()
        feature_group.add_children(Marker([45, -30], popup=Popup('-30')))
        feature_group.add_children(Marker([45, 30], popup=Popup('30')))
        map.add_children(feature_group)
        map.add_children(folium.map.LayerControl())

        map._repr_html_()
Ejemplo n.º 3
0
def add_sector_information(base_map, geo_data):
    if geo_data is not None:  # Have real sectors
        feature_group = FeatureGroup(name='Sector Information',
                                     control=True,
                                     show=True)

        gdf_cols = ['CircleCode', 'GeoName', 'geometry']
        geo_data_sectors = geo_data[geo_data['type'] == 'sector']
        gdf = gpd.GeoDataFrame(geo_data_sectors[gdf_cols], crs="EPSG:4326")
        folium.GeoJson(gdf).add_to(feature_group)
        add_sector_labels(feature_group, geo_data)
        feature_group.add_to(base_map)
Ejemplo n.º 4
0
    def test_feature_group(self):
        """Test FeatureGroup."""

        map = folium.Map()
        feature_group = FeatureGroup()
        feature_group.add_child(Marker([45, -30], popup=Popup('-30')))
        feature_group.add_child(Marker([45, 30], popup=Popup('30')))
        map.add_child(feature_group)
        map.add_child(folium.map.LayerControl())

        map._repr_html_()

        bounds = map.get_bounds()
        assert bounds == [[45, -30], [45, 30]], bounds
Ejemplo n.º 5
0
def draw_circle_boundary(base_map, center_pt, circle_radius):
    # Draw the circle
    # marker_cluster = MarkerCluster(control=False)
    # marker_cluster.add_to(base_map)
    feature_group = FeatureGroup(name='circle boundary',
                                 control=True,
                                 show=True)

    circle_boundary = folium.vector_layers.Circle(center_pt,
                                                  circle_radius,
                                                  stroke=5,
                                                  color='Magenta',
                                                  opacity=0.5,
                                                  dash_array='4 1')
    circle_boundary.add_to(feature_group)
    feature_group.add_to(base_map)

    return circle_boundary
Ejemplo n.º 6
0
    def test_feature_group(self):
        """Test FeatureGroup."""

        map = folium.Map()
        feature_group = FeatureGroup()
        feature_group.add_children(Marker([45, -30], popup=Popup('-30')))
        feature_group.add_children(Marker([45, 30], popup=Popup('30')))
        map.add_children(feature_group)
        map.add_children(folium.map.LayerControl())

        map._repr_html_()
Ejemplo n.º 7
0
    def test_feature_group(self):
        """Test FeatureGroup."""

        map = folium.Map()
        feature_group = FeatureGroup()
        feature_group.add_child(Marker([45, -30], popup=Popup('-30')))
        feature_group.add_child(Marker([45, 30], popup=Popup('30')))
        map.add_child(feature_group)
        map.add_child(folium.map.LayerControl())

        map._repr_html_()

        bounds = map.get_bounds()
        assert bounds == [[45, -30], [45, 30]], bounds
Ejemplo n.º 8
0
def make_map(layer_geojson=None, points=None, circles=None, polyline=None, goal_line=None, margin=0,
             thermal_layer=False, waypoint_layer=False, extra_tracks=None, airspace_layer=None, bbox=None):
    if points is None:
        points = []

    if bbox:
        location = bbox_centre(bbox)
    else:
        location = [45, 10]
    folium_map = folium.Map(location=location, zoom_start=13, tiles="Stamen Terrain", width='100%',
                            height='75%')
    #     folium.LayerControl().add_to(folium_map)
    '''Define map borders'''
    # at this stage a track (layer_geojason has bbox inside,
    # otherwise (plotting wpts, airspace, task) we can use the bbox variable
    if bbox:
        folium_map.fit_bounds(bounds=bbox, max_zoom=13)

    if layer_geojson:

        '''Define map borders'''
        if layer_geojson["bbox"]:
            bbox = layer_geojson["bbox"]
            folium_map.fit_bounds(bounds=bbox, max_zoom=13)

        """Design track"""
        if layer_geojson["geojson"]:
            track = layer_geojson['geojson']['tracklog']
            folium.GeoJson(track, name='Flight', style_function=track_style_function).add_to(folium_map)
            if extra_tracks:
                extra_track_style_function = lambda colour: (
                    lambda x: {'color': colour if x['properties']['Track'] == 'Pre_Goal' else 'grey'})

                for extra_track in extra_tracks:
                    colour = extra_track['colour']
                    folium.GeoJson(extra_track['track'], name=extra_track['name'],
                                   style_function=extra_track_style_function(colour)).add_to(folium_map)

            if thermal_layer:
                thermals = layer_geojson['geojson']['thermals']
                thermal_group = FeatureGroup(name='Thermals', show=False)

                for t in thermals:
                    # icon = Icon(color='blue', icon_color='black', icon='sync-alt', angle=0, prefix='fas')
                    icon = CustomIcon('/app/airscore/static/img/thermal.png')
                    thermal_group.add_child(Marker([t[1], t[0]], icon=icon, popup=Popup(t[2])))

                folium_map.add_child(thermal_group)

            if waypoint_layer:
                waypoints = layer_geojson['geojson']['waypoint_achieved']
                waypoint_group = FeatureGroup(name='Waypoints Taken', show=False)
                for w in waypoints:
                    waypoint_group.add_child(Marker([w[1], w[0]], popup=Popup(w[5])))

                folium_map.add_child(waypoint_group)
    """Design cylinders"""
    if circles:
        for c in circles:
            """create design based on type"""
            if c['type'] == 'launch':
                col = '#996633'
            elif c['type'] == 'speed':
                col = '#00cc00'
            elif c['type'] == 'endspeed':
                col = '#cc3333'
            elif c['type'] == 'restricted':
                col = '#ff0000'
            else:
                col = '#3186cc'

            popup = folium.Popup(f"<b>{c['name']}</b><br>Radius: {str(c['radius_label'])} m.", max_width=300)

            folium.Circle(
                location=(c['latitude'], c['longitude']),
                radius=0.0 + c['radius'],
                popup=popup,
                color=col,
                weight=2,
                opacity=0.8,
                fill=True,
                fill_opacity=0.2,
                fill_color=col
            ).add_to(folium_map)

    """Plot tolerance cylinders"""
    if margin:
        for c in circles:
            """create two circles based on tolerance value"""
            folium.Circle(
                location=(c['latitude'], c['longitude']),
                radius=0.0 + c['radius'] * (1 + margin),
                popup=None,
                color="#44cc44",
                weight=0.75,
                opacity=0.8,
                fill=False
            ).add_to(folium_map)

            folium.Circle(
                location=(c['latitude'], c['longitude']),
                radius=0.0 + c['radius'] * (1 - margin),
                popup=None,
                color="#44cc44",
                weight=0.75,
                opacity=0.8,
                fill=False
            ).add_to(folium_map)

    """Plot waypoints"""
    if points:
        for p in points:
            folium.Marker(
                location=[p['latitude'], p['longitude']],
                popup=p['name'],
                icon=folium.features.DivIcon(
                    icon_size=(20, 20),
                    icon_anchor=(0, 0),
                    html='<div class="waypoint-label">%s</div>' % p['name'],
                )
            ).add_to(folium_map)

    """Design optimised route"""
    if polyline:
        folium.PolyLine(
            locations=polyline,
            weight=1.5,
            opacity=0.75,
            color='#2176bc'
        ).add_to(folium_map)

    if goal_line:
        folium.PolyLine(
            locations=goal_line,
            weight=1.5,
            opacity=0.75,
            color='#800000'
        ).add_to(folium_map)

    if airspace_layer:
        for space in airspace_layer:
            space.add_to(folium_map)

    # path where to save the map
    # folium_map.save('templates/map.html')
    folium.LayerControl().add_to(folium_map)
    folium.plugins.Fullscreen().add_to(folium_map)
    folium.plugins.MeasureControl().add_to(folium_map)
    return folium_map
Ejemplo n.º 9
0
def make_map(layer_geojson=None,
             points=None,
             circles=None,
             polyline=None,
             goal_line=None,
             margin=0,
             thermal_layer=False,
             show_thermal=False,
             waypoint_layer=False,
             show_waypoint=False,
             extra_tracks=None,
             airspace_layer=None,
             show_airspace=False,
             infringements=None,
             bbox=None,
             trackpoints=None):
    """Gets elements and layers from Flask, and returns map object"""
    '''creates layers'''
    if points is None:
        points = []

    if bbox:
        location = bbox_centre(bbox)
    else:
        location = [45, 10]

    folium_map = folium.Map(location=location,
                            position='relative',
                            zoom_start=13,
                            tiles="Stamen Terrain",
                            max_bounds=True,
                            min_zoom=5,
                            prefer_canvas=True)
    #     folium.LayerControl().add_to(folium_map)
    '''Define map borders'''
    # at this stage a track (layer_geojason has bbox inside,
    # otherwise (plotting wpts, airspace, task) we can use the bbox variable
    if bbox:
        folium_map.fit_bounds(bounds=bbox, max_zoom=13)

    if layer_geojson:
        '''Define map borders'''
        if layer_geojson["bbox"]:
            bbox = layer_geojson["bbox"]
            folium_map.fit_bounds(bounds=bbox, max_zoom=13)
        """Design track"""
        if layer_geojson["geojson"]:
            track = layer_geojson['geojson']['tracklog']
            folium.GeoJson(
                track, name='Flight',
                style_function=track_style_function).add_to(folium_map)
            if extra_tracks:
                extra_track_style_function = lambda colour: (lambda x: {
                    'color':
                    colour
                    if x['properties']['Track'] == 'Pre_Goal' else 'grey'
                })

                for extra_track in extra_tracks:
                    colour = extra_track['colour']
                    folium.GeoJson(extra_track['track'],
                                   name=extra_track['name'],
                                   style_function=extra_track_style_function(
                                       colour)).add_to(folium_map)

            if thermal_layer:
                thermals = layer_geojson['geojson']['thermals']
                thermal_group = FeatureGroup(name='Thermals',
                                             show=show_thermal)

                for t in thermals:
                    # icon = Icon(color='blue', icon_color='black', icon='sync-alt', angle=0, prefix='fas')
                    icon = CustomIcon('/app/airscore/static/img/thermal.png')
                    thermal_group.add_child(
                        Marker([t[1], t[0]], icon=icon, popup=Popup(t[2])))

                folium_map.add_child(thermal_group)

            if waypoint_layer:
                waypoints = layer_geojson['geojson']['waypoint_achieved']
                waypoint_group = FeatureGroup(name='Waypoints Taken',
                                              show=show_waypoint)
                for w in waypoints:
                    waypoint_group.add_child(
                        Marker([w[1], w[0]], popup=Popup(w[6], max_width=300)))

                folium_map.add_child(waypoint_group)
    """Design cylinders"""
    if circles:
        for c in circles:
            """create design based on type"""
            if c['type'] == 'launch':
                col = '#996633'
            elif c['type'] == 'speed':
                col = '#00cc00'
            elif c['type'] == 'endspeed':
                col = '#cc3333'
            elif c['type'] == 'restricted':
                col = '#ff0000'
            else:
                col = '#3186cc'

            popup = folium.Popup(
                f"<b>{c['name']}</b><br>Radius: {str(c['radius_label'])} m.",
                max_width=300)

            folium.Circle(location=(c['latitude'], c['longitude']),
                          radius=0.0 + c['radius'],
                          popup=popup,
                          color=col,
                          weight=2,
                          opacity=0.8,
                          fill=True,
                          fill_opacity=0.2,
                          fill_color=col).add_to(folium_map)
    """Plot tolerance cylinders"""
    if margin:
        for c in circles:
            """create two circles based on tolerance value"""
            folium.Circle(location=(c['latitude'], c['longitude']),
                          radius=0.0 + c['radius'] * (1 + margin),
                          popup=None,
                          color="#44cc44",
                          weight=0.75,
                          opacity=0.8,
                          fill=False).add_to(folium_map)

            folium.Circle(location=(c['latitude'], c['longitude']),
                          radius=0.0 + c['radius'] * (1 - margin),
                          popup=None,
                          color="#44cc44",
                          weight=0.75,
                          opacity=0.8,
                          fill=False).add_to(folium_map)
    """Plot waypoints"""
    if points:
        for p in points:
            folium.Marker(location=[p['latitude'], p['longitude']],
                          popup=p['name'],
                          icon=folium.features.DivIcon(
                              icon_size=(20, 20),
                              icon_anchor=(0, 0),
                              html='<div class="waypoint-label">%s</div>' %
                              p['name'],
                          )).add_to(folium_map)
    """Design optimised route"""
    if polyline:
        folium.PolyLine(locations=polyline,
                        weight=1.5,
                        opacity=0.75,
                        color='#2176bc').add_to(folium_map)

    if goal_line:
        folium.PolyLine(locations=goal_line,
                        weight=1.5,
                        opacity=0.75,
                        color='#800000').add_to(folium_map)

    if airspace_layer:
        airspace_group = FeatureGroup(name='Airspaces', show=show_airspace)
        for space in airspace_layer:
            airspace_group.add_child(space)
        if infringements:
            for i in infringements:
                popup = folium.Popup(
                    f"<b>{i[3]}</b><br>{i[5]}. separation: {i[4]} m. <br>"
                    f"{i[7]} - alt. {i[2]} m.",
                    max_width=300)
                icon = folium.Icon(color="red", icon="times", prefix='fa')
                airspace_group.add_child(
                    Marker([i[1], i[0]], icon=icon, popup=popup))
        folium_map.add_child(airspace_group)

    if trackpoints:
        trackpoints_group = FeatureGroup(name='Trackpoints', show=True)
        for i in trackpoints:
            tooltip = folium.Tooltip(
                f"Time UTC: <b>{i[5]}</b> Local Time: <b>{i[6]}</b><br>"
                f"lat: <b>{round(i[1], 4)}</b> lon: <b>{round(i[0], 4)}</b><br>"
                f"GPS alt: <b>{int(i[4])} m.</b> ISA Press alt: <b>{int(i[3])} m.</b>"
            )
            trackpoints_group.add_child(
                folium.CircleMarker((i[1], i[0]), radius=1, tooltip=tooltip))
        folium_map.add_child(trackpoints_group)

    folium.LayerControl().add_to(folium_map)
    folium.plugins.Fullscreen().add_to(folium_map)
    folium.plugins.MeasureControl().add_to(folium_map)
    return folium_map
Ejemplo n.º 10
0
import folium
import geopandas as gpd
from folium import plugins
from folium.map import FeatureGroup, LayerControl

seoul = gpd.read_file("data/maps/seoul.geojson")
schoolzone = gpd.read_file("data/maps/schoolzone-seoul.geojson")
cluster = gpd.read_file("data/cluster.geojson")
acdnt_cls = gpd.read_file("data/acdnt-cls.geojson")

featuregroup1 = FeatureGroup(name="사고발생좌표")
featuregroup2 = FeatureGroup(name="어린이보호구역추천")
featuregroup3 = FeatureGroup(name="스쿨존")


def seoul_style(feature):
    style = {'fillColor': '#00000000'}
    return style


def cluster_style(feature):
    style = {'color': "red", "fillColor": "red", "opacity": 0.9}
    return style


def schoolzone_style(feature):
    style = {'color': "green", 'fillColor': "#D68910", "opacity": 0.6}
    return style


m = folium.Map(location=[37.54, 126.98], zoom_start=12)
Ejemplo n.º 11
0
lat = combo['latitude'].values
dens = combo['Population Density'].astype(int).values
pop = combo['Population']
aff = combo['estCustAffected'].astype(int).values
#print(aff)
inc = combo['Per capita income'].astype(int).values
#print(inc)

mindens = dens.min()
maxdens = dens.max()

start_lat = 39
start_lon = -121.5

dens_steps = [0, 2000, 4000, 6000, 7000, 9000, 10000]
feature_group1 = FeatureGroup(name='Less than 2000 Population Density')
feature_group2 = FeatureGroup(name='2000 - 4000 Population Density')
feature_group3 = FeatureGroup(name='4000 - 6000 Population Density')
feature_group4 = FeatureGroup(name='6000 - 7000 Population Density')
feature_group5 = FeatureGroup(name='7000 - 9000 Population Density')
feature_group6 = FeatureGroup(name='More than 10000 Population Density')

feat_list = [feature_group1, feature_group2, feature_group3, feature_group4, \
    feature_group5, feature_group6]

folium_map = folium.Map(location=[start_lat, start_lon], zoom_start=8)
cmap = cm.LinearColormap(colors=['red', 'yellow'],
                         index=[mindens, maxdens],
                         vmin=mindens,
                         vmax=maxdens)
cmap = cmap.to_step(n=12, method='log', round_method='log10')
Ejemplo n.º 12
0
dens = combo['Population Density'].astype(int).values
pop = combo['Population']
aff = combo['estCustAffected'].astype(int).values
#print(aff)
inc = combo['Per capita income'].astype(int).values
#print(inc)

thousand = 1000
mininc = inc.min()/thousand
maxinc = inc.max()/thousand

start_lat = 39
start_lon = -121.5

income_steps = [0, 30000, 50000, 80000, 100000, 200000]
feature_group1 = FeatureGroup(name='Less than $30,000 Per Capita Income')
feature_group2 = FeatureGroup(name='$30,000-$50,000 Per Capita Income')
feature_group3 = FeatureGroup(name='$50,000-$80,000 Per Capita Income')
feature_group4 = FeatureGroup(name='$80,000-$100,000 Per Capita Income')
feature_group5 = FeatureGroup(name='More than $100,000 Per Capita Income')

feat_list = [feature_group1, feature_group2, feature_group3, feature_group4, feature_group5]

folium_map = folium.Map(location=[start_lat, start_lon], 
						zoom_start = 8)
cmap = cm.LinearColormap(colors=['red', 'yellow'], index=[mininc, maxinc],
    vmin=mininc, vmax=maxinc)
cmap = cmap.to_step(n=12, method='log', round_method='log10')
cmap.caption = 'Per Capita Income in Thousands of Dollars ($1,000)'

for index, row in combo.iterrows():
Ejemplo n.º 13
0
    def layer_gen(self, group, group_id, show):
        """ Generates a bubbles layer """
        # Get the color of the bubble according to layer definitions
        color = 'blue'
        chart_options = self.options.get('chart_options', {})
        for ind_index in range(len(chart_options.get('indicadores', []))):
            if chart_options.get('indicadores')[ind_index] == group_id:
                color = chart_options.get('colorArray')[ind_index]
                break

        # Adding circle radius to group, if it's not present in dataframe group
        if 'radius' not in group.columns:
            group['radius'] = self.assess_radius(group)

        if 'timeseries' not in chart_options:
            # Creating a layer for the group
            layer = FeatureGroup(
                name=ViewConfReader.get_layers_names(self.options.get('headers')).get(group_id),
                show=show
            )

            # Check if popup data is present
            has_tooltip = 'tooltip' in group.columns

            # Generating circles
            for _row_index, row in group.iterrows():
                tooltip_data = None
                if has_tooltip:
                    tooltip_data = row['tooltip']

                CircleMarker(
                    location=[
                        row[chart_options.get('lat', 'latitude')],
                        row[chart_options.get('long', 'longitude')]
                    ],
                    radius=row['radius'],
                    popup=tooltip_data,
                    color=color,
                    fill=True,
                    fill_color=color
                ).add_to(layer)

            # Adding layer to map
            return layer
        else:
            features = []
            for _row_index, row in group.iterrows():
                features.append({
                    'type': 'Feature',
                    'geometry': {
                        'type': 'Point',
                        'coordinates': [
                            row[chart_options.get('long', 'longitude')],
                            row[chart_options.get('lat', 'latitude')]
                        ]
                    },
                    'properties': {
                        'time': pd.to_datetime(
                            row[chart_options.get('timeseries', 'nu_competencia')],
                            format='%Y'
                        ).__str__(),
                        'style': {'color': color},
                        'icon': 'circle',
                        'iconstyle': {
                            'fillColor': color,
                            'fillOpacity': 0.8,
                            'stroke': 'true',
                            'radius': row['radius']
                        }
                    }
                })

            return TimestampedGeoJson(
                features,
                period='P1Y',
                duration='P1Y',
                date_options='YYYY',
                transition_time=1000,
                auto_play=True
            )