Example #1
0
    def generateMap(self,
                    builds=None,
                    rivers=None,
                    roi=None,
                    poly_rivers=None,
                    superpixels=None,
                    bounding=None):

        self.generateMap2(builds, rivers, roi, poly_rivers, superpixels,
                          bounding)
        _map = folium.Map(location=self._location,
                          width=875,
                          height=660,
                          zoom_start=self._zoom,
                          attr='Ocupación en zonas de ronda hídrica',
                          max_zoom=18,
                          min_zoom=10)
        FloatImage(IMAGE, bottom=81, left=1).add_to(_map)
        FloatImage(IMAGE2, bottom=95, left=12).add_to(_map)
        FloatImage(IMAGE2, bottom=12, left=12).add_to(_map)
        _map.add_tile_layer(self._url,
                            name='Satelital',
                            attr='Ocupación en zonas de ronda hídrica',
                            max_zoom=17,
                            min_zoom=10)
        _map.add_child(folium.LatLngPopup())

        if builds is not None:
            gjson = builds.to_json()
            lay_builds = folium.FeatureGroup(
                name='Construcciones dentro de ronda hidrica')
            lay_builds.add_child(
                folium.GeoJson(data=gjson,
                               style_function=lambda x: {
                                   'color': '#000000',
                                   'weight': 0.15,
                                   'fillColor': '#F08615',
                                   'fillOpacity': 1.0
                               }))
            _map.add_child(lay_builds)

        if superpixels is not None:
            gjson = superpixels.to_json()
            lay_sp = folium.FeatureGroup(
                name='Regiones dentro de ronda hidrica')
            lay_sp.add_child(
                folium.GeoJson(data=gjson,
                               style_function=lambda x: {
                                   'color': '#F08615',
                                   'weight': 2,
                                   'fillColor': '#3DCF58',
                                   'fillOpacity': 0.1
                               }))
            _map.add_child(lay_sp)

        if rivers is not None:
            gjson = rivers.to_json()
            lay_rivers = folium.FeatureGroup(name='Rios')
            lay_rivers.add_child(
                folium.GeoJson(data=gjson,
                               style_function=lambda x: {
                                   'color': '#0083E9',
                                   'opacity': 0.8,
                                   'fillColor': '#0083E9',
                                   'fillOpacity': 1,
                                   'width': 0.1
                               }))
            if poly_rivers is not None:
                gjson = poly_rivers.to_json()
                lay_rivers.add_child(
                    folium.GeoJson(data=gjson,
                                   style_function=lambda x: {
                                       'color': '#0083E9',
                                       'opacity': 0.8,
                                       'fillColor': '#0083E9',
                                       'fillOpacity': 1,
                                       'width': 0.1
                                   }))
            _map.add_child(lay_rivers)

        if roi is not None:
            gjson = roi.to_json()
            lay_susceptibilidad = folium.FeatureGroup(name="Ronda Hidrica")
            lay_susceptibilidad.add_child(
                folium.GeoJson(data=gjson,
                               style_function=lambda x: {
                                   'color': '#B70015',
                                   'opacity': 0.2,
                                   'fillColor': '#B70015',
                                   'fillOpacity': 0.3,
                                   'width': 0.1
                               }))
            _map.add_child(lay_susceptibilidad)

        if bounding is not None:
            lat2, lon1, lat1, lon2 = bounding
            points = [(lat1, lon1), (lat1, lon2), (lat2, lon2), (lat2, lon1),
                      (lat1, lon1)]
            folium.PolyLine(points,
                            weight=1.5,
                            opacity=0.5,
                            dashArray=[20, 20],
                            dashOffset=20).add_to(_map)

        _map.add_child(folium.LayerControl())

        _map.save('temp1.html')

        return _map
        if '2015' in dt:
            iframe = folium.IFrame(html=html %
                                   (nm, nm, dt, rc, arm, tl, flee, bc, mod),
                                   width=200,
                                   height=100)
            fg15.add_child(
                folium.CircleMarker(location=[
                    offset_location_lat(lt),
                    offset_location_lon(ln)
                ],
                                    popup=folium.Popup(iframe),
                                    radius=5,
                                    fill_color=fill_color_selector(rc),
                                    fill_opacity=.8,
                                    color=color_icon(arm),
                                    opacity=1).add_to(cluster))
"""
Add all icons from the following feature groups to map
"""
map.add_child(fg20)
map.add_child(fg19)
map.add_child(fg18)
map.add_child(fg17)
map.add_child(fg16)
map.add_child(fg15)
FloatImage(legend_file, bottom=0, left=0).add_to(map)
cluster.add_to(map)
map.add_child(folium.LayerControl())

