Les fichiers enceintes-de-poste-rte.geojson et lignes-aeriennes-rte-nv.geojson ont été récupérés sur Odré ou RTE je ne sais plus exactement. Il y a d'autres formats (kml ? pour googlemaps) .
Folium génère un fichier .html qui grâce à une bibliothèque en Javascript est capable de charger un fond de carte et d'ajouter des couches. C'est pour celà qu'à la fin du code on appelle un navigateur, ici Opéra, pour afficher la carte.
On trouve aussi en opendata des fichiers de la consommation et de la production d'électricité, je les ai utilisé pour les graphiques qui illustrent mon cours.
Et sur un tout autre sujet (le covid19) j'ai un programme qui récupère les données sur geodes.gouv.fr pour tracer le nombre de cas depuis le début, j'avais fait du "reverse engineering" des requêtes de leur sites pour récupérer les données
PS: avant d'être professeur de PC, j'ai été analyste programmeur quelques années et j'en ai gardé des séquelles
- Code: Tout sélectionner
import folium
import webbrowser
m = folium.Map(location=[46.958, 3.13645], zoom_start=6,tiles= 'OpenStreetMap',control_scale=True )
field_locations = 'enceintes-de-poste-rte.geojson'
def printNode( x ):
vmax = x['properties']['tension_maximale']
#print( vmax )
if vmax == "400kV":
return {'fillColor': '#FF0000', 'color': '#FF0000' , 'weight':7}
if vmax == "225kV":
return {'fillColor': '#0000FF', 'color': '#0000FF' , 'weight':7}
if vmax == "90kV":
return {'fillColor': '#00F000', 'color': '#00F000' , 'weight':7}
if vmax == "63kV":
return {'fillColor': '#00A000', 'color': '#00A000' , 'weight':7}
if vmax == "45kV":
return {'fillColor': '#000000', 'color': '#000000' , 'weight':7}
return{ 'opacity':0 }
folium.GeoJson(field_locations, style_function=lambda x: printNode(x)).add_to(m)
lignes_locations = 'lignes-aeriennes-rte-nv.geojson'
def getStyle( x ):
t = x['properties']['tension']
if t == "400kV":
return {'fillColor': '#FF0000', 'color': '#FF0000' , 'opacity':1}
if t == "225kV":
return {'fillColor': '#0000FF', 'color': '#0000FF', 'opacity':1 }
if t == "90kV":
return {'fillColor': '#00F000', 'color': '#00F000', 'opacity':1 }
if t == "63kV" :
return {'fillColor': '#00A000', 'color': '#00A000', 'opacity':1 }
if t == "45kV" :
return {'fillColor': '#000000', 'color': '#000000', 'opacity':1 }
return {'opacity':0 }
folium.GeoJson(lignes_locations , style_function=lambda x:getStyle(x) ).add_to(m)
title_html = '''
<h3 align="center" style="font-size:16px"><b>Lignes <u>aériennes</u> haute tension et points de distribution <br>
<span style="color:#FF0000"> 400kV</span>, <span style="color:#0000FF"> 225kV</span>, <span style="color:#00F000"> 90kV</span>
<span style="color:#00A000"> 63kV</span> et <span style="color:#000000"> 45kV</span></b>
</h3>
'''
m.get_root().html.add_child(folium.Element(title_html))
m.save("reseau_tht.html")
opera = webbrowser.get('opera')
opera.open("reseau_tht.html")