File size: 8,145 Bytes
cb59c78 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 |
import os
import leafmap
import solara
import ipywidgets as widgets
from leafmap import leafmap
import leafmap.colormaps as cm
zoom = solara.reactive(2)
center = solara.reactive((20, 0))
maps = {
'Most limiting soil quality rating factor': 'https://s3.eu-west-1.amazonaws.com/data.gaezdev.aws.fao.org/LR/soi1/SQ0_mze_v9aH.tif',
"Nutrient retention capacity": 'https://s3.eu-west-1.amazonaws.com/data.gaezdev.aws.fao.org/LR/soi1/SQ2_mze_v9aH.tif',
"Rooting conditions" : 'https://s3.eu-west-1.amazonaws.com/data.gaezdev.aws.fao.org/LR/soi1/SQ3_mze_v9aH.tif',
'Soil and terrain suitability, rain-fed': 'https://s3.eu-west-1.amazonaws.com/data.gaezdev.aws.fao.org/LR/soi2/siHr_sst_mze.tif'
}
maps_list= list(maps)
maps_values= list(maps.values())
legend_dict1 = {
"NA": "#FFFFFF", # Branco
"0.0 - 0.1": "#8B0000", # Vermelho escuro
"0.1 - 0.2": "#FF4500", # Laranja avermelhado
"0.2 - 0.3": "#FFA500", # Laranja
"0.3 - 0.4": "#FFD700", # Amarelo dourado
"0.4 - 0.5": "#FFFF00", # Amarelo
"0.5 - 0.6": "#ADFF2F", # Verde amarelado
"0.6 - 0.7": "#7FFF00", # Verde limão
"0.7 - 0.8": "#32CD32", # Verde médio
"0.8 - 0.9": "#008000", # Verde
"0.9 - 1.0": "#006400", # Verde escuro
"Permafrost": "#B0C4DE", # Cinza claro azulado
"Not evaluated": "#A9A9A9", # Cinza escuro
"Water": "#0000FF", # Azul
}
hex_colors_dict = {
0: "#FFFFFF", # NA
1: "#8B0000", # 0.0 - 0.1
2: "#FF4500", # 0.1 - 0.2
3: "#FFA500", # 0.2 - 0.3
4: "#FFD700", # 0.3 - 0.4
5: "#FFFF00", # 0.4 - 0.5
6: "#ADFF2F", # 0.5 - 0.6
7: "#7FFF00", # 0.6 - 0.7
8: "#32CD32", # 0.7 - 0.8
9: "#008000", # 0.8 - 0.9
10: "#006400", # 0.9 - 1.0
11: "#B0C4DE", # Permafrost
12: "#A9A9A9", # Not evaluated
13: "#0000FF", # Water
}
def add_widgets(m):
setattr(m, "zoom_to_layer", True)
style = {"description_width": "initial"}
padding = "0px 0px 0px 5px"
image = widgets.Dropdown(
value=None,
options=[('Most limiting soil quality rating factor', maps_values[0]),
('Nutrient retention capacity', maps_values[1]),
('Rooting conditions', maps_values[2]),
('Soil and terrain suitability, rain-fed', maps_values[3]),
],
description="Image:",
style=style,
layout=widgets.Layout(width="270px", padding=padding),
)
output = widgets.Output()
def change_image(change):
if change.new:
if change.new not in m.get_layer_names():
#mosaic = f"{url}/datasets/{dataset.value}/{image.value}.json"
layer_list = m.get_layer_names()
for layer in layer_list:
m.remove_layer(m.find_layer(layer))
#municipiosBR= 'https://geoftp.ibge.gov.br/organizacao_do_territorio/malhas_territoriais/malhas_municipais/municipio_2023/Brasil/BR_Municipios_2023.zip'
#estadosBR = 'https://geoftp.ibge.gov.br/organizacao_do_territorio/malhas_territoriais/malhas_municipais/municipio_2023/Brasil/BR_UF_2023.zip'
m.add_basemap("HYBRID")
#m.add_shp(estadosBR, layer_name='EstadosBR')
#m.add_shp(municipiosBR, layer_name='MunicipiosBR')
#m.remove_legend()
if image.value == maps_values[0]:
m.add_cog_layer(image.value, name= maps_list[0], colormap = hex_colors_dict, nodata =0)
m.add_legend(legend_title="Legend", legend_dict=legend_dict1)
elif image.value == maps_values[1]:
m.add_cog_layer(image.value, name= maps_list[1], colormap = hex_colors_dict, nodata =0)
m.add_legend(legend_title="Legend", legend_dict=legend_dict1)
elif image.value == maps_values[2]:
m.add_cog_layer(image.value, name= maps_list[2], colormap = hex_colors_dict, nodata=0)
m.add_legend(legend_title="Legend", legend_dict=legend_dict1)
elif image.value == maps_values[3]:
colors_dict = {
0: "#FFFFFF10", # Branco
1: "#006400", # Verde escuro
2: "#008000", # Verde
3: "#ADFF2F", # Verde claro
4: "#FFFF00", # Amarelo
5: "#DAA520", # Dourado escuro
6: "#FF8C00", # Laranja
7: "#A9A9A9", # Cinza escuro
8: "#D3D3D3", # Cinza claro
9: "#0000FF", # Azul
10: "#FF0000" # Vermelho
}
legend_dict = {
"NA": "#FFFFFF", # Branco
"SI > 75 : Very high": "#006400", # Verde escuro
"SI > 63 : High": "#008000", # Verde
"SI > 50 : Good": "#ADFF2F", # Verde claro
"SI > 35 : Medium": "#FFFF00", # Amarelo
"SI > 20 : Moderate": "#DAA520", # Dourado escuro
"SI > 10 : Marginal": "#FF8C00", # Laranja
"SI > 0 : Very marginal": "#A9A9A9", # Cinza escuro
"Not suitable": "#D3D3D3", # Cinza claro
"No cultivation": "#0000FF", # Azul
"Water": "#FF0000" # Vermelho
}
m.add_cog_layer(image.value, name= maps_list[3], colormap = colors_dict,nodata=0)
m.add_legend(legend_title="Legend", legend_dict=legend_dict)
output.outputs = ()
#output.append_stdout(f"Image date: {image_date}\n")
image.observe(change_image, names="value")
box = widgets.VBox(
[ image, output]
)
m.add_widget(box, position="topright", add_header=False)
class Map(leafmap.Map):
def __init__(self, **kwargs):
super().__init__(**kwargs)
add_widgets(self)
self.add_layer_manager(opened= True)
@solara.component
def Page():
with solara.Column(style={"min-width": "500px"}):
Map.element(
zoom=zoom.value,
on_zoom=zoom.set,
center=center.value,
on_center=center.set,
height="600px",
toolbar_ctrl=False,
data_ctrl=True,
)
|