Exemplo n.º 1
0
def createMarkers(map,df,x,y,markers_name,comment_cols,comment_names,color_var,radius,colors,popup =True,indivMarkers = True):
    feature_group = FeatureGroup(name=markers_name)
    marker_cluster = MarkerCluster(name = 'Point clusters').add_to(map)
    for i in comment_cols:
        if df[i].dtype == object:
            df[i] = df[i].str.replace("'","'")
    for index, row in df.iterrows():
        if index % 1000 == 0:
            print(index,' markers added to the map!')
        x1,y1 = row[x],row[y]
#         x1_r,y1_r = "{0:.2f}".format(x1),"{0:.2f}".format(y1)
        popup_text = createPopupText(comment_names)
        comment_list = [row[i] for i in comment_cols]
        popup_text = popup_text.format(*comment_list)
        if "'" in popup_text:
            popup_text = popup_text.replace("'"," ")
        color = colors[list(df[color_var].unique()).index(row[color_var])]
        if popup == True:
            marker = folium.Circle(location = ([y1,x1]), fill=True,fill_opacity = 1,fill_color = color, color = color,radius = radius,popup = popup_text)
            folium.Circle(location = ([y1,x1]), fill=True,fill_opacity = 1,fill_color = color, color = color,radius = radius,popup = popup_text).add_to(marker_cluster)
        elif popup == False:
            marker = folium.Circle(location = ([y1,x1]), fill=True,fill_opacity = 1,fill_color = color, color = color,radius = radius)
            folium.Circle(location = ([y1,x1]), fill=True,fill_opacity = 1,fill_color = color, color = color,radius = radius).add_to(marker_cluster)
        feature_group.add_child(marker)
    if indivMarkers == True:
        map.add_child(feature_group)
Exemplo n.º 2
0
    def _add_layer(cls, map_object: Map,
                   layer_document: MapLayerDocument) -> None:
        """
        Create layer on a Folium Map. Method creates layer and adjusts it based on configuration. The layer is
        appended to the provided Folium Map.

        :param map_object: (Map) map object to create layer on

        :param layer_document: (MapLayerDocument) layer document configuration object.

        :return: None
        """
        model = layer_document.model
        latitude_column = layer_document.latitude
        longtitude_column = layer_document.longtitude

        axis = model.axis
        axis_label = axis.name or axis.data_field
        feature_group = FeatureGroup(name=axis_label)

        data_source = layer_document.data_source
        for row in data_source.itertuples():
            latitude = getattr(row, latitude_column.data_field)
            longtitude = getattr(row, longtitude_column.data_field)
            value = getattr(row, axis.data_field)

            coordinates = [latitude, longtitude]
            # model.figure.size *= 5
            marker = cls._create_marker(layer_value=str(value),
                                        coordinates=coordinates,
                                        layer_figure=model.figure)
            feature_group.add_child(marker)

        map_object.add_child(feature_group)
Exemplo n.º 3
0
def add_random_markers(feature_group: FeatureGroup) -> FeatureGroup:
    for i in range(random.randint(5, 10)):
        feature_group.add_child(child=Marker(location=[
            51.7522202 + random.uniform(-0.1, 0.1), -1.25596 +
            random.uniform(-0.1, 0.1)
        ],
                                             popup="Marker",
                                             icon=Icon()))
    return feature_group
Exemplo n.º 4
0
def get_population_feature_group() -> FeatureGroup:
    population_feature_group = FeatureGroup('Population')
    population_feature_group.add_child(
        GeoJson(
            data=open('world.json', mode='r', encoding='utf-8-sig').read(),
            style_function=lambda x: {
                'fillColor':
                'green' if x['properties']['POP2005'] < 10000000 else 'orange'
                if 10000000 <= x['properties']['POP2005'] < 20000000 else 'red'
            }))
    return population_feature_group
Exemplo n.º 5
0
def add_volcanoes(map):
    map = map
    volcanoes = read_excel('volcanoes.xlsx').iloc[1:, [1, 2, 4, 5, 6]]
    latitudes, longitudes = volcanoes['Latitude'], volcanoes['Longitude']
    name = volcanoes['Volcano Name']
    country = volcanoes['Country']
    elevation = volcanoes['Elev']

    fg_volcanoes = FeatureGroup(name='Volcanoes', show=False)

    def color_by_elevation(elev):
        if type(elev) == str:
            return 'white'
        if elev <= -4000:
            return 'darkblue'
        if elev <= -2000:
            return 'cadetblue'
        if elev <= 0:
            return 'lightblue'
        if elev <= 2000:
            return 'orange'
        if elev <= 4000:
            return 'red'
        if elev <= 6000:
            return 'darkred'
        else:
            return 'black'

    for i in range(len(volcanoes)):
        i += 1
        if isnan(elevation[i]):
            elevation[i] = 'Unknown'
        if name[i] == 'Unnamed':
            html = f'Volcano name:{name[i]}<br>Height: {elevation[i]} m<br> {country[i]}'
        else:
            html = f'Volcano name:<b4> <a href="https://www.google.com/search?q={name[i]} volcano" target="_blank">{name[i]}</a><br> \
                Height: {elevation[i]} m<br> {country[i]}'

        iframe = IFrame(html=html, width=200, height=100)
        coords = (latitudes[i], longitudes[i])
        fg_volcanoes.add_child(
            CircleMarker(location=coords,
                         popup=Popup(iframe),
                         color="gry",
                         fill_color=color_by_elevation(elevation[i]),
                         fill_opacity=0.9,
                         radius=6))
        i -= 1

    map.add_child(fg_volcanoes)
Exemplo n.º 6
0
def generate_map(name_and_coordinates:dict):
    """
    generates map
    """
    mp = Map( zoom_start=15) 
    markers = FeatureGroup() 
    for screen_name in name_and_coordinates:
        markers.add_child(Marker(location=[name_and_coordinates[screen_name][0], name_and_coordinates[screen_name][1]], 
                                    popup=screen_name, 
                                    icon=Icon())) 
    mp.add_child(markers) 
    mp.add_child(LayerControl()) 
 
    return mp._repr_html_()
Exemplo n.º 7
0
def get_volcanoes_feature_group() -> FeatureGroup:
    feature_group = FeatureGroup(name="Volcanoes")
    data = pandas.read_csv("./Volcanoes_USA.txt")
    latitudes = list(data['LAT'])
    longitudes = list(data['LON'])
    elevation = list(data['ELEV'])
    for lat, lon, elev in zip(latitudes, longitudes, elevation):
        feature_group.add_child(
            CircleMarker(location=(lat, lon),
                         color='grey',
                         weight=1,
                         radius=6,
                         popup=Popup(str(elev) + "m", parse_html=True),
                         fill_color=get_elevation_color(elev)))
    return feature_group
Exemplo n.º 8
0
def add_cities(map):
    cities = read_csv('worldcities.csv').iloc[:, [1, 2, 3, 4, 7, 8, 9]]
    latitudes, longitiudes = cities['lat'], cities['lng']
    name = cities['city_ascii']
    country = cities['country']
    admin_name = cities['admin_name']
    population = cities['population']

    fg_05to1m_cities = FeatureGroup(name='500k-1m', show=False)
    fg_1to2m_cities = FeatureGroup(name='1m-2m', show=False)
    fg_2to5m_cities = FeatureGroup(name='2m-5m', show=False)
    fg_5to10m_cities = FeatureGroup(name='5m-10m', show=False)
    fg_more_than_10m_cities = FeatureGroup(name='>10m', show=False)

    for i in range(len(cities)):
        if nan_to_num(population[i]) < 500000:
            continue
        html = f'City: <a href="https://www.google.com/search?q={name[i]} city" target="_blank">{name[i]}</a><br> \
                        Admin: {admin_name[i]}<br> \
                        Country: {country[i]}<br>\
                        Population: {population[i]}'

        iframe = IFrame(html=html, width=200, height=200)
        coords = (latitudes[i], longitiudes[i])

        if population[i] < 1000000:
            fg_05to1m_cities.add_child(
                Marker(location=coords, popup=Popup(iframe)))
        elif population[i] < 2000000:
            fg_1to2m_cities.add_child(
                Marker(location=coords, popup=Popup(iframe)))
        elif population[i] < 5000000:
            fg_2to5m_cities.add_child(
                Marker(location=coords, popup=Popup(iframe)))
        elif population[i] < 10000000:
            fg_5to10m_cities.add_child(
                Marker(location=coords, popup=Popup(iframe)))
        elif population[i] >= 1000000:
            fg_more_than_10m_cities.add_child(
                Marker(location=coords, popup=Popup(iframe)))

    map.add_child(fg_05to1m_cities)
    map.add_child(fg_1to2m_cities)
    map.add_child(fg_2to5m_cities)
    map.add_child(fg_5to10m_cities)
    map.add_child(fg_more_than_10m_cities)
Exemplo n.º 9
0
def compute_map(df):
    lat = list(df['lat'])
    lng = list(df['lng'])
    company_name = list(df['company_name'])

    map = Map(location=[15.2993, 74.1240], zoom_start=10)
    fgv = FeatureGroup()
    for lt, ln, name in zip(lat, lng, company_name):
        if not math.isnan(lt):
            fgv.add_child(
                CircleMarker(location=[lt, ln],
                             radius=6,
                             popup=name,
                             fill_color="green",
                             fill=True,
                             color='grey',
                             fill_opacity=0.7))
    pass

    map.add_child(fgv)
    map.save(map_name)
