Ejemplo n.º 1
0
def draw_mult_map(df_a, df_b):

    m = folium.Map(location=[df_a['lat'].mean(), df_b['long'].mean()],
                   zoom_start=15,
                   control_scale=True)

    feature_group_estaciones = folium.FeatureGroup(
        name='Estaciones de Bicicletas')
    feature_group_tiendas = folium.FeatureGroup(name='bicicleterias')

    marker_cluster_estaciones = MarkerCluster()
    marker_cluster_tiendas = MarkerCluster()

    for row in df_a.iterrows():
        marker_estaciones = folium.Marker(
            location=[row[1]['lat'], row[1]['long']],
            popup=str(row[1]['nro_est']) + '. ' + str(row[1]['nombre']),
            icon=folium.Icon(color='green'))
        marker_cluster_estaciones.add_child(marker_estaciones)

    for row in df_b.iterrows():
        marker_tiendas = folium.Marker(
            location=[row[1]['lat'], row[1]['long']],
            popup=row[1]['nombre'],
            icon=folium.Icon(color='red'))
        marker_cluster_tiendas.add_child(marker_tiendas)

    feature_group_estaciones.add_child(marker_cluster_estaciones)
    feature_group_tiendas.add_child(marker_cluster_tiendas)

    m.add_child(feature_group_estaciones)
    m.add_child(feature_group_tiendas)
    m.add_child(folium.LayerControl())

    #OPTIONAL PLUGGINS
    #minimaps
    minimap = MiniMap(toggle_display=True)
    m.add_child(minimap)

    #measure tool
    m.add_child(MeasureControl())
    #show de coordinates from cursor position
    MousePosition().add_to(m)

    #draw tools
    draw = Draw(export=True)
    draw.add_to(m)

    #full screen
    Fullscreen(position='topright',
               title='Expand me',
               title_cancel='Exit me',
               force_separate_button=True).add_to(m)
    return m
Ejemplo n.º 2
0
def gerarMapadePonto(listaDeCoordenadas, nomeDoMapa):

    mapa = folium.Map(location=[-8.05428, -34.8813], zoom_start=12)
    marker_cluster = MarkerCluster().add_to(mapa)
    draw = Draw()
    draw.add_to(mapa)

    if listaDeCoordenadas != None:
        for la, lo, rua, in zip(listaDeCoordenadas[0], listaDeCoordenadas[1],
                                listaDeCoordenadas[2]):
            folium.Marker(location=[la, lo],
                          popup=rua,
                          icon=folium.Icon(color='red')).add_to(marker_cluster)
    mapa.save('app/templates/' + nomeDoMapa + ".html")
Ejemplo n.º 3
0
def draw_map(df, cluster_marks=True):

    m = folium.Map(location=[df['lat'].mean(), df['long'].mean()],
                   zoom_start=15,
                   control_scale=True)

    if cluster_marks == True:

        mc = MarkerCluster()

        for row in df.iterrows():
            mc.add_child(
                folium.Marker(location=[row[1]['lat'], row[1]['long']],
                              popup=row[1]['nombre']))
        m.add_child(mc)
    else:
        for row in df.iterrows():
            folium.Marker(location=[row[1]['lat'], row[1]['long']],
                          popup=row[1]['nombre']).add_to(m)

    #OPTIONAL PLUGGINS
    #minimaps
    minimap = MiniMap(toggle_display=True)
    m.add_child(minimap)

    #measure tool
    m.add_child(MeasureControl())
    #show de coordinates from cursor position
    MousePosition().add_to(m)

    #draw tools
    draw = Draw(export=True)
    draw.add_to(m)

    #full screen
    Fullscreen(position='topright',
               title='Expand me',
               title_cancel='Exit me',
               force_separate_button=True).add_to(m)

    return m
Ejemplo n.º 4
0
# coding: utf-8

# In[1]:


import folium
import MySQLdb
db = MySQLdb.connect("localhost","root","","folium" )
from folium.plugins import Draw, Fullscreen
cursor = db.cursor()
m = folium.Map(location=[-27.228989, -48.36525], zoom_start=12)

draw = Draw(export=True)

draw.add_to(m)

m


# In[1]:


import os
import geopandas


gpd = geopandas.read_file(
    os.path.join(os.path.expanduser('~'), 'data.geojson')
)
poly_line = TimestampedGeoJson(data={
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "geometry": {
                "type": "LineString",
                "coordinates": coordinates,
            },
            "properties": {
                "times": time,
                "style": {
                    "color": "red",
                    "weight": 2
                }
            }
        }
    ]
}, period="PT1M")

poly_line.add_to(map)

# Create a tool to measure distance and area
tool_measure = MeasureControl()
tool_measure.add_to(map)

# Create tool to draw something
tool_draw = Draw()
tool_draw.add_to(map)
map.save("Munich_with_points_and_lines_.html")
Ejemplo n.º 6
0
	def createMapFile(self, Latitude, Longitude, ImgName, ImgDate, Zip):
		dlg = wx.DirDialog(self, "Select Photo Directory:")
		if dlg.ShowModal() == wx.ID_CANCEL:
			return     # the user changed their mind
		pathname = dlg.GetPath()
		self.botP.thumbnail.ShowDir(pathname + "/Thumbnails")
		coordsPopup = []
		coordsSearch = []
		points = []
		draw = Draw()
		
		mymap = folium.Map(location=[38.0, -97.0],zoom_start=5, attr=self.__attrStringMain)
		
		
		resolution, width, height = 75, 7, 3

		for j in range(0, len(Latitude)):
			coordsPopuptemp = [Latitude[j][0], Longitude[j][0]]# Popup needs (Lat, Long) format
			coordsSearchtemp = [Longitude[j][0], Latitude[j][0]] #Search function needs (Long, Lat) format
			coordsPopup.append(coordsPopuptemp)
			coordsSearch.append(coordsSearchtemp)
#----------------Used for Searching--------------------------------------------------------------------
		for x in range(0, len(coordsSearch)):

			point = Point(coordsSearch[x])
			
			my_feature=Feature(geometry=point, properties={"name": ImgName[x][0]})
			points.append(my_feature)
		feature_collection = FeatureCollection(points)

		glayer=folium.GeoJson(feature_collection, name='Search Layer', show=False).add_to(mymap)
		folium.plugins.Search(layer=glayer, search_label='name', search_zoom=20).add_to(mymap)
		
		
#------------------------------------------------------------------------------------------------------

		mc = MarkerCluster(name='Cluster Layer',overlay=True, control=True)
		for i in range(0, len(Zip)):
			self.c.execute(('SELECT Latitude from exifdata WHERE zip_id = {}').format(i+1))
			LatitudeCluster = self.c.fetchall()
			self.c.execute(('SELECT Longitude from exifdata WHERE zip_id = {}').format(i+1))
			LongitudeCluster = self.c.fetchall()
			self.c.execute(('SELECT name from exifdata WHERE zip_id = {}').format(i+1))
			ImgNameCluster = self.c.fetchall()
			self.c.execute(('SELECT date_time from exifdata WHERE zip_id = {}').format(i+1))
			ImgDateCluster = self.c.fetchall()


			
			for x in range(0, len(LatitudeCluster)):
				filename = os.path.join((pathname + "/Thumbnails"), ("T_" + ImgNameCluster[x][0]))
				encoded = base64.b64encode(open(filename, 'rb').read()).decode()
				htmlstr = '<div style="font-size: 10pt">{}</div><div style="font-size: 10pt">{}</div><div style="font-size: 10pt">{}</div>, <img src="data:image/jpeg;base64,{}", \
	    		width="128px" height="128px">'.format(ImgNameCluster[x][0],ImgDateCluster[x][0],str(coordsPopup[x]),encoded)
				html = folium.Html(htmlstr, script=True)
				iframe = folium.IFrame(htmlstr, width=(width*resolution)+20, height=(height*resolution)+20)
				Popup=folium.Popup(html, max_width=500)
				folium.Marker(location=[LatitudeCluster[x][0], LongitudeCluster[x][0]], popup=Popup).add_to(mc)
			
		
		
		rm.RoutingMachine().add_to(mymap)
		mymap.add_child(mc)
		
		folium.TileLayer(tiles='Mapbox Bright', attr=self.__attrStringGeneral).add_to(mymap)
		folium.TileLayer(tiles='Mapbox Control Room', attr=self.__attrStringGeneral).add_to(mymap)

		
		
		
		
		
		folium.LayerControl().add_to(mymap)
		draw.add_to(mymap)
		
	
		try:
			mymap.save(self.OnSaveAs())
		except FileNotFoundError:
			dlg = wx.MessageDialog(self, "Map Not Saved Correctly!", "Error!", wx.OK | wx.ICON_ERROR)
			dlg.ShowModal()
			dlg.Destroy()
