Advertisement
Infidelis

map

Feb 3rd, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.90 KB | None | 0 0
  1. com_dist = mongo.mongo_to_dateframe(['district', 'district_name', 'population'])
  2. com_dist.columns = ['ID_DISTICT', 'NAME_DISTICT', 'population']
  3. nill = geopandas.read_file('community_dist.json')
  4. nill = geopandas.read_file('community_dist.json')
  5. nill = nill[['BoroCD','geometry', 'Shape__Area']]
  6.  
  7. nill.columns = ['ID_DISTICT','geometry', 'area']
  8. nilpop = nill.merge(com_dist,on="ID_DISTICT")
  9.  
  10. mymap = folium.Map(location=[40.75, -74.125], zoom_start=10.5,tiles=None)
  11. folium.TileLayer('CartoDB positron',name="Light Map",control=False).add_to(mymap)
  12.  
  13. style_function = lambda x: {'fillColor': '#ffffff',
  14.                             'color':'#000000',
  15.                             'fillOpacity': 0.1,
  16.                             'weight': 0.1}
  17.  
  18. highlight_function = lambda x: {'fillColor': '#000000',
  19.                                 'color':'#000000',
  20.                                 'fillOpacity': 0.50,
  21.                                 'weight': 0.1}
  22.  
  23. mymap.choropleth(
  24.      geo_data=nilpop,
  25.      name='Choropleth',
  26.      data=nilpop,
  27.      columns=['ID_DISTICT','PER_FOREIGN'],
  28.      key_on="feature.properties.ID_DISTICT",
  29.      fill_color='YlGnBu',
  30.      threshold_scale=myscale,
  31.      fill_opacity=1,
  32.      line_opacity=0.2,
  33.      legend_name='Resident foreign population in %',
  34.      smooth_factor=0
  35. )
  36.  
  37. NIL = folium.features.GeoJson(
  38.     nilpop,
  39.     style_function=style_function,
  40.     control=False,
  41.     highlight_function=highlight_function,
  42.     tooltip=folium.features.GeoJsonTooltip(
  43.         fields=['ID_DISTICT', 'NAME_DISTICT', 'population', 'area'],
  44.         aliases=['District Code: ', 'District Name: ','Dictrict population: ', 'Shape Area:'],
  45.         style=("background-color: white; color: #333333; font-family: arial; font-size: 13px; padding: 10px;")
  46.     )
  47. )
  48.  
  49. mymap.add_child(NIL)
  50. mymap.keep_in_front(NIL)
  51. folium.LayerControl().add_to(mymap)
  52.  
  53. mymap.save(outfile='map-test.html')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement