Commit 23f4581a authored by Christine Plumejeaud's avatar Christine Plumejeaud
Browse files

make a map with port and countries

parent 03e48fd3
from branca.utilities import color_brewer
import folium
import pandas as pd
#import geopandas as gpd
......@@ -8,6 +9,9 @@ import json
import requests
import random
from ipyleaflet import AwesomeIcon, GeoJSON, Map, Marker, LayerGroup, SearchControl
# Look at https://python-visualization.github.io/folium/quickstart.html#GeoJSON/TopoJSON-Overlays
# https://makina-corpus.com/blog/metier/2019/python-carto
# https://www.geeksforgeeks.org/visualizing-geospatial-data-using-folium-in-python/?ref=rp
......@@ -22,35 +26,47 @@ france_bad = f"{url}/cartoweb_france_1789_geojson.geojson"
url2 = (
"https://gitlab.huma-num.fr/portic/gazetteer/-/raw/master/maps/"
)
url3 = (
"C:/Travail/Dev/portic_humanum/gazetteer/maps"
)
#world_ok = f"{url2}/cartoweb_world_1789_29juillet2021_mixte3857_topo.json"
world_geojson=f"{url2}/cartoweb_world_1789_29juillet2021_mixte4326_geojson.geojson"
world_data = f"{url2}/dico_mixte.csv"
#world_geojson_old=f"{url2}/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"
#world_data = f"{url2}/dico_mixte.csv"
#state_data = pd.read_csv(world_data)
if not os.path.exists('world_1789.json'):
r = requests.get(world_geojson)
with open('world_1789.json', 'w') as f:
f.write(r.content.decode("utf-8"))
#with open('test.json', 'r') as f:
with open('world_1789.json', 'r') as f:
data = json.load(f)
#df = pd.read_json(f)
#df = gpd.read_file(f)
state_data = pd.read_csv(world_data)
def random_color(feature):
#print(feature['properties'])
#print(feature['properties']['red'])
return {
'opacity': 1,
'dashArray': '9',
'fillOpacity': 0.1,
'fillOpacity': 0.5,
'weight': 1,
'color': 'black',
'fillColor': random.choice(['red', 'yellow', 'green', 'orange']),
'fillColor': '#%02x%02x%02x' % (feature['properties']['red'], feature['properties']['green'], feature['properties']['blue']),
#'fillColor': random.choice(['red', 'yellow', 'green', 'orange', 'blue']),
}
#print(df.head())
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')
......@@ -61,21 +77,51 @@ m.get_root().add_child(intro,name='Christine',index=77)
style = {'fillColor': '#f5f5f5', 'lineColor': '#ffffbf', 'fill_opacity':'0.5','line_opacity': '.1'}
#styleMap = {'position': 'relative', 'width': '100%', 'height': '80.0%', 'left': '0.0%', 'top': '0.0%'}
#styleTitle = {'position': 'relative', 'width': '100%', 'height': '15.0%', 'left': '0.0%', 'top': '0.0%'}
#polygon = folium.GeoJson(gjson, style_function = lambda x: style).add_to(m)
folium.GeoJson(world_geojson,
name="world_1789_29juillet2021",
style_function = lambda x: style,
popup="feature.id",
tooltip="Oléron").add_to(m)
#https://ipyleaflet.readthedocs.io/en/latest/api_reference/geo_json.html
folium.GeoJson(world_geojson,
name="avec couleurs",
layer_world = folium.GeoJson(world_geojson,
name="Fond mixte 1789",
style_function= random_color
)
layer_world.add_to(m)
"""
folium.GeoJson(ports_geojson,
name="ports de navigo",
style_function = lambda x: style,
popup="feature.id",
tooltip="test ports").add_to(m)
"""
folium.GeoJson(ports_geojson,
name="ports de navigo",
popup=portdescription,
tooltip="Port, Click to get info"
).add_to(m)
"""
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
""" marker = Marker(icon=AwesomeIcon(name="check", marker_color='green', icon_color='darkred'))
m.add_control(SearchControl(
position="topleft",
layer=layer_world,
zoom=4,
property_name='shortname',
marker=marker
)) """
#hover_style={
# 'color': 'white', 'dashArray': '0', 'fillOpacity': 0.5
......@@ -88,45 +134,35 @@ folium.GeoJson(world_geojson,
name="world_1789"
).add_to(m)"""
""" folium.Choropleth(
# geographical locations
geo_data = world_geojson,
name = "France_1789",
# the data set we are using
data = world_data,
columns = ["id", "id_sup"], #"unitlevel", "shortname",
# YlGn refers to yellow and green
fill_color = "#f5f5f5",
fill_opacity = 0.7,
line_opacity = .1,
key_on = "feature.id",
legend_name = "Appartenance",
).add_to(m) """
## Add a control on layers to display
folium.LayerControl().add_to(m)
## You can get lat/long by clicking anywhere
m.add_child(folium.LatLngPopup())
tooltip = "Click me!"
folium.Marker(
[46.1722, -1.1481], popup="<i>La Rochelle</i>", tooltip=tooltip
).add_to(m)
folium.Marker(
[45.9588, -1.3184],
popup="<b>Oléron</b>",
tooltip="Oléron",
icon=folium.Icon(color="red", icon="info-sign")
).add_to(m)
feature_list = data["features"]
for f in feature_list:
print(f['properties'])
## You can get lat/long by clicking anywhere
#m.add_child(folium.LatLngPopup())
#{'type': 'Feature', 'properties': {'id': 651, 'unitlevel': 1, 'shortname': 'Principauté de Piombino', 'id_sup': 903}, 'geometry': {'type': 'MultiPolygon', 'coordinates': [[[[10.29, 42.33], [10.31, 42.35], [10.33, 42.33]
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
m.save("index.html")
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
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