Commit e1351b3d authored by Christine Plumejeaud's avatar Christine Plumejeaud
Browse files

Une carte pour visualiser les premiers résultats (localisation des ports,...

Une carte pour visualiser les premiers résultats (localisation des ports, cartes des frontières du monde en 1789 et capitales du monde en 2018
parent 23f4581a
'''
Created on 1 august 2021
@author: cplumejeaud
ANR PORTIC : used to map geographic data of portic - ports, province and state borders of 1789
'''
from branca.utilities import color_brewer from branca.utilities import color_brewer
from branca.element import Html
import folium import folium
from folium.plugins import MarkerCluster
import pandas as pd import pandas as pd
#import geopandas as gpd #import geopandas as gpd
import os import os
...@@ -9,19 +18,24 @@ import json ...@@ -9,19 +18,24 @@ import json
import requests import requests
import random import random
from ipyleaflet import AwesomeIcon, GeoJSON, Map, Marker, LayerGroup, SearchControl #from ipyleaflet import AwesomeIcon, GeoJSON, Map, Marker, LayerGroup, SearchControl
# Look at https://python-visualization.github.io/folium/quickstart.html#GeoJSON/TopoJSON-Overlays # Look at https://python-visualization.github.io/folium/quickstart.html#GeoJSON/TopoJSON-Overlays
# https://georgetsilva.github.io/posts/mapping-points-with-folium/
# https://makina-corpus.com/blog/metier/2019/python-carto # https://makina-corpus.com/blog/metier/2019/python-carto
# https://www.geeksforgeeks.org/visualizing-geospatial-data-using-folium-in-python/?ref=rp # https://www.geeksforgeeks.org/visualizing-geospatial-data-using-folium-in-python/?ref=rp
#https://gis.stackexchange.com/questions/362582/coordinate-system-mismatch-in-folium
# https://gis.stackexchange.com/questions/362582/coordinate-system-mismatch-in-folium
# https://ipyleaflet.readthedocs.io/en/latest/api_reference/geo_json.html
# https://ipyleaflet.readthedocs.io/en/latest/api_reference/search_control.html
# For popup options, look at leaflet : https://leafletjs.com/reference-1.4.0.html#popup
url = ( url = (
"https://raw.githubusercontent.com/medialab/portic-storymaps-2021/main/public/data/" "https://raw.githubusercontent.com/medialab/portic-storymaps-2021/main/public/data/"
) )
france_bad = f"{url}/cartoweb_france_1789_geojson.geojson" france_bad = f"{url}/cartoweb_france_1789_geojson.geojson"
#antarctic_ice_shelf_topo = f"{url}/antarctic_ice_shelf_topo.json"
url2 = ( url2 = (
"https://gitlab.huma-num.fr/portic/gazetteer/-/raw/master/maps/" "https://gitlab.huma-num.fr/portic/gazetteer/-/raw/master/maps/"
...@@ -31,27 +45,31 @@ url3 = ( ...@@ -31,27 +45,31 @@ url3 = (
"C:/Travail/Dev/portic_humanum/gazetteer/maps" "C:/Travail/Dev/portic_humanum/gazetteer/maps"
) )
#world_ok = f"{url2}/cartoweb_world_1789_29juillet2021_mixte3857_topo.json"
#world_geojson_old=f"{url2}/cartoweb_world_1789_29juillet2021_mixte4326_geojson.geojson"
world_geojson=f"{url3}/cartoweb_world_1789_29juillet2021_mixte4326_geojson.geojson" world_geojson=f"{url3}/cartoweb_world_1789_29juillet2021_mixte4326_geojson.geojson"
#world_centres_geojson=f"{url2}/cartoweb_world_1789_29juillet2021_mixte4326_centres.geojson"
ports_geojson=f"{url3}/ports_1789_4326.json" ports_geojson=f"{url3}/ports_1789_4326.json"
cities_geojson=f"{url3}/cities_2018_4326.json"
#world_data = f"{url2}/dico_mixte.csv"
#state_data = pd.read_csv(world_data)
"""
if not os.path.exists('world_1789.json'): if not os.path.exists('world_1789.json'):
r = requests.get(world_geojson) r = requests.get(world_geojson)
with open('world_1789.json', 'w') as f: with open('world_1789.json', 'w') as f:
f.write(r.content.decode("utf-8")) f.write(r.content.decode("utf-8"))
"""
#with open('test.json', 'r') as f: #with open('test.json', 'r') as f:
with open('world_1789.json', 'r') as f: with open(world_geojson, 'r') as f:
data = json.load(f) data = json.load(f)
#df = pd.read_json(f)
#df = gpd.read_file(f) with open(ports_geojson, 'r') as f:
ports = json.load(f)
with open(cities_geojson, 'r') as f:
cities = json.load(f)
def random_color(feature): def random_color(feature):
"""A set of RGB colors has been randomly generated in the database for each unit of level 0 (state). """
#print(feature['properties']) #print(feature['properties'])
#print(feature['properties']['red']) #print(feature['properties']['red'])
return { return {
...@@ -64,14 +82,19 @@ def random_color(feature): ...@@ -64,14 +82,19 @@ def random_color(feature):
#'fillColor': random.choice(['red', 'yellow', 'green', 'orange', 'blue']), #'fillColor': random.choice(['red', 'yellow', 'green', 'orange', 'blue']),
} }
def portdescription(feature):
print(feature['properties'])
return feature['properties']['toponyme_standard_fr']
m = folium.Map(location=[46.1722, -1.1481],zoom_start=6, tiles="Stamen Terrain", height='80%', top='0.0%', crs='EPSG3857')
intro = folium.Div(height='20%', top='80.0%') m = folium.Map(location=[46.1722, -1.1481],zoom_start=6, tiles="Stamen Terrain", height='80%', top='0.0%', crs='EPSG3857')
#intro.title("<i>Texte de présentation de la carte</i>") texte="<h1>Mapping the maritime world of 1789</h1>"
""" <h1>Mapping the maritime world of 1789</h1>
<ul>
<li>This map has been made in <a href='http://anr.portic.fr'> ANR PORTIC </a> under CC4.0-BY-SA Licence</li>
<li>First layer is the borders of world in 1789, drawn from many sources. Ask to Christine Plumejeaud for metadata </li>
<li>Second layer is the the set of harbors coming from navigocorpus database, for the end of 18th century. Ask to Silvia Marzagalli for metadata</li>
<li>Data and metadata can be downloaded from our <a href='https://gitlab.huma-num.fr/portic/gazetteer/maps'> github </a> </li>
</ul> """
intro = folium.Div(height='20%', top='0.0%')
intro.add_child(Html(data=texte), name="intro")
m.get_root().add_child(intro,name='Christine',index=77) m.get_root().add_child(intro,name='Christine',index=77)
style = {'fillColor': '#f5f5f5', 'lineColor': '#ffffbf', 'fill_opacity':'0.5','line_opacity': '.1'} style = {'fillColor': '#f5f5f5', 'lineColor': '#ffffbf', 'fill_opacity':'0.5','line_opacity': '.1'}
...@@ -80,38 +103,91 @@ style = {'fillColor': '#f5f5f5', 'lineColor': '#ffffbf', 'fill_opacity':'0.5','l ...@@ -80,38 +103,91 @@ style = {'fillColor': '#f5f5f5', 'lineColor': '#ffffbf', 'fill_opacity':'0.5','l
#polygon = folium.GeoJson(gjson, style_function = lambda x: style).add_to(m) #polygon = folium.GeoJson(gjson, style_function = lambda x: style).add_to(m)
#####################################################################
## First layer with countries
#####################################################################
"""folium.TopoJson(
json.loads(requests.get(world_ok).text),
"objects.cartoweb_world_1789_29juillet2021_mixte3857",
#style_function=style_function,
name="world_1789"
).add_to(m)"""
#https://ipyleaflet.readthedocs.io/en/latest/api_reference/geo_json.html #https://ipyleaflet.readthedocs.io/en/latest/api_reference/geo_json.html
layer_world = folium.GeoJson(world_geojson, layer_world = folium.GeoJson(world_geojson,
name="Fond mixte 1789", name="Word borders in 1789",
style_function= random_color style_function= random_color
) )
layer_world.add_to(m) layer_world.add_to(m)
marker_clusterinfo = MarkerCluster().add_to(layer_world)
""" feature_list = data["features"]
folium.GeoJson(ports_geojson, for f in feature_list:
#print(f['properties'])
name="ports de navigo", shortname = f['properties']['shortname']
style_function = lambda x: style, latitude = f['properties']['lat']
popup="feature.id", longitude = f['properties']['long']
tooltip="test ports").add_to(m) popuptext = "<b>"+shortname+"</b>"
""" if f['properties']['dominant']!=None :
if f['properties']['unitlevel']!=2:
popuptext += "<br> Dominated by : "+str(f['properties']['dominant'])
else:
popuptext += "<br> Belongs to : "+str(f['properties']['dominant'])
folium.Marker(
[latitude, longitude],
popup=folium.Popup(html=popuptext, maxWidth=500),
tooltip=shortname,
icon=folium.Icon(color="red", icon="info-sign")
).add_to(marker_clusterinfo)
folium.GeoJson(ports_geojson, #####################################################################
name="ports de navigo", ## Second layer with ports
popup=portdescription, #####################################################################
tooltip="Port, Click to get info"
).add_to(m) layer_port = folium.FeatureGroup(name="Ports of navigocorpus database")
layer_port.add_to(m)
#https://georgetsilva.github.io/posts/mapping-points-with-folium/
marker_cluster = MarkerCluster().add_to(layer_port)
#For popup options, look at leaflet : https://leafletjs.com/reference-1.4.0.html#popup
feature_list = ports["features"]
for f in feature_list:
#print(f['properties'])
#uhgs_id, toponyme_standard_fr, toponyme_standard_en, state_1789_fr, state_1789_en, amiraute, province, status
shortname = f['properties']['toponyme_standard_fr']
latitude = f['properties']['lat']
longitude = f['properties']['long']
popuptext = "<b>"+shortname+"</b>"
if latitude!= None :
popuptext += "<br><table>"
if f['properties']['state_1789_fr']!=None :
popuptext += "<tr><td> State : </td><td>"+str(f['properties']['state_1789_fr']+"</td></tr>")
if f['properties']['province']!=None :
popuptext += "<tr><td> Province : </td><td>"+str(f['properties']['province']+"</td></tr>")
if f['properties']['amiraute']!=None :
popuptext += "<tr><td> Admiralty : </td><td>"+str(f['properties']['amiraute']+"</td></tr>")
if f['properties']['status']!=None :
popuptext += "<tr><td> Status : </td><td>"+str(f['properties']['status']+"</td></tr>")
if f['properties']['uhgs_id']!=None :
popuptext += "<tr><td> UHGS_ID : </td><td>"+str(f['properties']['uhgs_id']+"</td></tr>")
popuptext += "</table>"
folium.CircleMarker(
[latitude, longitude],
popup=folium.Popup(html=popuptext, maxWidth=500),
radius=10,
#fill=True,
color="blue",
color_opacity=0.5,
fill_color="blue",
fill_opacity=0.5,
tooltip=shortname,
#icon=folium.Icon(color="red", icon="info-sign")
).add_to(marker_cluster)
"""
folium.CircleMarker(
location=[45.5215, -122.6261],
radius=50,
popup="Laurelhurst Park",
color="#3186cc",
fill=True,
fill_color="#3186cc",
).add_to(m)
"""
#https://ipyleaflet.readthedocs.io/en/latest/api_reference/search_control.html #https://ipyleaflet.readthedocs.io/en/latest/api_reference/search_control.html
""" marker = Marker(icon=AwesomeIcon(name="check", marker_color='green', icon_color='darkred')) """ marker = Marker(icon=AwesomeIcon(name="check", marker_color='green', icon_color='darkred'))
...@@ -123,16 +199,25 @@ m.add_control(SearchControl( ...@@ -123,16 +199,25 @@ m.add_control(SearchControl(
marker=marker marker=marker
)) """ )) """
#hover_style={
# 'color': 'white', 'dashArray': '0', 'fillOpacity': 0.5
# },
"""folium.TopoJson( #####################################################################
json.loads(requests.get(world_ok).text), ## Cities layers
"objects.cartoweb_world_1789_29juillet2021_mixte3857", #####################################################################
#style_function=style_function,
name="world_1789" layer_cities = folium.FeatureGroup(name="Cities (capitals) 2018")
).add_to(m)""" layer_cities.add_to(m)
feature_list = cities["features"]
for f in feature_list:
folium.vector_layers.CircleMarker(
location=[f['properties']['lat'], f['properties']['long']],
tooltip =f['properties']['capital_city'],
radius = 7,
color="black",
fill_color="black",
fill_opacity=0.5,
#icon=folium.Icon(color="black", icon="info-sign")
).add_to(layer_cities)
## Add a control on layers to display ## Add a control on layers to display
...@@ -140,29 +225,5 @@ folium.LayerControl().add_to(m) ...@@ -140,29 +225,5 @@ folium.LayerControl().add_to(m)
## You can get lat/long by clicking anywhere ## You can get lat/long by clicking anywhere
m.add_child(folium.LatLngPopup()) m.add_child(folium.LatLngPopup())
tooltip = "Click me!"
feature_list = data["features"]
for f in feature_list:
print(f['properties'])
shortname = f['properties']['shortname']
latitude = f['properties']['lat']
longitude = f['properties']['long']
popuptext = "<b>"+shortname+"</b>"
if f['properties']['dominant']!=None :
if f['properties']['unitlevel']!=2:
popuptext += "<br> Sous la domination de : "+str(f['properties']['dominant'])
else:
popuptext += "<br> Appartient à : "+str(f['properties']['dominant'])
folium.Marker(
[latitude, longitude],
popup=popuptext,
tooltip=shortname,
icon=folium.Icon(color="red", icon="info-sign")
).add_to(m)
##Export HTML ##Export HTML
m.save("index.html") m.save("maps/index.html")
\ No newline at end of file \ No newline at end of file
This diff is collapsed.
"id","unitlevel","shortname","id_sup"
668,1,Schweinfurt,857
976,1,Unclaimed territory,-1
724,1,Wittelsbach,927
723,1,Memmingen,928
677,1,Ratzeburg,869
730,1,Biberach,936
702,1,Espagne,902
966,1,Northwest Territory,970
680,1,Dortmund,872
681,1,Frankfurt,874
695,1,Hesse-Darmstadt,891
765,1,Sardaigne,888
703,1,Danemark,905
965,1,Kamtchatka,973
718,1,Cologne,922
659,1,Duché d'Oldenbourg,882
687,1,Bernburg,880
751,1,colonies portugaises d'Amérique,895
752,1,îles atlantiques portugaises,895
711,1,Trier,916
758,1,Pays de la Généralité,925
670,1,Grande-Bretagne,859
71,2,Limousin,944
72,2,Auvergne,944
697,1,Nassau,896
59,2,Touraine,944
964,1,Georgia,860
60,2,Anjou,944
645,1,Duché de Massa et Carrare,894
63,2,Poitou,944
56,2,Foix,944
55,2,Bouillon,944
69,2,Languedoc,944
699,1,Zweibrücken,898
64,2,Aunis,944
669,1,Andorra,858
728,1,Hechingen,933
73,2,Guyenne-Gascony,944
93,2,Champagne,944
79,2,Berry,944
686,1,Mühlhausen,881
74,2,Lyonnais,944
708,1,Brunswick-Wolfenbuttel,910
75,2,Provence,944
690,1,Waldeck,884
756,1,Overijssel,925
76,2,Bourbonnais,944
707,1,Orange,907
77,2,La Marche,944
66,2,Bretagne,944
664,1,Malte,850
67,2,Maine,944
647,1,Hambourg,849
691,1,Dessau,886
78,2,Nivernais,944
57,2,Roussillon,944
82,2,Bourgogne,944
704,1,Schwabisches Hall,906
706,1,Lindau,908
95,2,Flandre,944
696,1,Rottweil,890
58,2,Navarre-Béarn,944
662,1,Altenburg,845
96,2,Dauphiné,944
87,2,Franche-Comté,944
80,2,Orléanais,944
968,1,Disputed between West Florida and USA,972
701,1,Weimar,900
854,0,Etats-Unis d'Amérique,-1
61,2,Normandie,944
748,1,Iles anglo-normandes,859
579,2,Lorraine,944
83,2,Île-de-France,944
62,2,Saintonge,944
947,2,Artois,944
673,1,Sigmaringen,863
689,1,Eisenach,885
726,1,Rothenburg,931
705,1,Reutlingen,909
84,2,Picardie,944
92,2,Alsace,944
733,1,Nuremberg,939
946,2,Angoumois,944
948,2,Comté de Créhange,944
661,1,principauté de Lampédouse,893
719,1,Sulzbach,923
725,1,Porrentruy,929
671,1,Russie,860
652,1,République de Venise,904
657,1,Pologne,878
682,1,Small States,873
679,1,Autriche,870
763,1,Sicile,861
764,1,Naples,861
766,1,Finlande,892
767,1,Poméranie suédoise,892
712,1,Prusse,914
736,1,Pays-Bas autrichiens,870
737,1,colonies danoises,905
746,1,colonies britanniques d'Amérique,859
749,1,Irlande,859
747,1,Ecosse,859
761,1,Isles de Corse,945
655,1,République de Raguse,864
739,1,Régence d'Alger,912
740,1,Régence de Tripoli,912
738,1,Norvège,905
741,1,Régence de Tunis,912
675,1,Köthen,866
755,1,Gueldre,925
720,1,Swiss Cantons,924
716,1,Zerbst,921
663,1,Hesse-Kassel,846
745,1,colonies françaises en Asie,945
715,1,Ulm,919
969,1,Disputed between Rupert’s land (UK) and USA,974
676,1,Bavaria,867
678,1,République de Gènes,868
688,1,Württemberg,883
685,1,Hanover,879
731,1,Mainz,938
650,1,Etats pontificaux,901
709,1,Empire ottoman,912
698,1,Portugal,895
967,1,Disputed between Massachusetts and Colony of new Brunswick (UK),971
717,1,Brandenburg-Bayreuth,920
943,1,colonies françaises d'Amérique,945
649,1,Dantzig,853
672,1,Überlingen,862
727,1,Kaufbeuren,932
653,1,République de Lucques,911
693,1,Royaume de Piémont-Sardaigne,888
656,1,San Marino,871
694,1,Suède,892
735,1,Persia,940
825,1,Empire du Maroc,856
830,1,Hawaï,899
722,1,Brandenburg-Ansbach,926
674,1,Coburg,865
844,1,Svalbard,930
822,1,"reste Asie, Moyen-Orient et Océanie",-1
658,1,Monaco,935
710,1,Saxe-Hildburghausen,913
757,1,Hollande,925
742,1,Canaries,902
750,1,Pays de Galles,859
743,1,colonies espagnoles d'Amérique,902
753,1,Frise,925
827,1,reste Afrique,-1
759,1,Zélande,925
654,1,Toscane,917
665,1,Saxony-Poland-Lithuania,851
700,1,Baden,897
841,1,reste Amérique-du-Sud,-1
683,1,Liège,876
839,1,Mexique,875
754,1,Groningue,925
762,1,Etat des Présides,861
660,1,Lubeck,889
729,1,Modena,934
646,1,Brême,847
648,1,Duché de Mecklenbourg,848
667,1,Lippe,855
651,1,Principauté de Piombino,903
768,1,colonie suèdoise en Amérique,892
666,1,Meiningen,852
760,1,Frise orientale,914
684,1,Passau,877
732,1,Parma Piacenza,937
692,1,Salzburg,887
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment