cboettig commited on
Commit
9ef5688
·
1 Parent(s): dd37993
Files changed (2) hide show
  1. app.py +52 -5
  2. requirements.txt +2 -1
app.py CHANGED
@@ -12,6 +12,8 @@
12
  # limitations under the License.
13
 
14
  import leafmap.foliumap as leafmap
 
 
15
  import streamlit as st
16
  import altair as alt
17
  import ibis
@@ -26,31 +28,76 @@ st.set_page_config(layout="wide", page_title="Leafmap Explorer", page_icon="⚡"
26
  # Leafmap explorer
27
 
28
  '''
29
- # -
30
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  code = '''
32
  m = leafmap.Map(center=[35, -100], zoom=3)
33
- m.add_cog_layer("https://data.source.coop/cboettig/carbon/cogs/irrecoverable_c_total_2018.tif", palette="reds", name="irrecoverable carbon", transparent_bg=True, opacity = 0.8)
34
- m.add_cog_layer("https://data.source.coop/cboettig/carbon/cogs/vulnerable_c_total_2018.tif", palette="purples", name="vulnerable carbon", transparent_bg=True, opacity = 0.8)
35
  m.add_cog_layer("https://data.source.coop/cboettig/carbon/cogs/manageable_c_total_2018.tif", palette="greens", name="manageable carbon", transparent_bg=True, opacity = 0.8)
36
  '''
37
 
38
 
 
 
 
 
 
39
  # +
40
  ## Map controls sidebar
41
 
42
  with st.sidebar:
43
 
44
- "## Map controls"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
  code = st.text_area(
47
  label = "Python code",
48
  value = code,
49
  height = 400)
50
 
51
- # -
52
 
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  eval(code)
55
  m.to_streamlit(height=700)
56
 
 
 
 
12
  # limitations under the License.
13
 
14
  import leafmap.foliumap as leafmap
15
+ import rioxarray
16
+ import geopandas as gpd
17
  import streamlit as st
18
  import altair as alt
19
  import ibis
 
28
  # Leafmap explorer
29
 
30
  '''
 
31
 
32
+
33
+ deforest = "https://data.source.coop/vizzuality/lg-land-carbon-data/deforest_carbon_100m_cog.tif"
34
+ irrecoverable = "https://data.source.coop/cboettig/carbon/cogs/irrecoverable_c_total_2018.tif"
35
+ vulnerable = "https://data.source.coop/cboettig/carbon/cogs/vulnerable_c_total_2018.tif"
36
+
37
+
38
+ # m.add_cog_layer("https://data.source.coop/cboettig/carbon/cogs/irrecoverable_c_total_2018.tif", palette="reds", name="irrecoverable carbon", transparent_bg=True, opacity = 0.8)
39
+ # m.add_cog_layer("https://data.source.coop/cboettig/carbon/cogs/vulnerable_c_total_2018.tif", palette="purples", name="vulnerable carbon", transparent_bg=True, opacity = 0.8)
40
+
41
+
42
+
43
+ # +
44
  code = '''
45
  m = leafmap.Map(center=[35, -100], zoom=3)
 
 
46
  m.add_cog_layer("https://data.source.coop/cboettig/carbon/cogs/manageable_c_total_2018.tif", palette="greens", name="manageable carbon", transparent_bg=True, opacity = 0.8)
47
  '''
48
 
49
 
50
+ polygon = '''
51
+ {"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[-123.011169,40.728527],[-123.011169,40.798217],[-122.956924,40.798217],[-122.956924,40.728527],[-123.011169,40.728527]]]}}
52
+ '''
53
+
54
+
55
  # +
56
  ## Map controls sidebar
57
 
58
  with st.sidebar:
59
 
60
+ "# Map controls"
61
+
62
+ '''
63
+ ### Polygon selector
64
+
65
+ Use the map tools to draw a polygon (e.g. box area) anywhere on the map.
66
+ Click inside the box when you are done to show the coordinates.
67
+ Please paste those coordinates (or any geojson of your choosing) here
68
+ to see summary statistics on the map.
69
+ '''
70
+
71
+ polygon = st.text_area(
72
+ label = "geometry",
73
+ value = polygon,
74
+ height = 400)
75
+
76
+
77
+ "### Execute arbitrary python code:"
78
 
79
  code = st.text_area(
80
  label = "Python code",
81
  value = code,
82
  height = 400)
83
 
 
84
 
85
 
86
+ # +
87
+ geo = gpd.read_file(polygon, driver='GeoJSON')
88
+ geo.set_crs('epsg:4326')
89
+
90
+ x = (rioxarray.
91
+ open_rasterio('/vsicurl/'+deforest, masked=True).
92
+ rio.clip(geo.geometry.values, geo.crs, from_disk=True).
93
+ mean()
94
+ )
95
+
96
+ st.write(float(x))
97
+ # -
98
+
99
  eval(code)
100
  m.to_streamlit(height=700)
101
 
102
+
103
+
requirements.txt CHANGED
@@ -5,4 +5,5 @@ streamlit
5
  leafmap
6
  ibis-framework[duckdb]
7
  altair
8
-
 
 
5
  leafmap
6
  ibis-framework[duckdb]
7
  altair
8
+ rioxarray
9
+ geopandas