Beispiel #1
0
 def __init__(self, location=None, layout='horizontal', **kwargs):
     super(DualMap, self).__init__()
     for key in ('width', 'height', 'left', 'top', 'position'):
         assert key not in kwargs, ('Argument {} cannot be used with '
                                    'DualMap.'.format(key))
     if layout not in ('horizontal', 'vertical'):
         raise ValueError(
             'Undefined option for argument `layout`: {}. '
             'Use either \'horizontal\' or \'vertical\'.'.format(layout))
     width = '50%' if layout == 'horizontal' else '100%'
     height = '100%' if layout == 'horizontal' else '50%'
     self.m1 = Map(location=location,
                   width=width,
                   height=height,
                   left='0%',
                   top='0%',
                   position='absolute',
                   **kwargs)
     self.m2 = Map(location=location,
                   width=width,
                   height=height,
                   left='50%' if layout == 'horizontal' else '0%',
                   top='0%' if layout == 'horizontal' else '50%',
                   position='absolute',
                   **kwargs)
     figure = Figure()
     figure.add_child(self.m1)
     figure.add_child(self.m2)
     # Important: add self to Figure last.
     figure.add_child(self)
     self.children_for_m2 = []
     self.children_for_m2_copied = []  # list with ids
Beispiel #2
0
def make_map(bbox, **kw):
    """Creates a folium map instance."""
    line = kw.pop('line', True)
    zoom_start = kw.pop('zoom_start', 7)

    lon, lat = np.array(bbox).reshape(2, 2).mean(axis=0)
    m = Map(width=750, height=500, location=[lat, lon], zoom_start=zoom_start)
    if line:
        # Create the map and add the bounding box line.
        kw = dict(line_color='#FF0000', line_weight=2)
        m.line(get_coordinates(bbox), **kw)
    return m
def map_results_raster(structure_list, raster, breach=None, book=None, width=800, height=700, zoom = 14):
    from folium import raster_layers
    colormap=lambda x: (0, 0, 0, x)
    
    overtopped={}
    # Read in Raster Data
    src = gdal.Open(raster)
    ulx, xres, xskew, uly, yskew, yres  = src.GetGeoTransform()
    lrx = ulx + (src.RasterXSize * xres)
    lry = uly + (src.RasterYSize * yres)
    centerx, centery  = np.mean([ulx, lrx]),np.mean([uly, lry])
    img = src.ReadAsArray()
        
    colormap=lambda x: (0, 1, 1, x)
    folmap = Map(width=800, height=700, location=[centery, centerx], zoom_start=zoom)
    folmap.add_child(raster_layers.ImageOverlay(img, colormap=colormap,opacity=0.5, bounds =[[lry, lrx],[uly, ulx]], mercator_project=True))
    
    if isinstance(breach, gpd.geodataframe.GeoDataFrame):
        if breach.crs != '4326':
            breach = breach.to_crs({'init' :'epsg:4326'})
        html = f"""<h4>Breach Location</h4>"""    
        iframe=branca.element.IFrame(html=html, width=120, height=80)    
        popup = folium.Popup(iframe)  
        folmap.add_child(folium.CircleMarker(location=[breach.loc[0, 'geometry'].y, 
                                     breach.loc[0, 'geometry'].x], 
                                     popup= popup,radius=6, weight=12, color='Red'))
        
    if isinstance(book, gpd.geodataframe.GeoDataFrame):
        print('Book!', book.crs)
        if book.crs != {'init': 'epsg:4326'}:
            print('Projecting')
            book = book.to_crs({'init' :'epsg:4326'})
            # Placeholder for plotting structures
            

    for structures in structure_list:
        #print(structures.crs)
        if structures.crs != '4326':
            structures = structures.to_crs({'init' :'epsg:4326'})
        try:


            for idx in structures.index:
                sID =  structures.loc[idx, 'ID']  
                sWSE = round(structures.loc[idx, 'Max WSE'],2)
                sCrest = round(structures.loc[idx, 'Crest'],2)
                sStation = int(structures.loc[idx, 'Station'])

                if sWSE < sCrest:
                    html = f"""<h4>{sID}</h4><p>Station {sStation}</p><p>Levee Crest {sCrest}</p><p>Max WSE {sWSE}</p>"""
                    iframe=branca.element.IFrame(html=html, width=200, height=150)    
                    popup = folium.Popup(iframe)  
                    folmap.add_child(folium.CircleMarker(location=[structures.loc[idx, 'geometry'].y, 
                                                 structures.loc[idx, 'geometry'].x], 
                                                 popup= popup,radius=3, weight=3, color='black'))
                else:
                    max_depth=round(sWSE-sCrest,2)
                    overtopped[f'{sID} Station {sStation}'] =  max_depth
                    html = f"""<h4>{sID}</h4><p>Station {sStation}</p><p>Levee Crest {sCrest}</p><p>Max WSE {sWSE}</p><p>Max Overtopping Depth {max_depth}</p>"""
                    iframe=branca.element.IFrame(html=html, width=200, height=250)    
                    popup = folium.Popup(iframe) 
                    folmap.add_child(folium.CircleMarker(location=[structures.loc[idx, 'geometry'].y, 
                                                 structures.loc[idx, 'geometry'].x], 
                                                 popup= popup,radius=4, weight=4, color='red'))
                    
            line_points = zip(structures.geometry.y.values,structures.geometry.x.values)
            folium.PolyLine(list(line_points), color='black').add_to(folmap)
        except:
            print('ERROR')
                
    add_tiles(folmap)
    return folmap, overtopped

def inline_map(m):
    if isinstance(m, Map):
        m._build_map()
        srcdoc = m.HTML.replace('"', '&quot;')
        embed = HTML('<iframe srcdoc="{srcdoc}" '
                     'style="width: 100%; height: 500px; '
                     'border: none"></iframe>'.format(srcdoc=srcdoc))
    elif isinstance(m, str):
        embed = IFrame(m, width=750, height=500)
    return embed

# <codecell>

m = Map(width=750, height=500, location=[42, -72], zoom_start=5)

url='http://coast.noaa.gov/arcgis/services/CCAP/All_Change_0106/MapServer/WMSServer?request=GetCapabilities&service=WMS'

m.add_wms_layer(wms_name="northeast_0106_all_change_wm",
                wms_url="http://coast.noaa.gov/arcgis/services/CCAP/All_Change_0106/MapServer/WMSServer",
                wms_format="image/png",
                wms_layers='2')

m.add_layers_to_map()
inline_map(m)

# <codecell>