from __future__ import print_function
from ipyleaflet import (
Map,
Marker,
TileLayer, ImageOverlay,
Polyline, Polygon, Rectangle, Circle, CircleMarker,
GeoJSON,
DrawControl
)
center = [41.8919300, 12.5113300]
zoom = 6
m = Map(center=center, zoom=zoom)
m
Failed to display Jupyter Widget of type Map
.
If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean that the widgets JavaScript is still loading. If this message persists, it likely means that the widgets JavaScript library is either not installed or not enabled. See the Jupyter Widgets Documentation for setup instructions.
If you're reading this message in another frontend (for example, a static rendering on GitHub or NBViewer), it may mean that your frontend doesn't currently support widgets.
import matplotlib as mpl
import matplotlib.cm
import matplotlib.colors
import numpy as np
def n_colors(n, colormap=mpl.cm.Blues):
data = np.linspace(0.0,1.0,n)
c = [mpl.colors.rgb2hex(d[0:3]) for d in colormap(data)]
return c
def data_to_colors(data, colormap=mpl.cm.Blues):
c = [mpl.colors.rgb2hex(d[0:3]) for d in colormap(mpl.colors.Normalize()(data))]
return c
import json
with open('romandata.json') as f:
data = json.load(f)
data['features'][0]['geometry']
{'type': 'Polygon', 'id': '#geo-disc-tile-geom-032021', 'coordinates': [[[-84.375, 27.059125784374068], [-78.75000000000001, 27.059125784374068], [-78.75000000000001, 31.952162238024975], [-84.375, 31.952162238024975], [-84.375, 27.059125784374068]]]}
n_features = len(data['features'][0]['geometry'])
colors = n_colors(n_features)
print(n_features)
3
colors
['#f7fbff', '#6aaed6', '#08306b']
for feature, color in zip(data['features'], colors):
feature['properties']['style'] = {'color':color, 'weight': 1, 'fillColor':color, 'fillOpacity':0.5}
data['features'][0]['geometry']
{'type': 'Polygon', 'id': '#geo-disc-tile-geom-032021', 'coordinates': [[[-84.375, 27.059125784374068], [-78.75000000000001, 27.059125784374068], [-78.75000000000001, 31.952162238024975], [-84.375, 31.952162238024975], [-84.375, 27.059125784374068]]]}
g = GeoJSON(data=data)
m.add_layer(g)
m
Failed to display Jupyter Widget of type Map
.
If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean that the widgets JavaScript is still loading. If this message persists, it likely means that the widgets JavaScript library is either not installed or not enabled. See the Jupyter Widgets Documentation for setup instructions.
If you're reading this message in another frontend (for example, a static rendering on GitHub or NBViewer), it may mean that your frontend doesn't currently support widgets.