示例#1
0
def get_map_panel_zip_layout():
    classes = [0, 100, 500, 1000, 2000, 5000, 10000, 20000]
    colorscale = [
        "#FFEDA0",
        "#FED976",
        "#FEB24C",
        "#FD8D3C",
        "#FC4E2A",
        "#E31A1C",
        "#BD0026",
        "#800026",
    ]
    style = {
        "weight": 2,
        "opacity": 1,
        "color": "white",
        "dashArray": 3,
        "fillOpacity": 0.7,
    }

    ctg = ["{}+".format(cls, classes[i + 1]) for i, cls in enumerate(classes[:-1])] + [
        "{}+".format(classes[-1])
    ]
    colorbar = dlx.categorical_colorbar(
        categories=ctg,
        colorscale=colorscale,
        width=400,
        height=30,
        position="bottomright",
    )

    ns = Namespace("dlx", "choropleth")
    zip_geojson = dl.GeoJSON(
        data=None,  # url to geojson file
        options=dict(style=ns("style")),  # how to style each polygon
        zoomToBounds=False,  # when true, zooms to bounds when data changes (e.g. on load)
        zoomToBoundsOnClick=True,  # when true, zooms to bounds of feature (e.g. polygon) on click
        hoverStyle=arrow_function(
            dict(weight=5, color="#666", dashArray="")
        ),  # style applied on hover
        hideout=dict(
            colorscale=colorscale, classes=classes, style=style, colorProp="Amount"
        ),
        id="zips-geojson",
    )

    stl_center = [38.648, -90.253]
    city_map_style = {"height": "100vh", "margin": "none", "display": "block"}
    city_map = html.Div(
        dl.Map(
            children=[get_base_toner_tile_layer(), zip_geojson, colorbar],
            zoom=12,
            center=stl_center,
        ),
        style=city_map_style,
        id="map",
    )
    map_panel_style = {"width": "100%", "height": "100vh", "display": "block"}
    map_panel = html.Div(id="map-panel", children=city_map, style=map_panel_style)
    return map_panel
示例#2
0
def get_precinct_geojson():
    ns = Namespace("dlx", "choropleth")
    precincts_geobuf_path = "dsadata/static/geobuf/stl-city-and-county-precincts.pbf"
    precincts_geojson = dl.GeoJSON(
        format="geobuf",
        options=dict(style=ns("style")),
        hoverStyle=arrow_function(dict(weight=5, color="#666", dashArray="")),
        hideout=bootstrap_stuff.build_choropleth_hideout(
            "total_monetary_donations"),
        id="precincts-geojson",
    )
    return precincts_geojson
示例#3
0
def get_neighborhood_geojson():
    ns = Namespace("dlx", "choropleth")
    neighborhoods_geobuf_path = "static/geobuf/neighborhoods-and-municipalities.pbf"
    neighborhoods_geojson = dl.GeoJSON(
        format="geobuf",
        options=dict(style=ns("style")),
        hoverStyle=arrow_function(dict(weight=5, color="#666", dashArray="")),
        hideout=bootstrap_stuff.build_choropleth_hideout(
            "total_monetary_donations"),
        id="neighborhood-geojson",
    )
    return neighborhoods_geojson
示例#4
0
def get_neighborhood_geojson():
    ns = Namespace("dlx", "choropleth")
    neighborhoods_geojson = dl.GeoJSON(
        format="geobuf",
        options=dict(style=ns("style")),
        hoverStyle=arrow_function(dict(weight=5, color="#666", dashArray="")),
        zoomToBoundsOnClick=
        False,  # when true, zooms to bounds of feature (e.g. polygon) on click
        hideout=bootstrap_stuff.build_choropleth_hideout(
            "total_monetary_donations"),
        id="neighborhood-geojson",
    )
    return neighborhoods_geojson
示例#5
0
def get_precinct_overlay():
    # original file was wrong hand rule, whis one was rewound with geojson-rewind:
    precinct_geojson_path = "data/geojson/stl-city/precincts_rw.geojson"
    with open(precinct_geojson_path) as read_file:
        precinct_geojson = json.load(read_file)
    precincts = dl.GeoJSON(
        data=precinct_geojson,
        options=dict(style=dict(color="blue", fillOpacity=0.5)),
        zoomToBoundsOnClick=True,
        hoverStyle=arrow_function(dict(weight=4, fillOpacity=0.2, dashArray="")),
        id="precincts-geojson",
    )
    precinct_overlay = dl.Overlay(precincts, name="precincts", checked=False)
    return precinct_overlay
示例#6
0
def get_precinct_overlay():
    # original file was wrong hand rule, whis one was rewound with geojson-rewind:
    precinct_pbf_url = "dsadata/static/geobuf/stl-city-precincts.pbf"
    ns = Namespace("dlx", "choropleth")
    precincts = dl.GeoJSON(
        url=precinct_pbf_url,
        format="geobuf",
        options=dict(style=ns("style")),
        zoomToBoundsOnClick=True,
        hoverStyle=arrow_function(dict(weight=4, fillOpacity=0.2,
                                       dashArray="")),
        hideout=bootstrap_stuff.build_choropleth_hideout("total_donations"),
        id="precincts-geojson",
    )
    precinct_overlay = dl.Overlay(precincts, name="precincts", checked=False)
    return precinct_overlay
示例#7
0
def get_zip_geojson():
    ns = Namespace("dlx", "choropleth")
    zip_geojson = dl.GeoJSON(
        format="geobuf",
        options=dict(style=ns("style")),  # how to style each polygon
        # options=dict(style=dict(color="blue")),
        zoomToBounds=
        False,  # when true, zooms to bounds when data changes (e.g. on load)
        zoomToBoundsOnClick=
        False,  # when true, zooms to bounds of feature (e.g. polygon) on click
        hoverStyle=arrow_function(dict(weight=5, color="#666", dashArray="")),
        hideout=bootstrap_stuff.build_choropleth_hideout(
            "total_monetary_donations"),
        id="zip-geojson",
    )
    return zip_geojson
示例#8
0
def get_zip_overlay(mec_df, candidate):
    if candidate is not None:
        cand_df = contrib.sum_funds_by_zip(cand_zip_df)
    else:
        df = cand_zip_df[cand_zip_df[" MECID"] == candidate]
    # original file was wrong hand rule, whis one was rewound with geojson-rewind:
    zip_geojson_path = "data/geojson/stl-region-zip_rw.geojson"
    gdf = gpd.read_file(zip_geojson_path)
    gdf = gdf.merge(cand_zip_df, left_on="ZCTA5CE10", right_on="ZIP5")
    if candidate is not None:
        df = contrib.sum_funds_by_zip(cand_zip_df)
    else:
        df = cand_zip_df[cand_zip_df[" MECID"] == candidate]
    with open(zip_geojson_path) as read_file:
        zip_geojson = json.load(read_file)
    zips = dl.GeoJSON(
        data=zip_geojson,
        options=dict(style=dict(color="purple", fillOpacity=0.5)),
        zoomToBoundsOnClick=True,
        hoverStyle=arrow_function(dict(weight=4, fillOpacity=0.2, dashArray="")),
        id="zips-geojson",
    )
    zip_overlay = dl.Overlay(zips, name="zips", checked=True)
    return zip_overlay
示例#9
0
classes = quantiles
colorscale = ['#FED976', '#FEB24C', '#FD8D3C', '#FC4E2A', '#800026']
style = dict(weight=2, opacity=1, color='white', dashArray='3', fillOpacity = 0.7)

# Create colorbar.
ctg = ["{}+".format(cls, classes[i + 1]) for i, cls in enumerate(classes[:-1])] + ["{}+".format(classes[-1])]
colorbar = dlx.categorical_colorbar(categories=ctg, colorscale=colorscale, width=300, height=30, position="bottomleft")

ns = Namespace("dlx", "choropleth")
### Define layouts
geojson = dl.GeoJSON(
    data = json_data,
    options=dict(style=ns("style")),
    zoomToBoundsOnClick = False,
    hoverStyle=arrow_function(dict(weight=2, color='#666', dashArray='', fillOpacity=0.2)),  # style applied on hover
    hideout=dict(colorscale=colorscale, classes=classes, style=style, colorProp = "cases"),
    id = "geojson")




cont = dbc.Card(
    [
        dbc.CardImg(src = "assets/form.svg", top = True, className = "card-img"),
        dbc.CardBody(
            [
                html.P(
                    "Casos: " + str(conf.return_data_size())
                )
            ],
示例#10
0
    id='geojson',
    format='geobuf',
    zoomToBounds=True,
    cluster=True,
    #  clusterToLayer=ns("clusterToLayer"),
    zoomToBoundsOnClick=True,
    #  options=dict(pointToLayer=ns('pointToLayer')),
    superClusterOptions=dict(radius=150))
#  hideout=dict(colorscale='Viridis', colorProp='cpa'))

# add cpa boundaries
cpa_boundaries = dl.GeoJSON(
    id='rfmp',
    url="/assets/rfmp4.json",
    zoomToBounds=True,
    hoverStyle=arrow_function(dict(weight=5, color='#666',
                                   dashArray='')))  # must be in assets folder

# create map
map = dl.Map([dl.TileLayer(), cpa_boundaries, geojson])

# create dropdown for CPA
dd = html.Div(
    [dd_cpa],
    style={
        "position": "relative",
        "bottom": "80px",
        "left": "10px",
        "z-index": "1000",
        "width": "200px"
    })
示例#11
0
        50: "50"
    },
    disabled=disable_odlines(default_zoomed),
    id="sl_line",
)

# Create geojson foreground.
style_hover = {"weight": 5, "color": "#666", "dashArray": ""}
ns = Namespace("dlx", "choropleth")
geojson_fg = dl.GeoJSON(
    url=get_url_fg(default_zoomed, default_region, default_name),
    format="geobuf",
    options=dict(style=ns("style")),  # how to style each polygon
    hideout=get_hideout(default_case),
    zoomToBoundsOnClick=True,  # when true, zooms to bounds of feature on click
    hoverStyle=arrow_function(style_hover),
    id="geojson_fg")

# Create geojson background.
style_bg = {
    "weight": 2,
    "opacity": 1,
    "color": "white",
    "dashArray": 3,
    "fillOpacity": 0.5
}
geojson_bg = dl.GeoJSON(
    url=get_url_bg(default_zoomed, default_region, default_name),
    format="geobuf",
    options=dict(style=style_bg),  # how to style each polygon
    zoomToBoundsOnClick=True,  # when true, zooms to bounds of feature on click
示例#12
0
文件: app.py 项目: renodubois/data
            adult_hispanic_2000=df_ward.values[0][19],
            total_housing_units_2000=df_ward.values[0][20],
            occupied_housing_units_2000=df_ward.values[0][21],
            vacant_housing_units_2000=df_ward.values[0][22],
        )
wards = dl.GeoJSON(
    data=ward_geojson,  # TODO: Faster is to get PBFs
    options={"style": {
        "color": "red",
        "fillOpacity": 0.5,
        "weight": 2
    }},
    zoomToBoundsOnClick=
    True,  # when true, zooms to bounds of feature (e.g. polygon) on click
    hoverStyle=arrow_function(
        dict(weight=4, fillOpacity=0.2,
             dashArray="")),  # special style applied on hover)
    id="wards-geojson",
)
ward_overlay = dl.Overlay(dl.LayerGroup(wards), name="wards", checked=True)


