La population des villes dans le var
Sur ce site : sql.sh , on trouve un fichier de données contenant les villes géolocalisées de toute la France et de leur nombre d'habitants.
Le programme suivant affiche sur une carte les villes et le nombre d'habitant pour le département du var
1
"""
2
population varoise
3
affichage du nombre d'habitants ( chiffres 2012 )
4
villes géolocalisées
5
"""
6
# import des bibliothèques
7
import folium
8
import csv
9
import requests
10
import webbrowser
11
# importation au format csv
12
url="https://sql.sh/ressources/sql-villes-france/villes_france.csv"
13
csvfile = requests.get(url)
14
csvfile = csvfile.content.decode('utf-8')
15
16
population_csv = csv.reader(csvfile.splitlines(), delimiter=',')
17
18
19
# Création de la carte centrée sur Draguignan (centre var à peu près )
20
carte_population = folium.Map(location=[43.5374662,6.4627333], zoom_start=9)
21
22
# lecture des données
23
24
for ligne in population_csv :
25
if ligne[1]=='83':
26
longitude=float(ligne[19])
27
latitude=float(ligne[20])
28
population=int(ligne[15])
29
nom=str(ligne[3])
30
nom=nom+" : " +str(population) + "hab"
31
if population >=20000 :
32
folium.Marker([latitude,longitude], popup = nom, icon = folium.Icon(color='red')).add_to(carte_population)
33
elif population > 15000 :
34
folium.Marker([latitude,longitude], popup = nom, icon = folium.Icon(color='blue')).add_to(carte_population)
35
elif population > 5000 :
36
folium.Marker([latitude,longitude], popup = nom, icon = folium.Icon(color='green')).add_to(carte_population)
37
elif population > 1000 :
38
folium.Marker([latitude,longitude], popup = nom, icon = folium.Icon(color='orange')).add_to(carte_population)
39
elif population > 10:
40
folium.Marker([latitude,longitude], popup = nom, icon = folium.Icon(color='pink')).add_to(carte_population)
41
42
43
#affichage
44
carte_population.save("pop_var.html")
45
webbrowser.open('pop_var.html')
46
Travail à réaliser :
Écrire et exécuter ce programme
Réaliser un affichage pour un autre département
Pour les plus rapide...
Modifiez les lignes du programme comme ci-dessous
1
for ligne in population_csv :
2
if ligne[1]=='83':
3
4
longitude=float(ligne[19])
5
latitude=float(ligne[20])
6
population=int(ligne[15])
7
nom=str(ligne[3])
8
nom=nom+" : " +str(population) + " hab"
9
rayon=population/1000
10
11
if population >=20000 :
12
folium.CircleMarker([latitude,longitude], tooltip = nom, radius = rayon, color='red', fill_color = 'red' , fill_opacity = 0.2 ).add_to(carte_population)
13
elif population > 10000 :
14
rayon=rayon*3
15
folium.CircleMarker([latitude,longitude], tooltip = nom, radius = rayon, color='blue', fill_color = 'blue' , fill_opacity = 0.2 ).add_to(carte_population)
16
elif population > 5000 :
17
rayon=rayon*4
18
folium.CircleMarker([latitude,longitude], tooltip = nom, radius = rayon, color='green', fill_color = 'green' , fill_opacity = 0.2 ).add_to(carte_population)
19
elif population > 1000 :
20
rayon=rayon*4
21
folium.CircleMarker([latitude,longitude], tooltip = nom, radius = rayon, color='orange', fill_color = 'orange' , fill_opacity = 0.2 ).add_to(carte_population)
22
elif population > 100:
23
rayon=rayon*10
24
folium.CircleMarker([latitude,longitude], tooltip = nom, radius = rayon, color='pink', fill_color = 'pink' , fill_opacity = 0.2 ).add_to(carte_population)
25
26
Modifier les rayons, les couleurs...Comme bon vous semble..