Ejemplo n.º 7
0
                        }
                    {{this._parent.get_name()}}.on('click', latLngPop);
                    
                {% endmacro %}
                """)


locations = []
coordinates = {}

detroit = [42.3316, -83.0467]

folium_map = folium.Map(location=detroit, zoom_start=8)

draw = Draw()
draw.add_to(folium_map)

fmtr = "function(num) {return L.Util.formatNum(num, 3) + ' deg ';};"
mouse = plugins.MousePosition(position='topright',
                              separator=' ',
                              num_digits=10,
                              prefix="Current Location:",
                              lat_formatter=fmtr, lng_formatter=fmtr)
mouse.add_to(folium_map)


@app.route('/')
def index():
    folium_map.add_child(PopUp())

    map = folium_map._repr_html_()
Ejemplo n.º 8
0
def index():
    start_coords = (-15.79340,-47.88232)
    folium_map = folium.Map(location=start_coords, zoom_start=16)
    draw = Draw()
    draw.add_to(folium_map)
    folium_map.add_child(MeasureControl())
    tooltip = 'Click me!'
    folium.Marker(
    [-15.796218,-47.872002 ], 
    popup='<i>Estrada Parque Ceilândia, SIA</i>', 
    icon=folium.Icon(color='black',icon='car', prefix='fa'),
    tooltip=tooltip).add_to(folium_map)
    folium.Marker(
    [-15.791077,-47.875543], 
    popup='<b>QSB 12, Taguatinga, Região</b>', 
    icon=folium.Icon(color='black',icon='car', prefix='fa'),
    tooltip=tooltip).add_to(folium_map)
    folium.Marker(
    [-15.787711,-47.878397], 
    popup='<b>Bloco A / B, W1 Sul, SQS 104, Asa Sul</b>', 
    icon=folium.Icon(color='black',icon='car', prefix='fa'),
    tooltip=tooltip).add_to(folium_map)
    folium.Marker(
    [-15.790932,-47.879212], 
    popup='<b>Recanto das Emas, Região Integrada de Desenvol...</b>', 
    icon=folium.Icon(color='black',icon='car', prefix='fa'),
    tooltip=tooltip).add_to(folium_map)
    folium.Marker(
    [-15.793678,-47.880199], 
    popup='<b>Recanto das Emas, Região Integrada de Desenvol...</b>', 
    icon=folium.Icon(color='black',icon='car', prefix='fa'),
    tooltip=tooltip).add_to(folium_map)
    folium.Marker(
    [-15.79628,-47.885885], 
    popup='<b>Recanto das Emas, Região Integrada de Desenvol...</b>', 
    icon=folium.Icon(color='black',icon='car', prefix='fa'),
    tooltip=tooltip).add_to(folium_map)
    folium.Marker(
    [-15.789507,-47.883203], 
    popup='<b>Recanto das Emas, Região Integrada de Desenvol...</b>', 
    icon=folium.Icon(color='black',icon='car', prefix='fa'),
    tooltip=tooltip).add_to(folium_map)
    folium.Marker(
    [-47.887988,-47.887988], 
    popup='<b>Recanto das Emas, Região Integrada de Desenvol...</b>', 
    icon=folium.Icon(color='black',icon='car', prefix='fa'),
    tooltip=tooltip).add_to(folium_map)
    folium.Marker(
    [-15.79436,-47.887602], 
    popup='<b>Recanto das Emas, Região Integrada de Desenvol...</b>', 
    icon=folium.Icon(color='black',icon='car', prefix='fa'),
    tooltip=tooltip).add_to(folium_map)
    folium.Marker(
    [-15.788743,-47.889705], 
    popup='<b>Recanto das Emas, Região Integrada de Desenvol...</b>', 
    icon=folium.Icon(color='black',icon='car', prefix='fa'),
    tooltip=tooltip).add_to(folium_map)
    folium.Marker(
    [-15.788826,-47.89346], 
    popup='<b>Recanto das Emas, Região Integrada de Desenvol...</b>', 
    icon=folium.Icon(color='black',icon='car', prefix='fa'),
    tooltip=tooltip).add_to(folium_map)
    formatter = "function(num) {return L.Util.formatNum(num, 3) + ' º ';};"
    MousePosition(
    position='topright',
    separator=' | ',
    empty_string='NaN',
    lng_first=True,
    num_digits=20,
    prefix='Coordinates:',
    lat_formatter=formatter,
    lng_formatter=formatter,
    ).add_to(folium_map)
    return folium_map._repr_html_()
Ejemplo n.º 9
0
    def mapping(self, start, end, dis, arg):
        gmaps = googlemaps.Client(
            key='AIzaSyBjcH8wXlR_EZAIm8k8XFHgkJ6cOlEtpvM')
        now = datetime.now()

        directions_result = gmaps.directions(start,
                                             end,
                                             mode="driving",
                                             departure_time=now)

        DirectionResult = directions_result[0]['legs']
        DirectionSteps = DirectionResult[0]['steps']
        DecodedNp = np.zeros(shape=[1, 2])

        for step in DirectionSteps:
            Temp = list(step['polyline'].values())
            DecodedNp = np.concatenate(
                (DecodedNp, np.array(polyline.decode(Temp[0]))))

        DecodedPos = DecodedNp.tolist()

        m = folium.Map(location=DecodedPos[1],
                       zoom_start=5,
                       tiles="Stamen Toner")

        draw = Draw()
        draw.add_to(m)

        #folium.TileLayer('Mapbox Control Room').add_to(m) # 여러가지 타일들 "Mapbox Bright"
        #folium.TileLayer('Stamen Toner').add_to(m)
        #folium.TileLayer('openstreetmap').add_to(m)
        #folium.LayerControl().add_to(m) # 빠른 마커로딩과 동시에 안됨
        convert_dis = dis
        try:
            convert_dis = float(convert_dis)
        except ValueError:
            pass

        if arg == 1:
            if convert_dis * 1000 < DirectionResult[0]['distance']['value']:
                folium.Circle(location=DecodedPos[1],
                              popup='Available distance',
                              radius=convert_dis * 1000,
                              color='#8AC317',
                              fill=True,
                              fill_color='#BBFF33').add_to(m)  #기본 길이단위 미터

            ShortestPolyline = folium.PolyLine(locations=[DecodedPos[1:]],
                                               color='red',
                                               weight=5).add_to(m)
            attr = {
                'fill': '#421100',
                'font-weight': 'bold',
                'font-size': '48'
            }
            folium.plugins.PolyLineTextPath(ShortestPolyline,
                                            text='\u00BB    ',
                                            repeat=True,
                                            center=True,
                                            offset=16,
                                            attributes=attr).add_to(
                                                m)  # 색깔 그림 폰트 등등 라인꾸미기

            self.progressBar.setValue(50)

        elif arg == 2:
            folium.Circle(location=DecodedPos[1],
                          popup='Available distance',
                          radius=convert_dis * 1000,
                          color='#8AC317',
                          fill=True,
                          fill_color='#BBFF33').add_to(m)  #기본 길이단위 미터

            self.progressBar.setValue(0)
            EV_data = self.EV_Discovery()
            Availiable_ChargerLocList = []
            for i in range(len(EV_data)):
                Charger_distance = self.Distance(DecodedPos[1][0],
                                                 DecodedPos[1][1],
                                                 EV_data[i][0], EV_data[i][1])
                if Charger_distance < convert_dis:
                    Availiable_ChargerLocList.append(EV_data[i])
            folium.plugins.FastMarkerCluster(Availiable_ChargerLocList).add_to(
                m)
            if len(Availiable_ChargerLocList) == 0:
                self.textBrowser.append("There are no availiable charger")
                self.progressBar.setValue(100)
        elif arg == 3:
            folium.Circle(location=DecodedPos[1],
                          popup='Available distance',
                          radius=convert_dis * 1000,
                          color='#8AC317',
                          fill=True,
                          fill_color='#BBFF33').add_to(m)  #기본 길이단위 미터

            self.progressBar.setValue(0)
            EV_data = self.EV_Discovery()
            Availiable_ChargerLocList = []
            for i in range(len(EV_data)):
                Charger_distance = self.Distance(DecodedPos[1][0],
                                                 DecodedPos[1][1],
                                                 EV_data[i][0], EV_data[i][1])

                if Charger_distance < convert_dis:
                    Availiable_ChargerLocList.append(EV_data[i])
            print(len(Availiable_ChargerLocList))
            if len(Availiable_ChargerLocList) == 0:
                if convert_dis * 1000 < DirectionResult[0]['distance']['value']:
                    folium.Circle(location=DecodedPos[1],
                                  popup='Available distance',
                                  radius=convert_dis * 1000,
                                  color='#8AC317',
                                  fill=True,
                                  fill_color='#BBFF33').add_to(m)  #기본 길이단위 미터

                ShortestPolyline = folium.PolyLine(locations=[DecodedPos[1:]],
                                                   color='red',
                                                   weight=5).add_to(m)
                attr = {
                    'fill': '#421100',
                    'font-weight': 'bold',
                    'font-size': '48'
                }
                folium.plugins.PolyLineTextPath(ShortestPolyline,
                                                text='\u00BB    ',
                                                repeat=True,
                                                center=True,
                                                offset=16,
                                                attributes=attr).add_to(
                                                    m)  # 색깔 그림 폰트 등등 라인꾸미기

                self.progressBar.setValue(50)

                self.textBrowser.append("There are no availiable charger")

            else:
                self.progressBar.setValue(70)
                #Find Efficient Electric Charger location
                min_Dist = 10000000000  # Initial min value
                Efficient_ElecChargLoc = []
                for i in range(len(Availiable_ChargerLocList)):
                    Dist1 = self.Distance(DecodedPos[1][0], DecodedPos[1][1],
                                          Availiable_ChargerLocList[i][0],
                                          Availiable_ChargerLocList[i][1])
                    Dist2 = self.Distance(DecodedPos[-1][0], DecodedPos[-1][1],
                                          Availiable_ChargerLocList[i][0],
                                          Availiable_ChargerLocList[i][1])
                    if (Dist1 + Dist2 < min_Dist):
                        min_Dist = Dist1 + Dist2
                        Efficient_ElecChargLoc = [
                            Availiable_ChargerLocList[i][0],
                            Availiable_ChargerLocList[i][1]
                        ]
                print(Efficient_ElecChargLoc)
                self.progressBar.setValue(80)
                folium.Marker(Efficient_ElecChargLoc,
                              popup='Recommended Electric Charger',
                              icon=folium.Icon(color='green')).add_to(m)

                reverse_geocode_result = gmaps.reverse_geocode(
                    Efficient_ElecChargLoc)
                ElecLocStr = reverse_geocode_result[0]['formatted_address']

                #Start to Electric charger
                directions_result = gmaps.directions(start,
                                                     ElecLocStr,
                                                     mode="driving",
                                                     departure_time=now)
                DirectionResult = directions_result[0]['legs']
                DirectionSteps = DirectionResult[0]['steps']
                DecodedNp = np.zeros(shape=[1, 2])
                for step in DirectionSteps:
                    Temp = list(step['polyline'].values())
                    DecodedNp = np.concatenate(
                        (DecodedNp, np.array(polyline.decode(Temp[0]))))
                DecodedPos = DecodedNp.tolist()
                StartToElecCharg = folium.PolyLine(locations=[DecodedPos[1:]],
                                                   color='green',
                                                   weight=5).add_to(m)
                attr = {
                    'fill': '#421100',
                    'font-weight': 'bold',
                    'font-size': '48'
                }
                folium.plugins.PolyLineTextPath(StartToElecCharg,
                                                text='\u00BB    ',
                                                repeat=True,
                                                center=True,
                                                offset=16,
                                                attributes=attr).add_to(
                                                    m)  # Color, font

                #Electric charger to end
                directions_result = gmaps.directions(ElecLocStr,
                                                     end,
                                                     mode="driving",
                                                     departure_time=now)
                DirectionResult = directions_result[0]['legs']
                DirectionSteps = DirectionResult[0]['steps']
                DecodedNp = np.zeros(shape=[1, 2])
                for step in DirectionSteps:
                    Temp = list(step['polyline'].values())
                    DecodedNp = np.concatenate(
                        (DecodedNp, np.array(polyline.decode(Temp[0]))))
                DecodedPos = DecodedNp.tolist()
                ElecChargToEnd = folium.PolyLine(locations=[DecodedPos[1:]],
                                                 color='green',
                                                 weight=5).add_to(m)
                attr = {
                    'fill': '#421100',
                    'font-weight': 'bold',
                    'font-size': '48'
                }
                folium.plugins.PolyLineTextPath(ElecChargToEnd,
                                                text='\u00BB    ',
                                                repeat=True,
                                                center=True,
                                                offset=16,
                                                attributes=attr).add_to(
                                                    m)  # 색깔 그림 폰트 등등 라인꾸미기
                '''
                marker_cluster = folium.plugins.MarkerCluster(
                locations=data, popups=['lon:{}<br>lat:{}'.format(lon, lat) for (lat, lon) in data],
                name='EVcharger',overlay=True,control=False,icon_create_function=None)
                marker_cluster.add_to(m)# 
                '''

#        self.progressBar.setValue(70)
        m.save('temp\RoutePlanner.html')