Exemplo n.º 10
0
def create_map(user_coords: list, closest_points: list) -> None:
    """
    creates map and saves it
    """
    mp = Map(location=[user_coords[0], user_coords[1]], zoom_start=15)
    markers = FeatureGroup()
    closest_dict = create_dictionary(closest_points)
    for key in closest_dict:
        markers.add_child(
            Marker(location=[key[0], key[1]],
                   popup=closest_dict[key],
                   icon=Icon()))
    your_location = FeatureGroup()
    your_location.add_child(
        Marker(location=[user_coords[0], user_coords[1]],
               popup='You are here',
               icon=Icon()))
    mp.add_child(markers)
    mp.add_child(your_location)
    mp.add_child(LayerControl())

    mp.save('map1.html')
Exemplo n.º 11
0
def init_map(path, data):
    """
    str, list -> folium map
    Creates a folium map .html file in the direction path.
    """
    map = Map()
    data_group = FeatureGroup(name='Data Layer')
    geolocator = Nominatim(user_agent='shumakov')
    geocode = RateLimiter(geolocator.geocode, min_delay_seconds=0.01)
    for row in data:
        if not row[0] or not row[1]:
            continue
        pos = geolocator.geocode(row[1])
        data_group.add_child(
            CircleMarker(location=[pos.latitude, pos.longitude],
                         radius=7,
                         popup=row[0],
                         fill_color='red',
                         color='white',
                         fill_opacity=0.5))
    map.add_child(data_group)
    map.save(path)
    return map
Exemplo n.º 12
0
from datawrangling.geomunging import depthm3half
from pprint import pprint
from folium import LayerControl, Map, FeatureGroup
from folium.plugins import HeatMap

# create map object
m = Map(tiles='openstreetmap',min_zoom=7, max_zoom=14, zoom_start=7,\
         min_lat=40, max_lat=48,min_lon=-114, max_lon=-128, \
         max_bounds=True)
# create heat map object
fg = FeatureGroup('Heat Map')
# add list of coordinates to map object
fg.add_child(HeatMap(list(zip(depthm3half.lat.values,
                              depthm3half.lon.values))))
m.add_child(fg)
LayerControl().add_to(m)
m.save(r'templates\depthm3halfeventheat.html')
Exemplo n.º 13
0
from datawrangling.geomunging import oqh
from pprint import pprint
from folium import LayerControl, Map, FeatureGroup
from folium.plugins import HeatMap

# create map object
m = Map(tiles='openstreetmap',min_zoom=7, max_zoom=14, zoom_start=7,\
         min_lat=40, max_lat=48,min_lon=-114, max_lon=-128, \
         max_bounds=True)
fg = FeatureGroup('Heat Map')
# add a list of coordinates to the map object
fg.add_child(HeatMap(list(zip(oqh.lat.values, oqh.lon.values))))
m.add_child(fg)
LayerControl().add_to(m)
m.save(r'templates\alleventheat.html')
Exemplo n.º 14
0
    """.format
    iframe = IFrame(html_popup(row['Articulo'], row['Autor'], row['Fecha'],
                               row['Secuenciación'], row['Trypanosoma']),
                    width=500,
                    height=300,
                    ratio='1%')
    popup = Popup(iframe, max_width=2650)

    html_tooltip = """
    <h4><i>{}</i></h4>
    <p>Click para más información</p>
    """.format

    feature_articulos.add_child(
        Marker([row['Latitud'], row['Longitud ']],
               popup=popup,
               tooltip=html_tooltip(row['Cita']),
               icon=Icon(color='red', icon='info-sign')))

feature_articulos.add_to(hospedero_map)

for especie in df_resumen.Especie.unique():
    temp_df = df_resumen[df_resumen['Especie'] == especie]
    #     show_especie = True if especie == 'Carollia perspicillata' else False
    feature_group = FeatureGroup(especie, show=False)

    html_tooltip = """
    <h4><i>{}</i></h4>
    <h5><b>Cantidad:</b> {}</h5>
    """.format
Exemplo n.º 15
0
from datawrangling.geomunging import g3half
from pprint import pprint
from folium import LayerControl, Map, FeatureGroup
from folium.plugins import HeatMap


# create map object
m = Map(tiles='openstreetmap',min_zoom=7, max_zoom=14, zoom_start=7,\
         min_lat=40, max_lat=48,min_lon=-114, max_lon=-128, \
         max_bounds=True)
fg = FeatureGroup('Heat Map')
# add list of coordinates to map object
fg.add_child(HeatMap(list(zip(g3half.lat.values, g3half.lon.values))))
m.add_child(fg)
LayerControl().add_to(m)
m.save(r'templates\g3halfeventheat.html')
Exemplo n.º 16
0
def create_map(data, file_name="index.html"):
    map = Map(
        location=[data[col].mean() for col in ["latitude", "longitude"]],
        tiles="Stamen Toner",
        zoom_start=2,
    )

    fg_nodes_locations = FeatureGroup(name="Locations")
    fg_nodes_counts = FeatureGroup(name="Counts")

    circles = [
        {
            "radius": 5,
            "stroke": False,
            "fill": True,
            "fill_color": "crimson",
            "fill_opacity": opacity,
            "location": [latitude, longitude],
            "popup": Popup(
                html=f"""
                <style>
                    tbody {{
                        text-align: center;
                    }}
                    table,
                    tr,
                    td {{
                        border-collapse: collapse;
                        border: 1px solid black;
                    }}
                </style>
                <h3>{ip}</h3>
                <table>
                    <tbody>
                        <tr>
                        <td><strong>ISP</strong></td>
                        <td>{org}</td>
                        </tr>
                        <tr>
                        <td><strong>Completed requests</strong></td>
                        <td>{completed_requests}</td>
                        </tr>
                    </tbody>
                </table>
            """,
                max_width=300,
            ),
        }
        for ip, latitude, longitude, org, completed_requests, opacity in [
            named_tuple[2:] for named_tuple in data.itertuples(index=False)
        ]
    ]

    q1, q2, q3, q4 = nodes_counts_quantiles()

    def opacity(scaled_nodes_count):
        # print(scaled_nodes_count)
        if scaled_nodes_count < q1:
            return 0
        elif q1 <= scaled_nodes_count < q2:
            return 0.1
        elif q2 <= scaled_nodes_count < q3:
            return 0.25
        elif q3 <= scaled_nodes_count < q4:
            return 0.5
        else:
            return 0.75

    def style_function(feature):
        fillOpacity = opacity(feature["properties"]["scaled_nodes_count"])
        return {"fillColor": "blue", "weight": 0, "fillOpacity": fillOpacity}

    fg_nodes_counts.add_child(
        GeoJson(
            data=open("data/enriched_world.json", encoding="utf-8-sig").read(),
            style_function=style_function,
        )
    )

    for circle in circles:
        fg_nodes_locations.add_child(CircleMarker(**circle))

    map.add_child(fg_nodes_counts)
    map.add_child(fg_nodes_locations)
    map.add_child(LayerControl())
    map.save(file_name)
Exemplo n.º 17
0
    def mapper(self):
        m = folium.Map(location=[39.5, -98.4],
                       zoom_start=5,
                       tiles='stamentoner',
                       prefer_canvas=True,
                       world_copy_jump=True,
                       no_wrap=True)
        folium.TileLayer('openstreetmap').add_to(m)

        med_cities_fg = FeatureGroup(name='Cities Between 175,000 and 500,000',
                                     show=False)
        large_cities_fg = FeatureGroup(name='Cities Larger than 500,000',
                                       show=True)
        res_ind_fg = FeatureGroup(name='Resilience Indicator', show=True)
        lmi_burd_fg = FeatureGroup(name='LMI Energy Buden', show=False)
        rev_fg = FeatureGroup(name='County Revenue', show=False)
        FEMA_spend_fg = FeatureGroup(name='Total FEMA Spending', show=False)
        ports_fg = FeatureGroup(name='Air/Sea Ports', show=False)
        xw_fg = FeatureGroup(name='Extreme Weather Susceptibility', show=False)
        urban_fg = FeatureGroup(name='Urban Areas', show=False)
        NLC_fg = FeatureGroup(name='NLC Participants', show=False)

        airporticon = folium.features.CustomIcon(
            'https://image.flaticon.com/icons/svg/579/579268.svg',
            icon_size=(20, 20))
        seaporticon = folium.features.CustomIcon(
            'https://image.flaticon.com/icons/svg/1198/1198475.svg',
            icon_size=(20, 20))
        staricon = folium.features.CustomIcon(
            'https://image.flaticon.com/icons/svg/148/148839.svg',
            icon_size=(15, 15))

        for index, row in self.airports.iterrows():
            ports_fg.add_child(
                folium.map.Marker(
                    location=row['lat_long'],
                    icon=airporticon,
                    popup=(f"<b>Airport Code:</b> {row['iata_code']}<br>"
                           f"<b>Type:</b> {row['type']}")))
        for index, row in self.seaports.iterrows():
            ports_fg.add_child(
                folium.map.Marker(location=row['lat_long'],
                                  icon=seaporticon,
                                  popup=(f"<b>Port</b><br>"
                                         f"<b>Name:</b> {row['name']}")))

        for index, row in self.NLC.iterrows():
            NLC_fg.add_child(
                folium.map.Marker(location=row['lat_long'],
                                  icon=staricon,
                                  popup=(f"<b>NLC Participant</b><br>"
                                         f"<b>Name:</b> {row['City']}<br>"
                                         f"<b>Type:</b> {row['Type']}")))

        folium.GeoJson(self.urbanshp,
                       style_function=lambda feature: {
                           'fillColor': '#F37748',
                           'fillOpacity': 0.5,
                           'color': '#F37748',
                           'opacity': 0.5,
                           'weight': 0.1
                       }).add_to(urban_fg)

        for index, row in self.md_Citiesshp.iterrows():
            med_cities_fg.add_child(
                folium.Circle(
                    location=row['lat_long'],
                    radius=(row['size'] + row['pop'] / 200),
                    color=row['color'],
                    fill_color=row['color'],
                    fill=True,
                    fill_opacity=0.7,
                    popup=
                    (f"<b><i>{row['name']}, {row['state_abbr']}</b></i><br>"
                     f"<b>Population:</b> {row['pop_class_desc']}<br>"
                     f"<b>Climate Zone:</b> {row['ashrae_climate_zone_desc']}<br>"
                     f"<b>Residential Consumption:</b> {row['res_elec_mwh']} MWh<br>"
                     f"<b>Commercial Consumption:</b> {row['comm_elec_mwh']} MWh<br>"
                     f"<b>Industrial Consumption:</b> {row['ind_elec_mwh']} MWh<br>"
                     )))

        for index, row in self.lg_Citiesshp.iterrows():
            large_cities_fg.add_child(
                folium.Circle(
                    location=row['lat_long'],
                    radius=(row['size'] + row['pop'] / 200),
                    color=row['color'],
                    fill_color=row['color'],
                    fill=True,
                    fill_opacity=0.7,
                    popup=
                    (f"<b><i>{row['name']}, {row['state_abbr']}</b></i><br>"
                     f"<b>Population:</b> {row['pop_class_desc']}<br>"
                     f"<b>Climate Zone:</b> {row['ashrae_climate_zone_desc']}<br>"
                     f"<b>Residential Consumption:</b> {row['res_elec_mwh']} MWh<br>"
                     f"<b>Commercial Consumption:</b> {row['comm_elec_mwh']} MWh<br>"
                     f"<b>Industrial Consumption:</b> {row['ind_elec_mwh']} MWh<br>"
                     )))

        for index, row in self.Cshp.loc[self.Cshp['resil_ind'] > 0].iterrows():
            geojson_ = folium.GeoJson(
                self.Cshp.loc[index:index + 1],
                style_function=lambda feature: {
                    'fillColor': feature['properties']['resil_ind_color'],
                    'fillOpacity': 0.5,
                    'color': feature['properties']['resil_ind_color'],
                    'opacity': 0.6,
                    'weight': 0.5
                })

            popup_ = folium.Popup(
                f"<b>County FIP:</b> {row['GEOID']}<br>"
                f"<b>Resilience Indicator:</b> {row['resil_ind']}<br>"
                f"<b>LMI Burden:</b> {row['lmi_burd']*100}%<br>"
                f"<b>County Revenue:</b> ${format(row['rev'], ',d')}<br>"
                f"<b>FEMA Spending:</b> ${format(row['total_FEMA_spend'], ',d')}<br>"
            )
            popup_.add_to(geojson_)
            geojson_.add_to(res_ind_fg)

        for index, row in self.Cshp.loc[self.Cshp['lmi_burd'] > 0].iterrows():
            geojson_ = folium.GeoJson(
                self.Cshp.loc[index:index + 1],
                style_function=lambda feature: {
                    'fillColor': feature['properties']['lmi_burd_color'],
                    'fillOpacity': 0.5,
                    'color': feature['properties']['lmi_burd_color'],
                    'opacity': 0.6,
                    'weight': 0.5
                })

            popup_ = folium.Popup(
                f"<b>County FIP:</b> {row['GEOID']}<br>"
                f"<b>Resilience Indicator:</b> {row['resil_ind']}<br>"
                f"<b>LMI Burden:</b> {row['lmi_burd']*100}%<br>"
                f"<b>County Revenue:</b> ${format(row['rev'], ',d')}<br>"
                f"<b>FEMA Spending:</b> ${format(row['total_FEMA_spend'], ',d')}<br>"
            )
            popup_.add_to(geojson_)
            geojson_.add_to(lmi_burd_fg)

        for index, row in self.Cshp.loc[self.Cshp['rev'] > 0].iterrows():
            geojson_ = folium.GeoJson(
                self.Cshp.loc[index:index + 1],
                style_function=lambda feature: {
                    'fillColor': feature['properties']['rev_color'],
                    'fillOpacity': 0.5,
                    'color': feature['properties']['rev_color'],
                    'opacity': 0.6,
                    'weight': 0.5
                })

            popup_ = folium.Popup(
                f"<b>County FIP:</b> {row['GEOID']}<br>"
                f"<b>Resilience Indicator:</b> {row['resil_ind']}<br>"
                f"<b>LMI Burden:</b> {row['lmi_burd']*100}%<br>"
                f"<b>County Revenue:</b> ${format(row['rev'], ',d')}<br>"
                f"<b>FEMA Spending:</b> ${format(row['total_FEMA_spend'], ',d')}<br>"
            )
            popup_.add_to(geojson_)
            geojson_.add_to(rev_fg)

        for index, row in self.Cshp.loc[
                self.Cshp['total_FEMA_spend'] > 0].iterrows():
            geojson_ = folium.GeoJson(
                self.Cshp.loc[index:index + 1],
                style_function=lambda feature: {
                    'fillColor': feature['properties']['total_FEMA_spend_color'
                                                       ],
                    'fillOpacity': 0.5,
                    'color': feature['properties']['total_FEMA_spend_color'],
                    'opacity': 0.6,
                    'weight': 0.5
                })

            popup_ = folium.Popup(
                f"<b>County FIP:</b> {row['GEOID']}<br>"
                f"<b>Resilience Indicator:</b> {row['resil_ind']}<br>"
                f"<b>LMI Burden:</b> {row['lmi_burd']*100}%<br>"
                f"<b>County Revenue:</b> ${format(row['rev'], ',d')}<br>"
                f"<b>FEMA Spending:</b> ${format(row['total_FEMA_spend'], ',d')}<br>"
            )
            popup_.add_to(geojson_)
            geojson_.add_to(FEMA_spend_fg)

        for index, row in self.Cshp.loc[self.Cshp['risk'] > 0].iterrows():
            geojson_ = folium.GeoJson(
                self.Cshp.loc[index:index + 1],
                style_function=lambda feature: {
                    'fillColor': feature['properties']['risk_color'],
                    'fillOpacity': 0.5,
                    'color': feature['properties']['risk_color'],
                    'opacity': 0.6,
                    'weight': 0.5
                })

            popup_ = folium.Popup(
                f"<b>County FIP:</b> {row['GEOID']}<br>"
                f"<b>Resilience Indicator:</b> {row['resil_ind']}<br>"
                f"<b>LMI Burden:</b> {row['lmi_burd']*100}%<br>"
                f"<b>County Revenue:</b> ${format(row['rev'], ',d')}<br>"
                f"<b>FEMA Spending:</b> ${format(row['total_FEMA_spend'], ',d')}<br>"
            )
            popup_.add_to(geojson_)
            geojson_.add_to(xw_fg)

        m.add_child(res_ind_fg)
        m.add_child(lmi_burd_fg)
        m.add_child(rev_fg)
        m.add_child(FEMA_spend_fg)
        m.add_child(xw_fg)
        m.add_child(ports_fg)
        m.add_child(urban_fg)
        m.add_child(med_cities_fg)
        m.add_child(large_cities_fg)
        m.add_child(NLC_fg)

        m.keep_in_front(large_cities_fg)
        m.add_child(folium.map.LayerControl(collapsed=False, autoZIndex=True))

        self.html = m
        return self
Exemplo n.º 18
0
    def mapper(self):
        m = folium.Map(
            location=[39.068305, -105.612593],
            zoom_start=7,
            tiles='stamentoner',
            attr=
            'Map created by NREL using 2017 Polk Vehicle Registration Data.')
        folium.TileLayer('openstreetmap').add_to(m)

        level1_fg = FeatureGroup(name='Level 1 Chargers', show=False)
        level2_fg = FeatureGroup(name='Level 2 Chargers', show=False)
        dcfc_fg = FeatureGroup(name='DC Fast Chargers', show=True)
        hev_fg = FeatureGroup(name='Registered Hybrids', show=False)
        phev_fg = FeatureGroup(name='Registered PHEVs', show=False)
        ev_fg = FeatureGroup(name='Registered EVs', show=False)
        hevnorm_fg = FeatureGroup(name='Percent LDVs Hybrids', show=False)
        phevnorm_fg = FeatureGroup(name='Percent LDVs PHEVs', show=False)
        evnorm_fg = FeatureGroup(name='Percent LDVs EVs', show=True)
        transmission_fg = FeatureGroup(name='Transmission Lines', show=False)
        PSCo_fg = FeatureGroup(name='PSCo Territory', show=False)

        folium.GeoJson(self.xcelterritorygpd,
                       style_function=lambda feature: {
                           'fillColor': '#B6174B',
                           'fillOpacity': 0.3,
                           'color': '#B6174B',
                           'weight': 0.5
                       }).add_to(PSCo_fg)

        for index, row in self.transmissiongpd.iterrows():
            geojson_ = folium.GeoJson(self.transmissiongpd.loc[index:index +
                                                               1],
                                      style_function=lambda feature: {
                                          'fillColor': '#4863CE',
                                          'fillOpacity': 0.3,
                                          'color': '#4863CE',
                                          'weight': 2
                                      })
            popup_ = folium.Popup(
                f"<b>Owner:</b> {row['OWNER']}<br>"
                f"<b>Volt Class:</b> {row['VOLT_CLASS']}<br>"
                f"<b>Substations:</b> {row['SUB_1']} to {row['SUB_2']}<br>")
            popup_.add_to(geojson_)
            geojson_.add_to(transmission_fg)

        for index, row in self.zips.loc[self.zips['HEV'] > 0].iterrows():
            geojson_ = folium.GeoJson(
                self.zips.loc[index:index + 1],
                style_function=lambda feature: {
                    'fillColor': feature['properties']['HEV_color'],
                    'fillOpacity': 0.5,
                    'color': feature['properties']['HEV_color'],
                    'opacity': 0.7,
                    'weight': 0.5
                })

            popup_ = folium.Popup(f"<b>ZIP Code:</b> {int(row['ZIP'])}<br>"
                                  f"<b>Num Hybrids:</b> {int(row['HEV'])}<br>"
                                  f"<b>Num PHEVs:</b> {int(row['PHEV'])}<br>"
                                  f"<b>Num EVs:</b> {int(row['EV'])}<br>")
            popup_.add_to(geojson_)
            geojson_.add_to(hev_fg)

        for index, row in self.zips.loc[self.zips['PHEV'] > 0].iterrows():
            geojson_ = folium.GeoJson(
                self.zips.loc[index:index + 1],
                style_function=lambda feature: {
                    'fillColor': feature['properties']['PHEV_color'],
                    'fillOpacity': 0.3,
                    'color': feature['properties']['PHEV_color'],
                    'opacity': 0.5,
                    'weight': 0.5
                })

            popup_ = folium.Popup(f"<b>ZIP Code:</b> {int(row['ZIP'])}<br>"
                                  f"<b>Num Hybrids:</b> {int(row['HEV'])}<br>"
                                  f"<b>Num PHEVs:</b> {int(row['PHEV'])}<br>"
                                  f"<b>Num EVs:</b> {int(row['EV'])}<br>")
            popup_.add_to(geojson_)
            geojson_.add_to(phev_fg)

        for index, row in self.zips.loc[self.zips['EV'] > 0].iterrows():
            geojson_ = folium.GeoJson(
                self.zips.loc[index:index + 1],
                style_function=lambda feature: {
                    'fillColor': feature['properties']['EV_color'],
                    'fillOpacity': 0.5,
                    'color': feature['properties']['EV_color'],
                    'opacity': 0.7,
                    'weight': 0.5
                })

            popup_ = folium.Popup(f"<b>ZIP Code:</b> {int(row['ZIP'])}<br>"
                                  f"<b>Num Hybrids:</b> {int(row['HEV'])}<br>"
                                  f"<b>Num PHEVs:</b> {int(row['PHEV'])}<br>"
                                  f"<b>Num EVs:</b> {int(row['EV'])}<br>")
            popup_.add_to(geojson_)
            geojson_.add_to(ev_fg)

        for index, row in self.zips.loc[self.zips['HEVnorm'] > 0].iterrows():
            geojson_ = folium.GeoJson(
                self.zips.loc[index:index + 1],
                style_function=lambda feature: {
                    'fillColor': feature['properties']['HEVnorm_color'],
                    'fillOpacity': 0.5,
                    'color': feature['properties']['HEVnorm_color'],
                    'opacity': 0.7,
                    'weight': 0.5
                })

            popup_ = folium.Popup(
                f"<b>ZIP Code:</b> {int(row['ZIP'])}<br>"
                f"<b>Pct of LDVs Hybrids:</b> {row['HEVnorm']}%<br>"
                f"<b>Pct of LDVs PHEVs:</b> {row['PHEVnorm']}%<br>"
                f"<b>Pct of LDVs EVs:</b> {row['EVnorm']}%<br>")
            popup_.add_to(geojson_)
            geojson_.add_to(hevnorm_fg)

        for index, row in self.zips.loc[self.zips['PHEVnorm'] > 0].iterrows():
            geojson_ = folium.GeoJson(
                self.zips.loc[index:index + 1],
                style_function=lambda feature: {
                    'fillColor': feature['properties']['PHEVnorm_color'],
                    'fillOpacity': 0.3,
                    'color': feature['properties']['PHEVnorm_color'],
                    'opacity': 0.5,
                    'weight': 0.5
                })

            popup_ = folium.Popup(
                f"<b>ZIP Code:</b> {int(row['ZIP'])}<br>"
                f"<b>Pct of LDVs Hybrids:</b> {row['HEVnorm']}%<br>"
                f"<b>Pct of LDVs PHEVs:</b> {row['PHEVnorm']}%<br>"
                f"<b>Pct of LDVs EVs:</b> {row['EVnorm']}%<br>")
            popup_.add_to(geojson_)
            geojson_.add_to(phevnorm_fg)

        for index, row in self.zips.loc[self.zips['EVnorm'] > 0].iterrows():
            geojson_ = folium.GeoJson(
                self.zips.loc[index:index + 1],
                style_function=lambda feature: {
                    'fillColor': feature['properties']['EVnorm_color'],
                    'fillOpacity': 0.5,
                    'color': feature['properties']['EVnorm_color'],
                    'opacity': 0.7,
                    'weight': 0.5
                })

            popup_ = folium.Popup(
                f"<b>ZIP Code:</b> {int(row['ZIP'])}<br>"
                f"<b>Pct of LDVs Hybrids:</b> {row['HEVnorm']}%<br>"
                f"<b>Pct of LDVs PHEVs:</b> {row['PHEVnorm']}%<br>"
                f"<b>Pct of LDVs EVs:</b> {row['EVnorm']}%<br>")
            popup_.add_to(geojson_)
            geojson_.add_to(evnorm_fg)

        for index, row in self.level1chrg.iterrows():
            level1_fg.add_child(
                folium.CircleMarker(
                    location=row['lat_long'],
                    radius=4,
                    color='#76B041',
                    fill=True,
                    fill_opacity=0.8,
                    popup=
                    (f"<b>Num Level 1 Chargers:</b> {int(row['EV Level1 EVSE Num'])}<br>"
                     )))

        for index, row in self.level2chrg.iterrows():
            level2_fg.add_child(
                folium.CircleMarker(
                    location=row['lat_long'],
                    radius=4,
                    color='#17BEBB',
                    fill=True,
                    fill_opacity=0.8,
                    popup=
                    (f"<b>Num Level 2 Chargers:</b> {int(row['EV Level2 EVSE Num'])}<br>"
                     )))

        for index, row in self.dcfchrg.iterrows():
            dcfc_fg.add_child(
                folium.CircleMarker(
                    location=row['lat_long'],
                    radius=4,
                    color='#F9A03F',
                    fill=True,
                    fill_opacity=0.8,
                    popup=
                    (f"<b>Num DC Fast Chargers:</b> {int(row['EV DC Fast Count'])}<br>"
                     )))
        m.add_child(hev_fg)
        m.add_child(phev_fg)
        m.add_child(ev_fg)

        m.add_child(hevnorm_fg)
        m.add_child(phevnorm_fg)
        m.add_child(evnorm_fg)

        m.add_child(dcfc_fg)
        m.add_child(level1_fg)
        m.add_child(level2_fg)

        m.add_child(PSCo_fg)
        m.add_child(transmission_fg)

        m.add_child(folium.map.LayerControl(collapsed=False, autoZIndex=True))
        self.html = m
        return m
Exemplo n.º 19
0
    icon_HL = folium.features.CustomIcon(logo_HL, icon_size=(25, 25))
    if place.entry_type == data.TYPES['HiLife']:
        folium.Marker(location=[place.lat, place.lon],
                      icon=icon_HL).add_to(group_HL)
    xinyi_map.add_child(group_HL)

    icon_OK = folium.features.CustomIcon(logo_OK, icon_size=(25, 25))
    if place.entry_type == data.TYPES['OKmart']:
        folium.Marker(location=[place.lat, place.lon],
                      icon=icon_OK).add_to(group_OK)
    xinyi_map.add_child(group_OK)

for lat, lon in xinyi_exits.itervalues():
    icon_mrt = folium.features.CustomIcon(logo_mrt, icon_size=(25, 25))
    folium.Marker(location=[lat, lon], icon=icon_mrt).add_to(group_mrt)
    xinyi_map.add_child(group_mrt)

# heatmap
for place in data.all:
    folium.CircleMarker(location=[place.lat, place.lon], radius=1,
                        opacity=0).add_to(group_heat)
    xinyi_map.add_child(group_heat)
geocode = pd.DataFrame([(place.lat, place.lon)
                        for place in data.all]).values.tolist()
group_heat.add_child(plugins.HeatMap(geocode, radius=40))

# add layer control
folium.LayerControl().add_to(xinyi_map)

xinyi_map.save("xinyi_map.html")