map.save('map2.html')
Example #3
0
def mapper(data, lon, lat, type, output, indicator):
    # Create base map
    m = folium.Map(location=[data['lat'].mean(), data['lon'].mean()])

    # generical layer
    g = folium.FeatureGroup(name='Generical', overlay=True, show=True)

    # detailed layer
    d = folium.FeatureGroup(name='Detailed', overlay=True, show=False)

    mc = MarkerCluster()

    # add reference point to both layers. Reference point refers to the place where light pollution measurements was taken
    g.add_child(folium.Marker(location=(lat, lon), popup='Reference point', icon=folium.Icon(color='black')))
    d.add_child(folium.Marker(location=(lat, lon), popup='Reference point', icon=folium.Icon(color='black')))

    # Process all places and place them into both layers of the map.
    # Marker colors: blue-Municipio, red-Fábricas, orange-CentroComercial, purple-Minas, green-Invernadero, black-reference
    for index, row in data.iterrows():
        name = row['Nombre']
        type = row['Tipo']
        population = row['Poblacion']
        distance = row['Distancia']
        if type == 'tas':
            cloudiness = row['Nubosidad']
        else:
            cloudiness = "-"
        coordinates = str(row['lat']) + ", " + str(row['lon'])

        if type == 'Municipio':
            population = int(population)
            d.add_child(folium.Marker(location=(float(row['lat']), float(row['lon'])),
                          popup='<b>Nombre: </b>%s<br></br><b>Tipo: </b>%s<br></br><b>Población: '
                                '</b>%s<br></br><b>Distancia: </b>%s km<br></br><b>Nubosidad: '
                                '</b>%s<br></br><b>Coordenadas: </b>%s' % (name, type, population, distance,
                                                                           cloudiness, coordinates),
                          icon=folium.Icon(color='blue')))
            mc.add_child(
                folium.Marker(location=(float(row['lat']), float(row['lon'])),
                              popup='<b>Nombre: </b>%s<br></br><b>Tipo: </b>%s<br></br><b>Población: '
                                    '</b>%s<br></br><b>Distancia: </b>%s km<br></br><b>Nubosidad: '
                                    '</b>%s<br></br><b>Coordenadas: </b>%s' % (name, type, population, distance,
                                                                               cloudiness, coordinates),
                              icon=folium.Icon(color='blue'))
            )
        elif type == 'Fábricas':
            d.add_child(folium.Marker(location=(float(row['lat']), float(row['lon'])),
                          popup='<b>Nombre: </b>%s<br></br><b>Tipo: </b>%s<br></br><b>Distancia: '
                                '</b>%s km<br></br><b>Nubosidad: </b>%s<br></br><b>Coordenadas: </b>%s' % (name, type,
                                                                                                        distance,
                                                                                                        cloudiness,
                                                                                                        coordinates),
                          icon=folium.Icon(color='red')))
            mc.add_child(
                folium.Marker(location=(float(row['lat']), float(row['lon'])),
                              popup='<b>Nombre: </b>%s<br></br><b>Tipo: </b>%s<br></br><b>Distancia: '
                                    '</b>%s km<br></br><b>Nubosidad: </b>%s<br></br><b>Coordenadas: </b>%s' % (
                                    name, type,
                                    distance,
                                    cloudiness,
                                    coordinates),
                              icon=folium.Icon(color='red'))
            )
        elif type == 'Centro Comercial':
            d.add_child(folium.Marker(location=(float(row['lat']), float(row['lon'])),
                          popup='<b>Nombre: </b>%s<br></br><b>Tipo: </b>%s<br></br><b>Distancia: '
                                '</b>%s km<br></br><b>Nubosidad: </b>%s<br></br><b>Coordenadas: </b>%s' % (name, type,
                                                                                                        distance,
                                                                                                        cloudiness,
                                                                                                        coordinates),
                          icon=folium.Icon(color='orange')))
            mc.add_child(
                folium.Marker(location=(float(row['lat']), float(row['lon'])),
                              popup='<b>Nombre: </b>%s<br></br><b>Tipo: </b>%s<br></br><b>Distancia: '
                                    '</b>%s km<br></br><b>Nubosidad: </b>%s<br></br><b>Coordenadas: </b>%s' % (
                                    name, type,
                                    distance,
                                    cloudiness,
                                    coordinates),
                              icon=folium.Icon(color='orange'))
            )
        elif type == 'Minas':
            d.add_child(folium.Marker(location=(float(row['lat']), float(row['lon'])),
                          popup='<b>Nombre: </b>%s<br></br><b>Tipo: </b>%s<br></br><b>Distancia: '
                                '</b>%s km<br></br><b>Nubosidad: </b>%s<br></br><b>Coordenadas: </b>%s' % (name, type,
                                                                                                        distance,
                                                                                                        cloudiness,
                                                                                                        coordinates),
                          icon=folium.Icon(color='purple')))
            mc.add_child(
                folium.Marker(location=(float(row['lat']), float(row['lon'])),
                              popup='<b>Nombre: </b>%s<br></br><b>Tipo: </b>%s<br></br><b>Distancia: '
                                    '</b>%s km<br></br><b>Nubosidad: </b>%s<br></br><b>Coordenadas: </b>%s' % (
                                    name, type,
                                    distance,
                                    cloudiness,
                                    coordinates),
                              icon=folium.Icon(color='purple'))
            )
        elif type == 'Invernadero':
            d.add_child(folium.Marker(location=(float(row['lat']), float(row['lon'])),
                          popup='<b>Nombre: </b>%s<br></br><b>Tipo: </b>%s<br></br><b>Distancia: '
                                '</b>%s km<br></br><b>Nubosidad: </b>%s<br></br><b>Coordenadas: </b>%s' % (name, type,
                                                                                                        distance,
                                                                                                        cloudiness,
                                                                                                        coordinates),
                          icon=folium.Icon(color='green')))
            mc.add_child(
                folium.Marker(location=(float(row['lat']), float(row['lon'])),
                              popup='<b>Nombre: </b>%s<br></br><b>Tipo: </b>%s<br></br><b>Distancia: '
                                    '</b>%s km<br></br><b>Nubosidad: </b>%s<br></br><b>Coordenadas: </b>%s' % (
                                    name, type,
                                    distance,
                                    cloudiness,
                                    coordinates),
                              icon=folium.Icon(color='green'))
            )

    # add the MarkerCluster to generical layer
    g.add_child(mc)

    # add the generical layer to Map
    m.add_child(g)

    # add the detailed layer to Map
    m.add_child(d)

    # add indicator image to map if was set
    if indicator is not None:
        img = Image.open(indicator)
        img.putalpha(166)
        size = 250, 250
        img.thumbnail(size, Image.ANTIALIAS)
        img.save(output + '_indicator.png')
        m.add_child(FloatImage(output + '_indicator.png', bottom=3, left=3))

    # add layer control functionality
    m.add_child(LayerControl())

    # automatic map bounds setting
    m.fit_bounds(g.get_bounds())

    # save map to "map.html"
    m.save(output + "_map.html")

    print("Map saved in: " + output + "_map.html")
