Kelbec commited on
Commit
acf68bc
1 Parent(s): 092753f

WIP nc file reading

Browse files
Files changed (1) hide show
  1. pages/01_dcascade.py +48 -14
pages/01_dcascade.py CHANGED
@@ -2,6 +2,7 @@ import os
2
  from pathlib import Path
3
  import shutil
4
  from typing import Callable, Optional, Union, cast
 
5
  # import leafmap
6
  from ipyleaflet import Map, GeoData, basemaps, LayersControl, ScaleControl, FullScreenControl, WidgetControl, TileLayer, Marker
7
  import geopandas as gpd
@@ -11,7 +12,7 @@ from leafmap.toolbar import change_basemap
11
  from solara.components.file_drop import FileInfo
12
  from dcascade_py import dcascade_py
13
  import xarray as xr
14
-
15
 
16
  zoom = solara.reactive(6)
17
  center = solara.reactive((20, 0))
@@ -21,6 +22,7 @@ sel_var = solara.reactive("")
21
  ds = solara.reactive(None)
22
  feature_properties = solara.reactive(None)
23
  geo_data = solara.reactive(None)
 
24
  chart_options = solara.reactive({
25
  "line": {
26
  "title": {"text": "Variable"},
@@ -76,6 +78,7 @@ def on_feature_click(feature, **kwargs):
76
  properties = feature['properties']
77
  print("Clicked on:", properties)
78
  feature_properties.set(properties)
 
79
 
80
  print("GD",geo_data.value.geo_dataframe)
81
  for f in geo_data.value.geo_dataframe['FromN']:
@@ -114,9 +117,10 @@ def on_feature_click(feature, **kwargs):
114
  @solara.component
115
  def MapComponent():
116
  # Isolation is required to prevent the map from overlapping navigation (when screen width < 960px)
 
117
  with solara.Column(style={"isolation": "isolate"}):
118
 
119
-
120
 
121
  if not map_loaded.value:
122
  sel_df = gpd.read_file(os.getcwd()+'/public/deposito.shp')
@@ -126,6 +130,7 @@ def MapComponent():
126
  geo_data.value.on_click(on_feature_click)
127
  center.set((geo_df.total_bounds[1], geo_df.total_bounds[0]))
128
  geo_data.value.style = {'color': 'black', 'fillColor': '#3366cc', 'opacity':0.5, 'weight':3.9, 'dashArray':'2', 'fillOpacity':0.1}
 
129
 
130
  m = Map(center=center.value, zoom = zoom.value, basemap= basemaps.Esri.WorldTopoMap)
131
  map_type = maps[map_name.value]
@@ -134,18 +139,47 @@ def MapComponent():
134
 
135
  m.add(geo_data.value)
136
  m.add(LayersControl())
137
- m.element( # type: ignore
138
- zoom=zoom.value,
139
- on_zoom=zoom.set,
140
- center=center.value,
141
- on_center=center.set,
142
- scroll_wheel_zoom=True,
143
- layers=[
144
- TileLayer.element(url=url),
145
- # Marker.element(location=marker_location.value, draggable=True, on_location=location_changed),
146
- geo_data.value
147
- ]
148
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  map_loaded.set(True)
150
  solara.Select(label="Variable", value=sel_var, values=variables.value, on_value=on_variable_change)
151
  FigureEcharts(option=chart_options.value["line"])
 
2
  from pathlib import Path
3
  import shutil
4
  from typing import Callable, Optional, Union, cast
5
+ import geojson
6
  # import leafmap
7
  from ipyleaflet import Map, GeoData, basemaps, LayersControl, ScaleControl, FullScreenControl, WidgetControl, TileLayer, Marker
8
  import geopandas as gpd
 
12
  from solara.components.file_drop import FileInfo
13
  from dcascade_py import dcascade_py
14
  import xarray as xr
15
+ from shapely.geometry import LineString
16
 
17
  zoom = solara.reactive(6)
18
  center = solara.reactive((20, 0))
 
22
  ds = solara.reactive(None)
23
  feature_properties = solara.reactive(None)
24
  geo_data = solara.reactive(None)
25
+ sel_feature = solara.reactive(None)
26
  chart_options = solara.reactive({
27
  "line": {
28
  "title": {"text": "Variable"},
 
78
  properties = feature['properties']
79
  print("Clicked on:", properties)
80
  feature_properties.set(properties)
81
+ sel_feature.set(feature)
82
 
83
  print("GD",geo_data.value.geo_dataframe)
84
  for f in geo_data.value.geo_dataframe['FromN']:
 
117
  @solara.component
118
  def MapComponent():
119
  # Isolation is required to prevent the map from overlapping navigation (when screen width < 960px)
120
+ print("RENDERING MAP COMPONENT")
121
  with solara.Column(style={"isolation": "isolate"}):
122
 
123
+ sel_geo_data = None
124
 
125
  if not map_loaded.value:
126
  sel_df = gpd.read_file(os.getcwd()+'/public/deposito.shp')
 
130
  geo_data.value.on_click(on_feature_click)
131
  center.set((geo_df.total_bounds[1], geo_df.total_bounds[0]))
132
  geo_data.value.style = {'color': 'black', 'fillColor': '#3366cc', 'opacity':0.5, 'weight':3.9, 'dashArray':'2', 'fillOpacity':0.1}
133
+ print(type(sel_feature.value))
134
 
135
  m = Map(center=center.value, zoom = zoom.value, basemap= basemaps.Esri.WorldTopoMap)
136
  map_type = maps[map_name.value]
 
139
 
140
  m.add(geo_data.value)
141
  m.add(LayersControl())
142
+ if sel_feature.value is not None:
143
+ # print("SEL FEATURE",sel_feature.value)
144
+ # Extracting the geometry
145
+ geometry = LineString(sel_feature.value['geometry']['coordinates'])
146
+
147
+ # Creating GeoDataFrame
148
+ gdf = gpd.GeoDataFrame([sel_feature.value['properties']], geometry=[geometry])
149
+
150
+ # Set the CRS (Coordinate Reference System) if known
151
+ gdf.crs = "EPSG:4326"
152
+ # Set the CRS (Coordinate Reference System) if known
153
+ sel_geo_data = GeoData(geo_dataframe=gdf)
154
+ sel_geo_data.style = {'color': 'red', 'fillColor': '#3366cc', 'opacity':0.5, 'weight':15.0, 'dashArray':'5'}
155
+
156
+ if sel_geo_data:
157
+ m.element( # type: ignore
158
+ zoom=zoom.value,
159
+ on_zoom=zoom.set,
160
+ center=center.value,
161
+ on_center=center.set,
162
+ scroll_wheel_zoom=True,
163
+ layers=[
164
+ TileLayer.element(url=url),
165
+ # Marker.element(location=marker_location.value, draggable=True, on_location=location_changed),
166
+ geo_data.value,
167
+ sel_geo_data
168
+ ]
169
+ )
170
+ else:
171
+ m.element( # type: ignore
172
+ zoom=zoom.value,
173
+ on_zoom=zoom.set,
174
+ center=center.value,
175
+ on_center=center.set,
176
+ scroll_wheel_zoom=True,
177
+ layers=[
178
+ TileLayer.element(url=url),
179
+ # Marker.element(location=marker_location.value, draggable=True, on_location=location_changed),
180
+ geo_data.value
181
+ ]
182
+ )
183
  map_loaded.set(True)
184
  solara.Select(label="Variable", value=sel_var, values=variables.value, on_value=on_variable_change)
185
  FigureEcharts(option=chart_options.value["line"])