How to use the folium.GeoJson function in folium

To help you get started, we’ve selected a few folium examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bukun / book_python_gis / part010 / ch09_others / sec5_folium / test_2_data_x_x.py View on Github external
popup3 = folium.Popup(max_width=800,).add_child(
    folium.Vega(
        json.load(open('/gdata/folium/data/vis3.json')),
        width=500, height=250))
folium.RegularPolygonMarker([46.216, -124.1280],
    fill_color='#0000ff', radius=12, popup=popup3
    ).add_to(map_a)
map_a.save('folium_a.html')
###############################################################################
ice_edge = '/gdata/folium/data/antarctic_ice_edge.json'
map_b = folium.Map(
    location=[-59.1759, -11.6016],
    tiles='Mapbox Bright',
    zoom_start=2
)
folium.GeoJson(ice_edge, name='geojson').add_to(map_b)
###############################################################################
icej='/gdata/folium/data/antarctic_ice_shelf_topo.json'
folium.TopoJson(open(icej),
    'objects.antarctic_ice_shelf',
    name='topojson'
).add_to(map_b)
###############################################################################
folium.LayerControl().add_to(map_b)
map_b.save('folium_b.html')
###############################################################################
import pandas as pd
state_geo = '/gdata/folium/data/us-states.json'
csvf = '/gdata/folium/data/US_Unemployment_Oct2012.csv'
state_data = pd.read_csv(csvf)
map_c = folium.Map(location=[48, -102], zoom_start=3)
folium.Choropleth(geo_data=state_geo,
github python-visualization / folium / tests / test_features.py View on Github external
def test_geojson_tooltip():
    m = folium.Map([30.5, -97.5], zoom_start=10)
    folium.GeoJson(os.path.join(rootpath, 'kuntarajat.geojson'),
                   tooltip=folium.GeoJsonTooltip(fields=['code', 'name'])
                   ).add_to(m)
    with warnings.catch_warnings(record=True) as w:
        warnings.simplefilter('always')
        m._repr_html_()
        assert issubclass(w[-1].category, UserWarning), 'GeoJsonTooltip GeometryCollection test failed.'
github python-visualization / folium / tests / plugins / test_pattern.py View on Github external
'color': 'black',
            'weight': 2
        }

        if feature['properties']['name'] == 'Colorado':
            default_style['fillPattern'] = stripes
            default_style['fillOpacity'] = 1.0

        if feature['properties']['name'] == 'Utah':
            default_style['fillPattern'] = circles
            default_style['fillOpacity'] = 1.0

        return default_style

    data = os.path.join(os.path.dirname(__file__), os.pardir, 'us-states.json')
    folium.GeoJson(data, style_function=style_function).add_to(m)

    out = normalize(m._parent.render())

    # We verify that the script import is present.
    script = ''  # noqa
    assert script in out
github scikit-mobility / scikit-mobility / skmob / utils / plot.py View on Github external
vertices = list(zip(*gway.exterior.xy))
        gj = folium.GeoJson({"type": "Polygon", "coordinates": [vertices]},
                            style_function=geojson_style_function(weight=weight, color=color, opacity=opacity,
                                                                  fillColor=fillColor, fillOpacity=fillOpacity))

    elif type(gway) == shapely.geometry.multilinestring.MultiLineString:

        # MultiLine
        for gg in gway:
            if color == 'random':
                color = random_hex()
                fillColor = color

            vertices = list(zip(*gg.xy))
            gj = folium.GeoJson({"type": "LineString", "coordinates": vertices},
                                style_function=geojson_style_function(weight=weight, color=color, opacity=opacity,
                                                                      fillColor=fillColor, fillOpacity=fillOpacity))

    elif type(gway) == shapely.geometry.linestring.LineString:

        # LineString
        if color == 'random':
            color = random_hex()
            fillColor = color
        vertices = list(zip(*gway.xy))
        gj = folium.GeoJson({"type": "LineString", "coordinates": vertices},
                            style_function=geojson_style_function(weight=weight, color=color, opacity=opacity,
                                                                  fillColor=fillColor, fillOpacity=fillOpacity))

    else:
github scikit-mobility / scikit-mobility / skmob / utils / plot.py View on Github external
geom = fdf.get_geometry(O)
        lonO, latO = utils.get_geom_centroid(geom)

        for D, T in OD[[constants.DESTINATION, constants.FLOW]].values:
            if O == D:
                continue
            if T < min_flow:
                continue

            geom = fdf.get_geometry(D)
            lonD, latD = utils.get_geom_centroid(geom)

            gjc = LineString([(lonO,latO), (lonD,latD)])

            fgeojson = folium.GeoJson(gjc,
                                      name='geojson',
                                      style_function = style_function(T / mean_flows, flow_color, opacity,
                                                                      flow_weight, flow_exp)
                                      )
            if flow_popup:
                popup = folium.Popup('flow from %s to %s: %s'%(O, D, int(T)), max_width=300)
                fgeojson = fgeojson.add_child(popup)

            fgeojson.add_to(map_f)

    if radius_origin_point > 0:
        for O, OD in O_groups:

            name = 'origin: %s' % O.replace('\'', '_')
            T_D = [[T, D] for D, T in OD[[constants.DESTINATION, constants.FLOW]].values]
            trips_info = '<br>'.join(["flow to %s: %s" %
github akkana / scripts / mapping / polidistmap.py View on Github external
# Add some alternate tile layers
    folium.TileLayer('Stamen Terrain').add_to(m)
    folium.TileLayer('Stamen Toner').add_to(m)

    def style_fcn(x):
        '''The style function can key off x['properties']['NAME10']
           which will be strings like 'Senate District 42'
           but for now, let's just return random colors.
        '''
        return { 'fillColor': random_html_color() }

    def highlight_fcn(x):
        return { 'fillColor': '#ff0000' }

    gj = folium.GeoJson(jsonfile,
                        name="State %s Boundaries" % label,
                        tooltip=folium.GeoJsonTooltip(
                            fields=[fieldname],

                            # Don't include the field name in the tooltip.
                            # There doesn't seem to be a way to map to
                            # to '10' rather than ' Senate District 10';
                            # all folium allows is aliasing the field name
                            # and it will add a space even if the alias
                            # is empty.
                            aliases=[''],

                            # Optionally can pass a style
                            # style="font-family: serif;",
                        ),
                        style_function=style_fcn,