Example #4
0
                folium.Marker(location=(marshal_lat,marshal_long),icon=folium.Icon(color='blue', icon='male', prefix="fa"), popup="Marshal {0}<br>{1} , {2}".format(x-1,round(marshal_lat,6),round(marshal_long,6))).add_to(marshals_feature_group)
                
                folium.features.Circle(location=(marshal_lat,marshal_long),radius=distance_to_marshal_allowed, weight=1,color="gray", popup="allowed {0} meters from marshal {1}".format(distance_to_marshal_allowed,x-1),opacity=0.2).add_to(marshals_feature_group)

                OutputMarshal(x-1,marshal[0],marshal[1],distance_to_marshal_allowed)
                feature_group.add_to(my_map)

            os.remove("{1}/zzz_{0}.csv".format(file,cwd))
            if c < 15 :
                c = c + 1
            else:
                c = 0
                    
        marshals_feature_group.add_to(my_map)
        url = ('http://tnuatiming.com/android-chrome-36x36.png')
        FloatImage(url, bottom=2, left=96).add_to(my_map)
        # my_map.add_child(MeasureControl())
        # folium.LatLngPopup().add_to(my_map)
        my_map.add_child(folium.LayerControl())
        my_map.fit_bounds(my_map.get_bounds())
        with open("TrackingMap.html", "w"): pass # clear the txt file
        my_map.save("TrackingMap.html")
        print("a.ok")

    else:
        print('\nworong arguments, please use:\n\npython rally_marshal_folder.py marshal1_lat,marshal1_long marshal2_lat,marshal2_long \n\nEx: python rally_marshal_folder.py 45.48612,5.909551 45.49593,5.90369 45.50341,5.90479 45.51386,5.90625\n')
        sys.exit(0)

marshalfile.close()
'''
plt.xlabel('latitude')