def value_map(pollutant):
    """
    Returns a map with mesures values and their location for each instant

    Args:
        pollutant (string): name of the pollutant to display

    Returns:
        Map: folium map with time mesures
    """
    folium_map = folium.Map(location=[46, 2.291705], zoom_start=7)
    client = DBClient("database")
    ordered_mesures = client.get_mesures_by_time(pollutant)
    global_max = get_global_max(ordered_mesures)

    encoder = JSONEncoder(global_max)
    features = []
    for time in ordered_mesures:
        features += [
            encoder.encode_as_geoJSON(mesure)
            for mesure in ordered_mesures[time]
        ]

    tsjson = TimestampedGeoJson(
        {
            'type': 'FeatureCollection',
            'features': features
        },
        period='PT1H',
        add_last_point=True,
        auto_play=False,
        loop=False,
        max_speed=1,
        loop_button=True,
        time_slider_drag_update=True)
    tsjson.options["position"] = "topright"
    tsjson.add_to(folium_map)
    encoder.cm.caption = f"{pollutant} concentration in ug.m-3"
    folium_map.add_children(encoder.cm)
    return folium_map
示例#2
0
def make_map(features):
    coords = [44.981041, -93.232149]
    this_map = folium.Map(location=coords, control_scale=True, zoom_start=10)
    folium.TileLayer('cartodbpositron').add_to(this_map)

    temp = TimestampedGeoJson(
        {
            'type': 'FeatureCollection',
            'features': features
        },
        period='P1D',
        add_last_point=True,
        auto_play=True,
        loop=True,
        max_speed=.7,
        loop_button=True,
        date_options='YYYY/MM',
        time_slider_drag_update=True)

    temp.add_to(this_map)

    return this_map
poly_line = TimestampedGeoJson(data={
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "geometry": {
                "type": "LineString",
                "coordinates": coordinates,
            },
            "properties": {
                "times": time,
                "style": {
                    "color": "red",
                    "weight": 2
                }
            }
        }
    ]
}, period="PT1M")

poly_line.add_to(map)

# Create a tool to measure distance and area
tool_measure = MeasureControl()
tool_measure.add_to(map)

# Create tool to draw something
tool_draw = Draw()
tool_draw.add_to(map)
map.save("Munich_with_points_and_lines_.html")
示例#4
0
        51, 50, 31, 32, 4, 38, 30, 26, 13, 49, 40, 6, 29, 20, 10, 41, 3, 58, 7
    ]
    routes_gj = get_routes_geojson(bus_ids)
    grid_gj = get_grid_geojson(bus_ids, ('weekday', '00:00', '23:59'),
                               stations_source='here')
    m = folium.Map(location=[55.6795535, 12.542231],
                   zoom_start=13,
                   tiles='OpenStreetMap')
    routes = folium.GeoJson(routes_gj,
                            name='routes',
                            style_function=lambda feature: {'color': 'blue'})

    grid = TimestampedGeoJson(grid_gj,
                              period='PT1H',
                              duration='PT1M',
                              date_options='HH:mm',
                              auto_play=False,
                              max_speed=1,
                              loop=False,
                              time_slider_drag_update=True,
                              loop_button=True)

    routes.add_to(m)
    grid.add_to(m)

    folium.features.GeoJsonTooltip(fields=['bus_id', 'name'],
                                   aliases=['id', 'bus']).add_to(routes)
    folium.LayerControl().add_to(m)

    print(m)