Ejemplo n.º 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
Ejemplo n.º 2
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
Ejemplo n.º 3
0
def index():
    fig5=Figure(height=550,width=750)
    m5=folium.Map(location=[-6.920817, 107.604100],tiles='cartodbpositron',zoom_start=17)
    fig5.add_child(m5)
    folium.LayerControl().add_to(m5)
    m5.save('templates/map.html')
    return render_template('GoogleMaps.html')
Ejemplo n.º 4
0
def visualisation_sections(
    list_data: List[Tuple],
    map_filename: str,
) -> None:
    """Save the HTML code of the map visualisation. Every tuple correspond to a different point.
    :param list_data: list of tuples which contains
            in position 0: coordinates of the point as a tuple (latitude,longitude),
            in position 1: section of the road related with the point (outpput of find_optimal) with the type List['str','str',tuple,tuple] as the output of get_road_section,
            in position 2: list of all the node of a street (output of get_ways_from_node).
    :param map_filename: name of the map HTML code file.
    return None: the function just save the code with the correct path.
    """

    figure = Figure(height=550, width=750)
    map_display = folium.Map(location=[48.896205, 2.260466],
                             tiles='cartodbpositron',
                             zoom_start=14)
    figure.add_child(map_display)
    colors = [
        'red', 'blue', 'green', 'purple', 'orange', 'darkred', 'lightred',
        'beige', 'darkblue', 'darkgreen', 'cadetblue', 'darkpurple', 'white',
        'pink', 'lightblue', 'lightgreen', 'gray', 'black', 'lightgray'
    ]
    color_index = 0
    for data in list_data:
        latitude, longitude = data[0]
        section = data[1]
        list_node_street = data[2]
        begin_coordinates = section[2]
        end_coordinates = section[3]
        coordinates = [node[1] for node in list_node_street]
        coordinates = coordinates[coordinates.index(begin_coordinates):
                                  coordinates.index(end_coordinates) + 1]
        feature_group = folium.FeatureGroup(
            f"Tronçon Point ({latitude}, {longitude})")
        folium.vector_layers.PolyLine(
            coordinates,
            popup=f'<b>Tronçon Point ({latitude}, {longitude})</b>',
            tooltip=f'Tronçon Point ({latitude}, {longitude})',
            color=colors[color_index % len(colors)],
            weight=10).add_to(feature_group)
        folium.Marker(
            location=[latitude, longitude],
            popup='Custom Marker 1',
            tooltip=
            f'<strong>Point d\'interet ({latitude}, {longitude}) </strong>',
            icon=folium.Icon(color=colors[color_index % len(colors)],
                             icon='none')).add_to(map_display)
        color_index += 1
        feature_group.add_to(map_display)
    folium.LayerControl().add_to(map_display)
    map_display.save(map_filename)
    return None
