def show_datasets( dss, mode='leaflet', dst=None, layer_name='Datasets', style={}, simplify=True, tolerance=0.001, # ~100m at equator **kw): """ Display dataset footprints on a Leaflet map. :param mode: leaflet|geojson, geojson only works in JupyterLab, leave it as default :param dst: leaflet map to "show" datasets on, default -- create new one :param layer_name: name to give to the layer :param style: GeoJSON style dictionary - weight - color/fillColor - opacity/fillOpacity - full list of options here: https://leafletjs.com/reference-1.5.0.html#path-option :param simplify: simplify geometries before adding them to map :param tolerance: tolerance in degrees for geometry simplification, default 0.001 ~ 111 meters at equator **kw: Arguments to pass to leaflet.Map(..) constructor """ if mode not in ('leaflet', 'geojson'): raise ValueError('Invalid value for mode, expected: leaflet|geojson') polygons, bbox = dss_to_geojson(dss, bbox=True, simplify=simplify, tolerance=tolerance) if mode == 'geojson': from IPython.display import GeoJSON return GeoJSON(polygons) if mode == 'leaflet': from ipyleaflet import Map, GeoJSON, FullScreenControl, LayersControl if dst is None: center = kw.pop('center', None) zoom = kw.pop('zoom', None) if center is None: center = (bbox.bottom + bbox.top) * 0.5, (bbox.right + bbox.left) * 0.5 if zoom is None: zoom = zoom_from_bbox(bbox) height = kw.pop('height', '600px') width = kw.pop('width', None) m = Map(center=center, zoom=zoom, **kw) m.layout.height = height m.layout.width = width m.add_control(FullScreenControl()) m.add_control(LayersControl()) else: m = dst gg = GeoJSON(data={ 'type': 'FeatureCollection', 'features': polygons }, style=style, hover_style={'color': 'tomato'}, name=layer_name) m.add_layer(gg) if dst is None: return m else: return gg
GeoJSON( { "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": { "name": "Van Dorn Street", "marker-color": "#0000ff", "marker-symbol": "rail-metro", "line": "blue" }, "geometry": { "type": "Point", "coordinates": [ -77.12911152370515, 38.79930767201779 ] } }, { "type": "Feature", "properties": { "name": "Glenmont", "marker-color": "#ff0000", "marker-symbol": "rail-metro", "line": "red" }, "geometry": { "type": "Point", "coordinates": [ -77.05355735935977, 39.06178376553033 ] } }] }, )
GeoJSON( { "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": { "name": "Van Dorn Street", "marker-color": "#0000ff", "marker-symbol": "rail-metro", "line": "blue" }, "geometry": { "type": "Point", "coordinates": [ -77.12911152370515, 38.79930767201779 ] } }, { "type": "Feature", "properties": { "name": "Franconia-Springfield", "marker-color": "#0000ff", "marker-symbol": "rail-metro", "line": "blue" }, "geometry": { "type": "Point", "coordinates": [ -77.16797018042666, 38.766521892689916 ] } }, { "type": "Feature", "properties": { "name": "Federal Center SW", "marker-color": "#0000ff", "marker-symbol": "rail-metro", "line": "blue" }, "geometry": { "type": "Point", "coordinates": [ -77.01586821694521, 38.885072355144786 ] } }, { "type": "Feature", "properties": { "name": "Judiciary Sq", "marker-color": "#ff0000", "marker-symbol": "rail-metro", "line": "red" }, "geometry": { "type": "Point", "coordinates": [ -77.01663895662587, 38.896090317663166 ] } }, { "type": "Feature", "properties": { "name": "Capitol South", "marker-color": "#0000ff", "marker-symbol": "rail-metro", "line": "blue" }, "geometry": { "type": "Point", "coordinates": [ -77.00513941992737, 38.885062500925 ] } }, { "type": "Feature", "properties": { "name": "Metro Center", "marker-color": "#ff0000", "marker-symbol": "rail-metro", "line": "red" }, "geometry": { "type": "Point", "coordinates": [ -77.02807799718069, 38.89831447321318 ] } }, { "type": "Feature", "properties": { "name": "Gallery Pl-Chinatown", "marker-color": "#ff0000", "marker-symbol": "rail-metro", "line": "red" }, "geometry": { "type": "Point", "coordinates": [ -77.02191539042379, 38.89831680979661 ] } }, { "type": "Feature", "properties": { "name": "Mt Vernon Sq - 7th St Convention Center", "marker-color": "#008000", "marker-symbol": "rail-metro", "line": "green" }, "geometry": { "type": "Point", "coordinates": [ -77.02191438038649, 38.906436814951725 ] } }, { "type": "Feature", "properties": { "name": "U St/African-Amer Civil War Memorial/Cardozo", "marker-color": "#008000", "marker-symbol": "rail-metro", "line": "green" }, "geometry": { "type": "Point", "coordinates": [ -77.0274958929489, 38.91700239924426 ] } }, { "type": "Feature", "properties": { "name": "Union Station", "marker-color": "#ff0000", "marker-symbol": "rail-metro", "line": "red" }, "geometry": { "type": "Point", "coordinates": [ -77.00741429219985, 38.89776603923524 ] } }, { "type": "Feature", "properties": { "name": "Congress Heights", "marker-color": "#008000", "marker-symbol": "rail-metro", "line": "green" }, "geometry": { "type": "Point", "coordinates": [ -76.98851193260715, 38.84565770287511 ] } }, { "type": "Feature", "properties": { "name": "Naylor Road", "marker-color": "#008000", "marker-symbol": "rail-metro", "line": "green" }, "geometry": { "type": "Point", "coordinates": [ -76.95626270945314, 38.8513013835867 ] } }, { "type": "Feature", "properties": { "name": "Suitland", "marker-color": "#008000", "marker-symbol": "rail-metro", "line": "green" }, "geometry": { "type": "Point", "coordinates": [ -76.93187015895299, 38.84396455441679 ] } }, { "type": "Feature", "properties": { "name": "Branch Ave", "marker-color": "#008000", "marker-symbol": "rail-metro", "line": "green" }, "geometry": { "type": "Point", "coordinates": [ -76.91146421773884, 38.82644634832078 ] } }, { "type": "Feature", "properties": { "name": "Braddock Road", "marker-color": "#0000ff", "marker-symbol": "rail-metro", "line": "blue" }, "geometry": { "type": "Point", "coordinates": [ -77.05366757406264, 38.81414366728901 ] } }, { "type": "Feature", "properties": { "name": "King St - Old Town", "marker-color": "#0000ff", "marker-symbol": "rail-metro", "line": "blue" }, "geometry": { "type": "Point", "coordinates": [ -77.06081120854599, 38.806586117247996 ] } }, { "type": "Feature", "properties": { "name": "Eisenhower Ave", "marker-color": "#ffff00", "marker-symbol": "rail-metro", "line": "yellow" }, "geometry": { "type": "Point", "coordinates": [ -77.07087438931458, 38.800425449701244 ] } }, { "type": "Feature", "properties": { "name": "Huntington", "marker-color": "#ffff00", "marker-symbol": "rail-metro", "line": "yellow" }, "geometry": { "type": "Point", "coordinates": [ -77.075205789149, 38.793915852906736 ] } }, { "type": "Feature", "properties": { "name": "Anacostia", "marker-color": "#008000", "marker-symbol": "rail-metro", "line": "green" }, "geometry": { "type": "Point", "coordinates": [ -76.99537073875437, 38.862963116801595 ] } }, { "type": "Feature", "properties": { "name": "Eastern Market", "marker-color": "#0000ff", "marker-symbol": "rail-metro", "line": "blue" }, "geometry": { "type": "Point", "coordinates": [ -76.99600112671642, 38.884622260842676 ] } }, { "type": "Feature", "properties": { "name": "Potomac Ave", "marker-color": "#0000ff", "marker-symbol": "rail-metro", "line": "blue" }, "geometry": { "type": "Point", "coordinates": [ -76.98549531965503, 38.88126327363317 ] } }, { "type": "Feature", "properties": { "name": "Stadium Armory", "marker-color": "#0000ff", "marker-symbol": "rail-metro", "line": "blue" }, "geometry": { "type": "Point", "coordinates": [ -76.97708890144222, 38.88670908984284 ] } }, { "type": "Feature", "properties": { "name": "Rhode Island Ave", "marker-color": "#ff0000", "marker-symbol": "rail-metro", "line": "red" }, "geometry": { "type": "Point", "coordinates": [ -76.9959369166641, 38.921059689186336 ] } }, { "type": "Feature", "properties": { "name": "Minnesota Ave", "marker-color": "#ffa500", "marker-symbol": "rail-metro", "line": "orange" }, "geometry": { "type": "Point", "coordinates": [ -76.94674773364017, 38.89919122308901 ] } }, { "type": "Feature", "properties": { "name": "Van Ness-UDC", "marker-color": "#ff0000", "marker-symbol": "rail-metro", "line": "red" }, "geometry": { "type": "Point", "coordinates": [ -77.06298618051905, 38.94326528832245 ] } }, { "type": "Feature", "properties": { "name": "Cleveland Park", "marker-color": "#ff0000", "marker-symbol": "rail-metro", "line": "red" }, "geometry": { "type": "Point", "coordinates": [ -77.05804251913345, 38.93476289080542 ] } }, { "type": "Feature", "properties": { "name": "Columbia Heights", "marker-color": "#008000", "marker-symbol": "rail-metro", "line": "green" }, "geometry": { "type": "Point", "coordinates": [ -77.03255211771173, 38.9278379675233 ] } }, { "type": "Feature", "properties": { "name": "College Park-U of Md", "marker-color": "#008000", "marker-symbol": "rail-metro", "line": "green" }, "geometry": { "type": "Point", "coordinates": [ -76.92812498187074, 38.97863363396686 ] } }, { "type": "Feature", "properties": { "name": "Capitol Heights", "marker-color": "#0000ff", "marker-symbol": "rail-metro", "line": "blue" }, "geometry": { "type": "Point", "coordinates": [ -76.91180811452222, 38.889465856872334 ] } }, { "type": "Feature", "properties": { "name": "Morgan Boulevard", "marker-color": "#0000ff", "marker-symbol": "rail-metro", "line": "blue" }, "geometry": { "type": "Point", "coordinates": [ -76.86807476813904, 38.89383492821474 ] } }, { "type": "Feature", "properties": { "name": "Georgia Ave Petworth", "marker-color": "#008000", "marker-symbol": "rail-metro", "line": "green" }, "geometry": { "type": "Point", "coordinates": [ -77.02346090408138, 38.93743463014478 ] } }, { "type": "Feature", "properties": { "name": "Takoma", "marker-color": "#ff0000", "marker-symbol": "rail-metro", "line": "red" }, "geometry": { "type": "Point", "coordinates": [ -77.01817669871063, 38.97607853106706 ] } }, { "type": "Feature", "properties": { "name": "Glenmont", "marker-color": "#ff0000", "marker-symbol": "rail-metro", "line": "red" }, "geometry": { "type": "Point", "coordinates": [ -77.05355735935977, 39.06178376553033 ] } }, { "type": "Feature", "properties": { "name": "Wheaton", "marker-color": "#ff0000", "marker-symbol": "rail-metro", "line": "red" }, "geometry": { "type": "Point", "coordinates": [ -77.05010705352652, 39.03752714367442 ] } }, { "type": "Feature", "properties": { "name": "Forest Glen", "marker-color": "#ff0000", "marker-symbol": "rail-metro", "line": "red" }, "geometry": { "type": "Point", "coordinates": [ -77.04291655489614, 39.01495427527835 ] } }, { "type": "Feature", "properties": { "name": "Silver Spring", "marker-color": "#ff0000", "marker-symbol": "rail-metro", "line": "red" }, "geometry": { "type": "Point", "coordinates": [ -77.03101782681891, 38.99394937476845 ] } }, { "type": "Feature", "properties": { "name": "Brookland-CUA", "marker-color": "#ff0000", "marker-symbol": "rail-metro", "line": "red" }, "geometry": { "type": "Point", "coordinates": [ -76.99453428510049, 38.93321099135371 ] } }, { "type": "Feature", "properties": { "name": "Fort Totten", "marker-color": "#ff0000", "marker-symbol": "rail-metro", "line": "red" }, "geometry": { "type": "Point", "coordinates": [ -77.00220307680834, 38.95184676758986 ] } }, { "type": "Feature", "properties": { "name": "Prince George's Plaza", "marker-color": "#008000", "marker-symbol": "rail-metro", "line": "green" }, "geometry": { "type": "Point", "coordinates": [ -76.95588150788183, 38.96538544585582 ] } }, { "type": "Feature", "properties": { "name": "West Hyattsville", "marker-color": "#008000", "marker-symbol": "rail-metro", "line": "green" }, "geometry": { "type": "Point", "coordinates": [ -76.9695766751036, 38.955040170722334 ] } }, { "type": "Feature", "properties": { "name": "Benning Road", "marker-color": "#0000ff", "marker-symbol": "rail-metro", "line": "blue" }, "geometry": { "type": "Point", "coordinates": [ -76.93836486812415, 38.89097567600269 ] } }, { "type": "Feature", "properties": { "name": "Addison Road Seat Pleasant", "marker-color": "#0000ff", "marker-symbol": "rail-metro", "line": "blue" }, "geometry": { "type": "Point", "coordinates": [ -76.89410791000809, 38.886747816832674 ] } }, { "type": "Feature", "properties": { "name": "Deanwood", "marker-color": "#ffa500", "marker-symbol": "rail-metro", "line": "orange" }, "geometry": { "type": "Point", "coordinates": [ -76.93525678304978, 38.908178496517216 ] } }, { "type": "Feature", "properties": { "name": "New Carrollton", "marker-color": "#ffa500", "marker-symbol": "rail-metro", "line": "orange" }, "geometry": { "type": "Point", "coordinates": [ -76.87184128655672, 38.94778485583298 ] } }, { "type": "Feature", "properties": { "name": "Landover", "marker-color": "#ffa500", "marker-symbol": "rail-metro", "line": "orange" }, "geometry": { "type": "Point", "coordinates": [ -76.8911979676093, 38.93350623445376 ] } }, { "type": "Feature", "properties": { "name": "Cheverly", "marker-color": "#ffa500", "marker-symbol": "rail-metro", "line": "orange" }, "geometry": { "type": "Point", "coordinates": [ -76.91662804405367, 38.916631854659755 ] } }, { "type": "Feature", "properties": { "name": "Largo Town Center", "marker-color": "#0000ff", "marker-symbol": "rail-metro", "line": "blue" }, "geometry": { "type": "Point", "coordinates": [ -76.84203752022478, 38.905068807210085 ] } }, { "type": "Feature", "properties": { "name": "NoMa - Gallaudet U", "marker-color": "#ff0000", "marker-symbol": "rail-metro", "line": "red" }, "geometry": { "type": "Point", "coordinates": [ -77.00302044727623, 38.9070162121509 ] } }, { "type": "Feature", "properties": { "name": "Rosslyn", "marker-color": "#0000ff", "marker-symbol": "rail-metro", "line": "blue" }, "geometry": { "type": "Point", "coordinates": [ -77.07090868538504, 38.89597909628309 ] } }, { "type": "Feature", "properties": { "name": "Arlington|Cemetery", "marker-color": "#0000ff", "marker-symbol": "rail-metro", "line": "blue" }, "geometry": { "type": "Point", "coordinates": [ -77.06281012914037, 38.88468685852292 ] } }, { "type": "Feature", "properties": { "name": "Dupont Circle", "marker-color": "#ff0000", "marker-symbol": "rail-metro", "line": "red" }, "geometry": { "type": "Point", "coordinates": [ -77.04341435972708, 38.90959805757176 ] } }, { "type": "Feature", "properties": { "name": "Pentagon", "marker-color": "#0000ff", "marker-symbol": "rail-metro", "line": "blue" }, "geometry": { "type": "Point", "coordinates": [ -77.05371567343194, 38.869462701258364 ] } }, { "type": "Feature", "properties": { "name": "Crystal City", "marker-color": "#0000ff", "marker-symbol": "rail-metro", "line": "blue" }, "geometry": { "type": "Point", "coordinates": [ -77.05028980970857, 38.857904320437974 ] } }, { "type": "Feature", "properties": { "name": "Navy Yard - Ballpark", "marker-color": "#008000", "marker-symbol": "rail-metro", "line": "green" }, "geometry": { "type": "Point", "coordinates": [ -77.00508565136944, 38.87648108490679 ] } }, { "type": "Feature", "properties": { "name": "McPherson Sq", "marker-color": "#0000ff", "marker-symbol": "rail-metro", "line": "blue" }, "geometry": { "type": "Point", "coordinates": [ -77.03363417212512, 38.90133279688736 ] } }, { "type": "Feature", "properties": { "name": "Shaw-Howard Univ", "marker-color": "#008000", "marker-symbol": "rail-metro", "line": "green" }, "geometry": { "type": "Point", "coordinates": [ -77.02191170078564, 38.91347687116465 ] } }, { "type": "Feature", "properties": { "name": "Southern Ave", "marker-color": "#008000", "marker-symbol": "rail-metro", "line": "green" }, "geometry": { "type": "Point", "coordinates": [ -76.97505413887284, 38.841085780329024 ] } }, { "type": "Feature", "properties": { "name": "Greenbelt", "marker-color": "#008000", "marker-symbol": "rail-metro", "line": "green" }, "geometry": { "type": "Point", "coordinates": [ -76.91105757313493, 39.01114586051427 ] } }, { "type": "Feature", "properties": { "name": "Tenleytown-AU", "marker-color": "#ff0000", "marker-symbol": "rail-metro", "line": "red" }, "geometry": { "type": "Point", "coordinates": [ -77.07958732553253, 38.94885143514487 ] } }, { "type": "Feature", "properties": { "name": "West Falls Church VT/UVA", "marker-color": "#ffa500", "marker-symbol": "rail-metro", "line": "orange" }, "geometry": { "type": "Point", "coordinates": [ -77.18909482259758, 38.90078055103285 ] } }, { "type": "Feature", "properties": { "name": "Dunn Loring Merrifield", "marker-color": "#ffa500", "marker-symbol": "rail-metro", "line": "orange" }, "geometry": { "type": "Point", "coordinates": [ -77.22716067211516, 38.88362513595476 ] } }, { "type": "Feature", "properties": { "name": "Vienna Fairfax-GMU", "marker-color": "#ffa500", "marker-symbol": "rail-metro", "line": "orange" }, "geometry": { "type": "Point", "coordinates": [ -77.27262225692775, 38.877601123856635 ] } }, { "type": "Feature", "properties": { "name": "Friendship Heights", "marker-color": "#ff0000", "marker-symbol": "rail-metro", "line": "red" }, "geometry": { "type": "Point", "coordinates": [ -77.08499580503951, 38.959483873675715 ] } }, { "type": "Feature", "properties": { "name": "Shady Grove", "marker-color": "#ff0000", "marker-symbol": "rail-metro", "line": "red" }, "geometry": { "type": "Point", "coordinates": [ -77.16462733437842, 39.11992732498129 ] } }, { "type": "Feature", "properties": { "name": "Rockville", "marker-color": "#ff0000", "marker-symbol": "rail-metro", "line": "red" }, "geometry": { "type": "Point", "coordinates": [ -77.14612533928484, 39.084321607556745 ] } }, { "type": "Feature", "properties": { "name": "Twinbrook", "marker-color": "#ff0000", "marker-symbol": "rail-metro", "line": "red" }, "geometry": { "type": "Point", "coordinates": [ -77.12081795176874, 39.06246765170041 ] } }, { "type": "Feature", "properties": { "name": "White Flint", "marker-color": "#ff0000", "marker-symbol": "rail-metro", "line": "red" }, "geometry": { "type": "Point", "coordinates": [ -77.1128298590364, 39.04815135732502 ] } }, { "type": "Feature", "properties": { "name": "Grosvenor-Strathmore", "marker-color": "#ff0000", "marker-symbol": "rail-metro", "line": "red" }, "geometry": { "type": "Point", "coordinates": [ -77.10384972001367, 39.02926895002534 ] } }, { "type": "Feature", "properties": { "name": "Medical Center", "marker-color": "#ff0000", "marker-symbol": "rail-metro", "line": "red" }, "geometry": { "type": "Point", "coordinates": [ -77.09695229054405, 39.00005648434642 ] } }, { "type": "Feature", "properties": { "name": "Bethesda", "marker-color": "#ff0000", "marker-symbol": "rail-metro", "line": "red" }, "geometry": { "type": "Point", "coordinates": [ -77.09412919222653, 38.984393660394474 ] } }, { "type": "Feature", "properties": { "name": "Foggy Bottom GWU", "marker-color": "#0000ff", "marker-symbol": "rail-metro", "line": "blue" }, "geometry": { "type": "Point", "coordinates": [ -77.05027773906102, 38.900698009227014 ] } }, { "type": "Feature", "properties": { "name": "Court House", "marker-color": "#ffa500", "marker-symbol": "rail-metro", "line": "orange" }, "geometry": { "type": "Point", "coordinates": [ -77.0871312310518, 38.89017553121852 ] } }, { "type": "Feature", "properties": { "name": "Clarendon", "marker-color": "#ffa500", "marker-symbol": "rail-metro", "line": "orange" }, "geometry": { "type": "Point", "coordinates": [ -77.09539409835607, 38.886704839074675 ] } }, { "type": "Feature", "properties": { "name": "East Falls Church", "marker-color": "#ffa500", "marker-symbol": "rail-metro", "line": "orange" }, "geometry": { "type": "Point", "coordinates": [ -77.15688301999151, 38.88595316637261 ] } }, { "type": "Feature", "properties": { "name": "Virginia Square-GMU", "marker-color": "#ffa500", "marker-symbol": "rail-metro", "line": "orange" }, "geometry": { "type": "Point", "coordinates": [ -77.10297729421117, 38.88336615180341 ] } }, { "type": "Feature", "properties": { "name": "Ballston-MU", "marker-color": "#ffa500", "marker-symbol": "rail-metro", "line": "orange" }, "geometry": { "type": "Point", "coordinates": [ -77.11316883505587, 38.882182873810734 ] } }, { "type": "Feature", "properties": { "name": "Farragut West", "marker-color": "#0000ff", "marker-symbol": "rail-metro", "line": "blue" }, "geometry": { "type": "Point", "coordinates": [ -77.0406954151549, 38.90131289417984 ] } }, { "type": "Feature", "properties": { "name": "Farragut North", "marker-color": "#ff0000", "marker-symbol": "rail-metro", "line": "red" }, "geometry": { "type": "Point", "coordinates": [ -77.03970082724703, 38.90320194626843 ] } }, { "type": "Feature", "properties": { "name": "Woodley Park-Zoo Adams Morgan", "marker-color": "#ff0000", "marker-symbol": "rail-metro", "line": "red" }, "geometry": { "type": "Point", "coordinates": [ -77.05241802079871, 38.92508513710051 ] } }, { "type": "Feature", "properties": { "name": "L'Enfant Plaza", "marker-color": "#008000", "marker-symbol": "rail-metro", "line": "green" }, "geometry": { "type": "Point", "coordinates": [ -77.02190848409535, 38.88483772791197 ] } }, { "type": "Feature", "properties": { "name": "Smithsonian", "marker-color": "#0000ff", "marker-symbol": "rail-metro", "line": "blue" }, "geometry": { "type": "Point", "coordinates": [ -77.02806623428602, 38.888018702051426 ] } }, { "type": "Feature", "properties": { "name": "Pentagon City", "marker-color": "#0000ff", "marker-symbol": "rail-metro", "line": "blue" }, "geometry": { "type": "Point", "coordinates": [ -77.05953892154457, 38.86188238675449 ] } }, { "type": "Feature", "properties": { "name": "Federal Triangle", "marker-color": "#0000ff", "marker-symbol": "rail-metro", "line": "blue" }, "geometry": { "type": "Point", "coordinates": [ -77.02813199840536, 38.89318087185462 ] } }, { "type": "Feature", "properties": { "name": "Archives-Navy Mem'l", "marker-color": "#008000", "marker-symbol": "rail-metro", "line": "green" }, "geometry": { "type": "Point", "coordinates": [ -77.02191438799919, 38.89366522352208 ] } }, { "type": "Feature", "properties": { "name": "Waterfront", "marker-color": "#008000", "marker-symbol": "rail-metro", "line": "green" }, "geometry": { "type": "Point", "coordinates": [ -77.01750520880347, 38.87646186689611 ] } }, { "type": "Feature", "properties": { "name": "Ronald Reagan Washington National Airport", "marker-color": "#0000ff", "marker-symbol": "rail-metro", "line": "blue" }, "geometry": { "type": "Point", "coordinates": [ -77.04404229438322, 38.85341638599062 ] } } ] } )