# 	Wards: Show election info on click
@app.callback(
    Output("ward-info-panel", "children"),
    [Input("wards-geojson", "click_feature")],
    State("election-dropdown", "value"),
)
def ward_click(feature, election_selected):
    div_children = []
    races_per_election = dict(
示例#13
0

    ]),


    html.Div([
        dbc.Row([
           dbc.Col(children = [
                html.Label('Data for the regional level in France'),
                dl.Map(center=[47, 2], zoom=4, children=[
                   dl.TileLayer(),
                   #dl.GeoJSON(url='https://raw.githubusercontent.com/isellsoap/deutschlandGeoJSON/master/2_bundeslaender/4_niedrig.geo.json', id="capitals",
                   dl.GeoJSON(data = mapfrance, id="region_FR",
                   #url='https://raw.githubusercontent.com/gregoiredavid/france-geojson/master/regions-version-simplifiee.geojson'
                   #url='https://raw.githubusercontent.com/gregoiredavid/france-geojson/master/regions-version-simplifiee.geojson'
                        hoverStyle=arrow_function(dict(weight=5, color='#666', dashArray=''))),  # geojson resource (faster than in-memory)
                        ], style={'width': '28vh', 'height': '35vh', 'margin': "auto", "display": "block"}, id="mapFR"
                )
           ], width=2),
           dbc.Col(children = [
               state_dropdown_Fr,
               dcc.Graph(id="coronaRegionFR",style={'width': '90%'})
           ], width=4, style={'display': 'inline-block'}),

           dbc.Col(children=[
                html.Label('Data for the regional level in Germany. '),
                dl.Map(center=[51, 10], zoom=5, children=[
                   dl.TileLayer(),
                   dl.GeoJSON(data = mapgermany, id="laender_DE",
                   #url='https://raw.githubusercontent.com/isellsoap/deutschlandGeoJSON/master/2_bundeslaender/4_niedrig.geo.json'
                   #dl.GeoJSON(url='https://raw.githubusercontent.com/gregoiredavid/france-geojson/master/regions-version-simplifiee.geojson', id="capitals",
示例#14
0
def generate_choropleth(metric, violation, subcategory, year):
    """Updates the choropleth map on tab 1 when triggered
    
    Parameters
    -------
    String
        The name of the metric selected from the dropdown
    String
        The violation selected from the dropdown
    String
        The subcategory selected from the dropdown
    Int
        The year selected from the slider
    
    Returns
    -------
    html
        A leaflet choropleth map
    """

    geojson = PROVINCES
    df = DATA[(DATA["Metric"] == metric)
              & (DATA["Level1 Violation Flag"] == violation) &
              (DATA["Violation Description"] == subcategory) &
              (DATA["Year"] == year) & (DATA['Geo_Level'] == "PROVINCE")]

    data_dict = dict(zip(df['Geography'], df['Value']))

    for location in geojson['features']:
        try:
            lookup_val = data_dict[location['properties']['PRENAME']]
        except:
            lookup_val = None
        location['properties']['Value'] = lookup_val

    num = 13  # number of provinces and territories in Canada
    vals = pd.Series(data_dict.values())
    classes = list(
        np.linspace(int(vals.min()) - 0.01, int(vals.max()) + 0.01, num=num))
    mm = dict(min=vals.min(), max=vals.max())

    viridis = cm.get_cmap('viridis', num)
    colorscale = []
    for i in range(viridis.N):
        rgba = viridis(i)
        colorscale.append(matplotlib.colors.rgb2hex(rgba))

    style = dict(weight=1, color='black', fillOpacity=0.7)
    hover_style = dict(weight=5, color='orange', dashArray='')
    ns = Namespace("dlx", "choropleth")

    return [
        dl.TileLayer(),
        dl.GeoJSON(data=geojson,
                   id="provinces",
                   options=dict(style=ns("style")),
                   hideout=dict(colorscale=colorscale[::-1],
                                classes=classes,
                                style=style,
                                colorProp="Value"),
                   hoverStyle=arrow_function(hover_style)),
        dl.Colorbar(colorscale=colorscale[::-1],
                    id="colorbar",
                    width=20,
                    height=150,
                    **mm,
                    position="bottomleft")
    ]
示例#15
0
 #          hoverStyle=arrow_function(dict(weight=5, color='#666', dashArray='')),  # style applied on hover
 #          hideout=dict(colorscale=colorscale, classes=classes, style=style, colorProp="density"),
 #          id="geojson_test"),
 dl.GeoJSON(
     # url=app.get_asset_url('KCNeighborhood.json'),
     data=outline_data,
     id="outlines",
     options=dict(style=ns(
         "style")),  # how to style each polygon
     # when true, zooms to bounds when data changes (e.g. on load)
     # zoomToBounds=True,
     # when true, zooms to bounds of feature (e.g. polygon) on click
     zoomToBoundsOnClick=False,
     # style applied on hover
     hoverStyle=arrow_function(
         dict(weight=5,
              color='#666',
              dashArray='')),
     hideout=dict(
         colorscale=colorscale,
         classes=list(
             range(
                 outline_min, outline_max,
                 (outline_max - outline_min) //
                 5)),
         style=style,
         colorProp="volume"),
 ),
 locate_control,
 dl.LayersControl([
     dl.BaseLayer(dl.TileLayer(
         url=esri_url.format(