Ejemplo n.º 5
0
                            infoVertice['value']['latitude'],
                            infoVertice['value']['longitude']
                        ]

                        marker1 = folium.Marker(coordenadasA, popup=vertice)
                        marker1.add_to(mapaReq1)
                        coordREQ1.append(coordenadasA)
            caminoREQ1 = folium.vector_layers.PolyLine(coordREQ1,
                                                       color='red',
                                                       weight=2)
            caminoREQ1.add_to(grupoCaminos1)

            grupoCaminos1.add_to(mapaReq1)
            folium.LayerControl().add_to(mapaReq1)

            baseReq1.add_child(mapaReq1)
            mapaReq1.save("REQ1.html")

            # url1 = "C:\\Users\\juanj\\OneDrive\\Desktop\\Reto 4\\Reto4-G06\\REQ1.html"
            nuevo = 2
            webbrowser.open("REQ1.html", new=nuevo)
        """ 
        REQ 2
        """

        verticeMasArcosReq2 = verticeMasArcosReq2['vertice']
        pais = verticeMasArcosReq2.split('-')[1]

        paisValue = mp.get(analyzer['countries'], pais)['value']

        coordenadasPais = [
Ejemplo n.º 6
0
def test():
    firstloc = request.form['floc']
    endloc = request.form['eloc']
    pilihankota = int(request.form.get("comp_select"))
    adjMatrix = [[]]
    listNode = []
    listCoor = []
    listJalan = []
    if (request.form.get("pilihkota")):
        if (pilihankota == 2) :
            adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("ITB.txt")
        elif (pilihankota == 3) :
            adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("Alunalun.txt")
        elif (pilihankota == 4) :
            adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("buahbatu.txt")
        elif (pilihankota == 5) :
            adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("Kebumen.txt")
        elif (pilihankota == 6) :
            adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("graf.txt")
        elif (pilihankota == 7) :
            adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("tayu.txt")
        elif (pilihankota == 8) :
            adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("blitar.txt")
        elif (pilihankota == 9) :
            adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("monas.txt")
        if request.method == 'POST':
            if (pilihankota == 1):
                fig5=Figure(height=550,width=750)
                m5=folium.Map(location=[-6.920817, 107.604100],tiles='cartodbpositron',zoom_start=17)
                fig5.add_child(m5)
                folium.LayerControl().add_to(m5)
                m5.save('templates/map.html')
                flash('Masukkan Map Kota Anda', "info")
                return render_template('GoogleMaps.html')
        fig5=Figure(height=550,width=750)
        middle = main.middlePoint(listCoor)
        m5=folium.Map(location=[middle[0],middle[1]],tiles='cartodbpositron',zoom_start=17)
        fig5.add_child(m5)
        f1=folium.FeatureGroup("Jalan Asli")
        for i in range(len(listCoor)-1):
            
            for j in range(i+1, len(listCoor)):
                if (adjMatrix[i][j] != 0):
                    place1 = [[listCoor[i][0],listCoor[i][1]],[listCoor[j][0],listCoor[j][1]]]
                    line_1=folium.vector_layers.PolyLine(place1,color='red',weight=10).add_to(f1)

        #bikin node
        for i in range(len(listCoor)):
            folium.Marker(listCoor[i],popup=listNode[i],tooltip='<strong>Click here to see Popup</strong>',icon=folium.Icon(color='blue',icon='none')).add_to(m5)
        
        f1.add_to(m5) 
        folium.LayerControl().add_to(m5)
        m5.save('templates/map.html')
        return render_template('GoogleMaps.html', comp_select = str(pilihankota))
    
    if (request.form.get("search")):
        if (pilihankota == 2) :
            adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("ITB.txt")
            path, isNodeFound, isPathFound = main.main(adjMatrix,listNode,listCoor,firstloc,endloc)
        elif (pilihankota == 3) :
            adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("Alunalun.txt")
            path, isNodeFound, isPathFound = main.main(adjMatrix,listNode,listCoor,firstloc,endloc)
        elif (pilihankota == 4) :
            adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("buahbatu.txt")
            path, isNodeFound, isPathFound = main.main(adjMatrix,listNode,listCoor,firstloc,endloc)
        elif (pilihankota == 5) :
            adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("Kebumen.txt")
            path, isNodeFound, isPathFound = main.main(adjMatrix,listNode,listCoor,firstloc,endloc)
        elif (pilihankota == 6) :
            adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("graf.txt")
            path, isNodeFound, isPathFound = main.main(adjMatrix,listNode,listCoor,firstloc,endloc)
        elif (pilihankota == 7) :
            adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("tayu.txt")
            path, isNodeFound, isPathFound = main.main(adjMatrix,listNode,listCoor,firstloc,endloc)
        elif (pilihankota == 8) :
            adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("blitar.txt")
            path, isNodeFound, isPathFound = main.main(adjMatrix,listNode,listCoor,firstloc,endloc)
        elif (pilihankota == 9) :
            adjMatrix, listNode, listCoor, isFileFound = main.bacaFile("monas.txt")
            path, isNodeFound, isPathFound = main.main(adjMatrix,listNode,listCoor,firstloc,endloc)
        if request.method == 'POST':
            if (pilihankota == 1):
                fig5=Figure(height=550,width=750)
                m5=folium.Map(location=[-6.920817, 107.604100],tiles='cartodbpositron',zoom_start=17)
                fig5.add_child(m5)
                folium.LayerControl().add_to(m5)
                m5.save('templates/map.html')
                flash('Masukkan Map Kota Anda')
                return render_template('GoogleMaps.html')
            
            elif (not isNodeFound): #cek flag nodefound
                fig5=Figure(height=550,width=750)
                middle = main.middlePoint(listCoor)
                m5=folium.Map(location=[middle[0], middle[1]],tiles='cartodbpositron',zoom_start=17)
                fig5.add_child(m5)
                f1=folium.FeatureGroup("Jalan Asli")
                for i in range(len(listCoor)-1):
                    for j in range(i+1, len(listCoor)):
                        if (adjMatrix[i][j] != 0):
                            place1 = [[listCoor[i][0],listCoor[i][1]],[listCoor[j][0],listCoor[j][1]]]
                            line_1=folium.vector_layers.PolyLine(place1,color='red',weight=10).add_to(f1)
                for i in range(len(listCoor)):
                    folium.Marker(listCoor[i],popup=listNode[i],tooltip='<strong>Click here to see Popup</strong>',icon=folium.Icon(color='blue',icon='none')).add_to(m5)
                f1.add_to(m5) 
                folium.LayerControl().add_to(m5)
                m5.save('templates/map.html')
                flash('Tidak ditemukan lokasi yang sesuai')
                return render_template('GoogleMaps.html', comp_select = str(pilihankota))
            elif (not isPathFound):
                fig5=Figure(height=550,width=750)
                middle = main.middlePoint(listCoor)
                m5=folium.Map(location=[middle[0], middle[1]],tiles='cartodbpositron',zoom_start=17)
                fig5.add_child(m5)
                f1=folium.FeatureGroup("Jalan Asli")
                for i in range(len(listCoor)-1):
                    for j in range(i+1, len(listCoor)):
                        if (adjMatrix[i][j] != 0):
                            place1 = [[listCoor[i][0],listCoor[i][1]],[listCoor[j][0],listCoor[j][1]]]
                            line_1=folium.vector_layers.PolyLine(place1,color='red',weight=10).add_to(f1)
                for i in range(len(listCoor)):
                    folium.Marker(listCoor[i],popup=listNode[i],tooltip='<strong>Click here to see Popup</strong>',icon=folium.Icon(color='blue',icon='none')).add_to(m5)
                f1.add_to(m5) 
                folium.LayerControl().add_to(m5)
                m5.save('templates/map.html')
                flash('Tidak ditemukan jalan menuju lokasi tujuan')
                return render_template('GoogleMaps.html',comp_select = str(pilihankota))
            else:
                for i in range(len(path)-1):
                    listJalan.append([listCoor[path[i]],listCoor[path[i+1]]])
                    
                fig5=Figure(height=550,width=750)
                middle = main.middlePoint(listCoor)
                m5=folium.Map(location=[middle[0],middle[1]],tiles='cartodbpositron',zoom_start=17)
                fig5.add_child(m5)
                f1=folium.FeatureGroup("Jalan Asli")
                for i in range(len(listCoor)-1):
                    for j in range(i+1, len(listCoor)):
                        if (adjMatrix[i][j] != 0):
                            place1 = [[listCoor[i][0],listCoor[i][1]],[listCoor[j][0],listCoor[j][1]]]
                            line_1=folium.vector_layers.PolyLine(place1,color='red',weight=10).add_to(f1)
                
                
                
                jarakpath = "Jaraknya " + str(main.hitungJarakPath(adjMatrix,path,listCoor)) + " meter"
                for i in range(len(listJalan)):
                    line_1=folium.vector_layers.PolyLine(listJalan[i],popup=jarakpath,tooltip=jarakpath,color='blue',weight=10).add_to(f1)
                
                #bikin node
                for i in range(len(listCoor)):
                    folium.Marker(listCoor[i],popup=listNode[i],tooltip='<strong>Click here to see Popup</strong>',icon=folium.Icon(color='blue',icon='none')).add_to(m5)
                
                for i in range(len(path)):
                    folium.Marker(listCoor[path[i]],popup=listNode[path[i]],tooltip='<strong>Click here to see Popup</strong>',icon=folium.Icon(color='green',icon='none')).add_to(m5)
                
                f1.add_to(m5) 
                folium.LayerControl().add_to(m5)
                m5.save('templates/map.html')

    #kalau sampai sini aman
    #bisa mulai gambar

    #untuk ngecek apakah node i dan j dihubungkan 1 sisi atau gak -> cek adjMatrix[i][j] jika isinya 0 berarti gak berhubungan
    #untuk cek coordinat simpul ke i dari listNode tinggal pilih listCoor[i] (isinya tuple, yang pertama lat kedua long)
    #harusnya bisa lah ya kan alam gitu lho hehe
    
    #ini buat nampilin pake panah2 gitu jadi maneh gk usah liat
    #nah kalau mau hitung jaraknya bisa pake ini hitungJarakPath, jaraknya dalam meter
    
    return render_template('GoogleMaps.html')
Ejemplo n.º 7
0
import folium
from branca.element import Figure
m = folium.Map(location=[23.76327225, 90.3598240238032],
               tiles='cartodbpositron',
               zoom_start=11)
m1 = folium.Map(location=[28.644800, 77.216721],
                tiles='cartodbpositron',
                zoom_start=14)
fig = Figure(width=550, height=350)
fig1 = Figure(height=550, width=750)
fig.add_child(m)
fig1.add_child(m1)
folium.Marker(location=[23.76327225, 90.3598240238032],
              popup='Current',
              tooltip='<strong>Current</strong>',
              icon=folium.Icon(color='red', icon='none')).add_to(m)
folium.Marker(location=[22.5726, 88.3639],
              popup='Destination',
              tooltip='<strong>Destination</strong>',
              icon=folium.Icon(color='green', prefix='glyphicon',
                               icon='off')).add_to(m)
m.save("user2destination.html")
coords_1 = [[28.65685, 77.21899], [28.65699, 77.21898], [28.65699, 77.21898],
            [28.65702, 77.21875], [28.65702, 77.21875], [28.6547, 77.21902],
            [28.65308, 77.21921], [28.65286, 77.21926], [28.65255, 77.21938],
            [28.65227, 77.21954], [28.65152, 77.22005], [28.64655, 77.22346],
            [28.64643, 77.22354], [28.64635, 77.22357], [28.64623, 77.2236],
            [28.64616, 77.22363], [28.64612, 77.22364], [28.64557, 77.22364],
            [28.64525, 77.22365], [28.64525, 77.22365], [28.64517, 77.22366],
            [28.64515, 77.22367], [28.64512, 77.22367], [28.64504, 77.22369],
            [28.64493, 77.22371], [28.64483, 77.22373], [28.64462, 77.22377],
def make_choropleth_map(df,
                        plot_col,
                        popup_dict,
                        tooltip_dict,
                        colorscale,
                        fig_width,
                        fig_height,
                        zoom=6,
                        centroid=[36.2, -119.1]):
    fig = Figure(width=fig_width, height=fig_height)

    m = folium.Map(location=centroid,
                   tiles='cartodbpositron',
                   zoom_start=zoom,
                   width=fig_width,
                   height=fig_height)

    popup = GeoJsonPopup(
        fields=list(popup_dict.keys()),
        aliases=list(popup_dict.values()),
        localize=True,
        labels=True,
        style=f"background-color: light_gray;",
        max_width=100,
    )

    tooltip = GeoJsonTooltip(
        fields=list(tooltip_dict.keys()),
        aliases=list(tooltip_dict.values()),
        # localize = True sets the commas for numbers, but zipcode should be displayed as string
        #localize=True,
        sticky=False,
        labels=True,
        style=f"""
            background-color: "gray";
            border: 0px #FFFFFF;
            border-radius: 0px;
            box-shadow: 0px;
            font-size: 12px;
        """,
        max_width=300,
    )

    #https://medium.com/analytics-vidhya/create-and-visualize-choropleth-map-with-folium-269d3fd12fa0
    g = folium.GeoJson(
        df,
        style_function=lambda x: {
            "fillColor":
            colorscale(x["properties"][plot_col])
            if x["properties"][plot_col] is not None else f"gray",
            "color":
            "#FFFFFF",
            "fillOpacity":
            0.8,
            "weight":
            0.2,
        },
        tooltip=tooltip,
        popup=popup,
    ).add_to(m)

    fig.add_child(m)

    return fig
Ejemplo n.º 9
0
    def return_map(self,mypandas,which_data = None,width_height = None, date = 'last'):
        """Create a Folium map from a pandas input

        Keyword arguments
        -----------------
        babepandas : pandas consided
        which_data: variable from pandas data. If pandas is produced from cocoa get_stat method
        then 'diff' and 'cumul' can be also used
        width_height : as a list of width and height of the histo, default [500,400]
        date : - default 'last'
               Value at the last date (from database point of view) and for all the location defined in
               the pandas will be computed
               - date
               Value at date (from database point of view) and for all the location defined in the pandas
               will be computed
        """

        if width_height:
            plot_width  = width_height[0]
            plot_height = width_height[1]
        else :
            plot_width  = width_height_default[0]
            plot_height = width_height_default[1]
        label , what ='',''
        if type(which_data) is None.__class__:
            which_data = mypandas.columns[2]
            label = which_data
        else:
            which_data = which_data
            if which_data == 'diff':
               what = 'day to day diffence'
            else:
               what = 'cumulative sum'
            label = mypandas.columns[2] + ' (' + what +  ')'

        if date == "last" :
           when = mypandas['date'].max()
        else:
           when = date

        jhu_stuff = mypandas.loc[(mypandas.date == when)]

        a = self.info.add_field(field=['geometry'],input=jhu_stuff ,geofield='location')

        data=gpd.GeoDataFrame(self.info.add_field(input=a,geofield='location',\
                                  field=['country_name']),crs="EPSG:4326")
        data = data.loc[data.geometry != None]
        data['geoid'] = data.index.astype(str)

        data=data[['geoid','location',which_data,'geometry']]
        data[which_data] = round(data[which_data])
        data = data.set_index('geoid')

        centroid=unary_union(data.geometry).centroid
        min_col,max_col=CocoDisplay.min_max_range(0,max(data[which_data]))
        colormap = branca.colormap.linear.RdPu_09.scale(min_col,max_col)
        #colormap = (colormap.to_step(n=len(data[which_data]),method='log'))
        colormap.caption = 'Covid-19 cases : ' + label
        fig = Figure(width=plot_width, height=plot_height)
        mapa = folium.Map(location=[centroid.y, centroid.x], zoom_start=2)
        #tiles='https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}.png',
        #attr = "IGN")
        fig.add_child(mapa)
        folium.GeoJson(
            data,
            style_function=lambda x:
            {
                #'fillColor': '#ffffffff' if x['properties'][which_data] < max(data[which_data]/1000.) else
                'fillColor':colormap(x['properties'][which_data]),
                'fillOpacity': 0.8,
                'color' : None,
            },
            name="Cases",
            highlight_function=lambda x: {'weight':2, 'color':'green'},
            tooltip=folium.GeoJsonTooltip(fields=['location',which_data],
                                              aliases = ['country','totcases'],
                                              labels=False),


        ).add_to(mapa)
        colormap.add_to(mapa)
        #folium.LayerControl(autoZIndex=False, collapsed=False).add_to(mapa)
        return mapa
Ejemplo n.º 10
0
#%%

points = [{
    'name': stationsInfo[ID]['name'],
    'coords': (stationsInfo[ID]['lat'], stationsInfo[ID]['lon']),
    'country': stationsInfo[ID]['country']
} for ID in stationsInfo.keys() & paramsInfo['stations']]

centroid = (52.23, 17.01)  # lat / lon

#%%
fig = Figure(width='80%', height='80%')

basemap = folium.Map(location=centroid, control_scale=True, zoom_start=5)

fig.add_child(basemap)
folium.TileLayer('cartodbpositron').add_to(basemap)
folium.TileLayer('Stamen Toner').add_to(basemap)
folium.TileLayer('Stamen Terrain').add_to(basemap)

icosGroup = folium.FeatureGroup(name="ICOS").add_to(basemap)

for point in points:
    icon = folium.Icon(
        color='white',
        icon='train',
        icon_color='red',
        prefix='fa'  # font awesome lib
    )

    popup = folium.Popup(f"""station: {point['name']} <br>
Ejemplo n.º 11
0
from branca.element import Figure

#create a title on web
st.markdown(
    "<h1 style='text-align: center; color: black;'>ASTROANALYZER </h1>",
    unsafe_allow_html=True)

#create a base map
fig3 = Figure(width=550, height=350)
m3 = folium.Map(
    location=[-8.907970, 33.433200],
    zoom_start=2,
    tiles=
    'https://api.mapbox.com/v4/mapbox.mapbox-incidents-v1/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoiZS1rIiwiYSI6ImNrbWwycnY1aTA5OXQycXJ6b3piZmRjdjAifQ.4sci1n22WrZvWaQL_99mrA',
    attr='Mapbox')
fig3.add_child(m3)

st.sidebar.title('Map Legend:')
st.sidebar.header('High Mass Binaries - Red')
st.sidebar.header('Low Mass Binaries - Blue')
st.sidebar.write('')
st.sidebar.title('Radius for plotted dots:')

#radius for plotted points
r = st.sidebar.slider(label='Slide this-', min_value=1, max_value=15, value=5)

#reading catalog B csv file
f1 = pd.read_csv('catalog_B.csv')
#making the list of all columns in catalog B
f1_ra = list(f1['RA'])
f1_dec = list(f1['Dec'])