def render_example6(): # Generate some in-memory data. bermuda = dlx.dicts_to_geojson([dict(lat=32.299507, lon=-64.790337)]) biosfera = dlx.geojson_to_geobuf( dlx.dicts_to_geojson([dict(lat=29.015, lon=-118.271)])) with open("data/KCNeighborhood.json", 'r') as f: statesData = json.load(f) return [ dl.Map( center=[39, -98], zoom=4, children=[ dl.TileLayer(), dl.GeoJSON(data=bermuda), # in-memory geojson (slowest option) dl.GeoJSON( data=biosfera, format="geobuf" ), # in-memory geobuf (smaller payload than geojson) dl.GeoJSON( data=statesData, id="capitals"), # geojson resource (faster than in-memory) ], style={ 'width': '100%', 'height': '50vh', 'margin': "auto", "display": "block" }, id="map"), html.Div(id="state"), html.Div(id="capital") ]
def get_data(dataframe): df = dataframe.drop_duplicates(subset='ChargePoint_ID') dicts = df.to_dict('records') for item in dicts: item["tooltip"] = f'{item["Address"]}, {item["PostalCode"]}, {item["ChargePoint_ID"]}' # bind tooltip item['Selected'] = 'Not Selected' geojson = dlx.dicts_to_geojson( dicts, lon="Longitude", lat="Latitude") # convert to geojson geobuf = dlx.geojson_to_geobuf(geojson) # convert to geobuf return geobuf
def get_data(nbhid, years_range): # filter_df = df[(df['CREATION YEAR'] <= years_range[1]) & # (df['CREATION YEAR'] >= years_range[0])] df_nbh = df[df["nbhid"] == nbhid] # pick one state df_nbh = df_nbh[['LATITUDE', 'LONGITUDE', 'NEIGHBORHOOD', 'DAYS TO CLOSE']] # use only relevant columns dicts = df_nbh.to_dict('rows') for item in dicts: item["tooltip"] = "{:.1f}".format(item[color_prop]) # bind tooltip item["popup"] = item["NEIGHBORHOOD"] # bind popup geojson = dlx.dicts_to_geojson(dicts, lat="LATITUDE", lon="LONGITUDE") # convert to geojson geobuf = dlx.geojson_to_geobuf(geojson) # convert to geobuf return geobuf
def get_data(color_prop): df = read_data().dropna(subset=[color_prop]) # drop irrelevant columns df = df[['lat', 'lon', 'alt', 'station', 'date', color_prop]] dicts = df.to_dict('rows') for item in dicts: item["tooltip"] = "Measured at %s : %2.1f" % (item["date"], item[color_prop]) item["popup"] = "%s, altitude %4.0f" % (item["station"], item["alt"]) geojson = dlx.dicts_to_geojson(dicts, lon="lon", lat="lat") geobuf = dlx.geojson_to_geobuf(geojson) # convert to geobuf return geobuf
def get_data(cpa: int): df_cpa = df[df['cpa_name'] == cpa] if cpa else df df_cpa = df_cpa[[ 'project_nickname', 'cpa_name', 'coordinate_x', 'coordinate_y' ]].dropna() dicts = df_cpa.to_dict('rows') for item in dicts: item['tooltip'] = item['project_nickname'] item['popup'] = item['cpa_name'] geojson = dlx.dicts_to_geojson(dicts, lat='coordinate_x', lon="coordinate_y") geobuf = dlx.geojson_to_geobuf(geojson) return geobuf
def get_project_points(cpa: str): df_cpa = project_outcomes[project_outcomes['cpa_name'] == cpa] if cpa else project_outcomes df_cpa = df_cpa[[ 'project_nickname', 'cpa_name', 'coordinate_x', 'coordinate_y' ]].dropna().drop_duplicates() dicts = df_cpa.to_dict('rows') for item in dicts: item['tooltip'] = item['project_nickname'] item['popup'] = item['cpa_name'] geojson = dlx.dicts_to_geojson(dicts, lat='coordinate_x', lon="coordinate_y") return dlx.geojson_to_geobuf(geojson)
def get_data(variable): df = get_df().dropna(subset=[variable]) # drop irrelevant columns df = df[['latitude', 'longitude', 'altitude', 'name', 'observation_time_local', variable]] dicts = df.to_dict('records') for item in dicts: item["tooltip"] = "Measured at %s : %2.1f" % ( item["observation_time_local"], item[variable]) item["popup"] = "%s, altitude: %4.0f m" % ( item["name"], item["altitude"]) geojson = dlx.dicts_to_geojson(dicts, lon="longitude", lat="latitude") geobuf = dlx.geojson_to_geobuf(geojson) return geobuf
def get_data(state): df_state = df[df["state_id"] == state] # pick one state df_state = df_state[['lat', 'lng', 'city', 'population', 'density']] # drop irrelevant columns df_state = df_state[df_state[color_prop] > 0] # drop abandoned cities df_state[color_prop] = np.log( df_state[color_prop]) # take log as the values varies A LOT dicts = df_state.to_dict('rows') for item in dicts: item["tooltip"] = item["city"] # bind tooltip item["popup"] = item["city"] # bind popup geojson = dlx.dicts_to_geojson(dicts, lon="lng") # convert to geojson geobuf = dlx.geojson_to_geobuf(geojson) # convert to geobuf return geobuf
import numpy as np from dash.dependencies import Output, Input df = pd.read_csv('gridcities.csv') color_prop = 'population' df_state = df.dropna() df_state = df_state[['lat', 'lng', 'city', 'population', 'density']] # drop irrelevant columns dicts = df_state.to_dict('rows') for item in dicts: item["tooltip"] = item["city"] # bind tooltip geojson = dlx.dicts_to_geojson(dicts, lon="lng") # convert to geojson geobuf = dlx.geojson_to_geobuf(geojson) # convert to geobuf with open('geobuf.pkl', 'wb') as f: pickle.dump(geobuf, f, pickle.HIGHEST_PROTOCOL) geojson = dl.GeoJSON( data=geobuf, id="geojson", format="geobuf", zoomToBounds=True, # when true, zooms to bounds when data changes cluster=True, # when true, data are clustered clusterToLayer=dlx.scatter.cluster_to_layer, # how to draw clusters zoomToBoundsOnClick= True, # when true, zooms to bounds of feature (e.g. cluster) on click options=dict( pointToLayer=dlx.scatter.point_to_layer), # how to draw points
encoded_kuk_sound = base64.b64encode(open(kuk_sound, 'rb').read()) encoded_quaa_sound = base64.b64encode(open(quaa_sound, 'rb').read()) encoded_moan_sound = base64.b64encode(open(moan_sound, 'rb').read()) app = dash.Dash(__name__, suppress_callback_exceptions=True, external_stylesheets=[dbc.themes.BOOTSTRAP]) app.title = 'SQURL' server = app.server # Find Lat Long center to set map center lat_center = sum(squirrel_census['lat']) / len(squirrel_census['lat']) long_center = sum(squirrel_census['lon']) / len(squirrel_census['lon']) data = dlx.geojson_to_geobuf(dlx.dicts_to_geojson(squirrel_data)) ns = Namespace("myNamespace", "mySubNamespace") nz = Namespace("dlx", "scatter") # get map style url = 'https://tiles.stadiamaps.com/tiles/alidade_smooth_dark/{z}/{x}/{y}{r}.png' attribution = '© <a href="https://stadiamaps.com/">Stadia Maps</a> ' app.layout = html.Div( children=[ # HEADER html.Div( children=[ html.H1('SQURL', id='header-text'),
def update_local_table(at, data, viewport_ids, selected_row_id, data_state, local_map): # TODO don't pass entire map. just need to see if it exists if (not at) or (at != "local_tab"): raise PreventUpdate ctx = dash.callback_context input_id = ctx.triggered[0]["prop_id"].split(".")[0] dff = pd.DataFrame(data) if dff.empty: return [], [], [], None, None, {} else: if "Per Capita" in dff: color_column = "Per Capita" elif "Per Student" in dff: color_column = "Per Student" else: color_column = "Amount" (styles, legend, df_color, max_y) = du.discrete_background_color_bins(dff, columns=[color_column]) styles = styles + [{ "if": { "column_id": c }, "width": 100, "font-family": "Sparks-Bar-Extrawide", "font-size": "18px", "padding-right": "15px", "padding-left": "15px", } for c in ["sparkline_Per Capita", "sparkline_Per Student"]] bar_charts = [] if (not df_color.empty) and (len(dff["id"].unique()) > 1): dff[color_column + "_color"] = df_color dff = dff[dff["id"].isin(viewport_ids)] bar_charts = du.make_bar_charts(dff, color_column, "ID name", clip=max_y) # update map dff_state = pd.DataFrame(data_state) dff_lat_lng = df_lat_lng[df_lat_lng["state_id"] == dff_state["ST"].iat[0]] dff_state["name"] = dff_state["ID name"].str[:-4] dff_state = pd.merge( dff_state, dff_lat_lng, how="left", left_on=["County name", "name"], right_on=["county_name", "city"], ) dff_state = dff_state.dropna() dicts = dff_state.to_dict("row") for item in dicts: item["popup"] = "${:.0f} per capita {}".format( item[color_column], item["name"]) item["tooltip"] = item["name"] # bind popup geojson_data = dlx.dicts_to_geojson(dicts, lon="lng") # convert to geojson geobuf = dlx.geojson_to_geobuf(geojson_data) # convert to geobuf colors = colorlover.scales[str(5)]["seq"]["Blues"] hideout = dict( colorscale=colors, color_prop=color_column, popup_prop="name", min=0, max=max_y, circle_options=dict(radius=10), ) if selected_row_id and selected_row_id != []: selected_row = dff_state[dff_state["id"].isin(selected_row_id)] lat = selected_row.iloc[0]["lat"] lng = selected_row.iloc[0]["lng"] hideout = dict( colorscale=colors, color_prop=color_column, popup_prop="name", min=0, max=max_y, open=selected_row_id[0], circle_options=dict(radius=10), ) return ( styles, bar_charts, legend, hideout, geobuf, { "zoom": 12, "center": [lat, lng] }, ) else: return styles, bar_charts, legend, hideout, geobuf, {}
from dash_extensions.javascript import arrow_function app = dash.Dash() with open( r"C:\Users\julien_schroder\Desktop\JM_FinaleMaps_Repo\Points4326.geojson" ) as f: points = geojson.load(f) with open( r"C:\Users\julien_schroder\Desktop\JM_FinaleMaps_Repo\Routes4326.geojson" ) as g: routes = geojson.load(g) dRoutes = FeatureCollection([f for f in routes['features']]) dPoints = FeatureCollection([f for f in points['features']]) biosfera = dlx.geojson_to_geobuf( dlx.dicts_to_geojson([dict(lat=29.015, lon=-118.271)])) app.layout = html.Div([ dl.Map( center=[39, -98], zoom=4, children=[ dl.TileLayer(), dl.GeoJSON(data=dPoints, id='capitals', cluster=True), # in-memory geojson (slowest option) dl.GeoJSON(data=dRoutes, id='states' ), # in-memory geobuf (smaller payload than geojson) ], style={ 'width': '100%', 'height': '100vh', 'margin': "auto",