Spaces:
Runtime error
Runtime error
Jonathan Marokhovsky
commited on
Commit
•
dc438fe
1
Parent(s):
bb5a9d0
Backed up the original eurocrops code then started adapting the app to use the pmtiles which Quisheng was using.
Browse files- pages/01_eurocrops.py +6 -63
- pages/01_eurocrops.py.bak +144 -0
pages/01_eurocrops.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import leafmap
|
2 |
from leafmap import pmtiles_style
|
3 |
import solara
|
4 |
-
import
|
5 |
|
6 |
# THings to come:
|
7 |
# TODO: Calculate some metrics given the area.
|
@@ -12,49 +12,6 @@ import ipyleaflet
|
|
12 |
zoom = solara.reactive(2)
|
13 |
center = solara.reactive((20, 0))
|
14 |
|
15 |
-
# Euromap info
|
16 |
-
eurocrops_pmtiles = "https://s3.us-west-2.amazonaws.com/us-west-2.opendata.source.coop/cholmes/eurocrops/eurocrops-all.pmtiles"
|
17 |
-
|
18 |
-
original_style = {
|
19 |
-
"version": 8,
|
20 |
-
"sources": {
|
21 |
-
"source": {
|
22 |
-
"type": "vector",
|
23 |
-
"url": "pmtiles://https://s3.us-west-2.amazonaws.com/us-west-2.opendata.source.coop/cholmes/eurocrops/eurocrops-all.pmtiles",
|
24 |
-
"attribution": "PMTiles",
|
25 |
-
}
|
26 |
-
},
|
27 |
-
"layers": [
|
28 |
-
{
|
29 |
-
"id": "eurocrops_point",
|
30 |
-
"source": "source",
|
31 |
-
"source-layer": "eurocrops",
|
32 |
-
"type": "circle",
|
33 |
-
"paint": {"circle-color": "#8dd3c7", "circle-radius": 5},
|
34 |
-
"filter": ["==", ["geometry-type"], "Point"],
|
35 |
-
},
|
36 |
-
{
|
37 |
-
"id": "eurocrops_stroke",
|
38 |
-
"source": "source",
|
39 |
-
"source-layer": "eurocrops",
|
40 |
-
"type": "line",
|
41 |
-
"paint": {"line-color": "#8dd3c7", "line-width": 1},
|
42 |
-
"filter": ["==", ["geometry-type"], "LineString"],
|
43 |
-
},
|
44 |
-
{
|
45 |
-
"id": "eurocrops_fill",
|
46 |
-
"source": "source",
|
47 |
-
"source-layer": "eurocrops",
|
48 |
-
"type": "fill",
|
49 |
-
"paint": {"fill-color": "#8dd3c7", "fill-opacity": 0.5},
|
50 |
-
"filter": ["==", ["geometry-type"], "Polygon"],
|
51 |
-
},
|
52 |
-
],
|
53 |
-
}
|
54 |
-
style = original_style
|
55 |
-
del style["version"]
|
56 |
-
del style["sources"]
|
57 |
-
|
58 |
q_url = "https://storage.googleapis.com/ahp-research/overture/pmtiles/overture.pmtiles"
|
59 |
|
60 |
q_style = {
|
@@ -90,49 +47,35 @@ q_style = {
|
|
90 |
],
|
91 |
}
|
92 |
|
93 |
-
# self.add_pmtiles(url, name='PMTiles', style=style)
|
94 |
-
|
95 |
|
96 |
class Map(leafmap.Map):
|
97 |
def __init__(self, **kwargs) -> None:
|
98 |
super().__init__(**kwargs)
|
99 |
self.add_basemap("CartoDB.DarkMatter")
|
100 |
-
# self.add_pmtiles(
|
101 |
-
# eurocrops_pmtiles,
|
102 |
-
# style=style,
|
103 |
-
# name="Euro Crops",
|
104 |
-
# overlay=True,
|
105 |
-
# show=True,
|
106 |
-
# zoom_to_layer=True,
|
107 |
-
# )
|
108 |
-
# print(pmtiles_style(eurocrops_pmtiles))
|
109 |
-
# print(style)
|
110 |
self.add_pmtiles(
|
111 |
q_url,
|
112 |
-
# style=pmtiles_style(q_url),
|
113 |
style=q_style,
|
114 |
name="Quisheng Layer",
|
115 |
overlay=True,
|
116 |
show=True,
|
117 |
zoom_to_layer=True,
|
118 |
)
|
119 |
-
# self.add_my_pmtiles()
|
120 |
-
# self.add_stac_gui() ## TODO: make sure I need this
|
121 |
|
122 |
-
def
|
123 |
-
|
124 |
-
self.add(layer)
|
125 |
|
126 |
|
127 |
@solara.component
|
128 |
def Page():
|
|
|
|
|
|
|
129 |
with solara.Column(style={"min-width": "500px"}):
|
130 |
# solara components support reactive variables
|
131 |
# solara.SliderInt(label="Zoom level", value=zoom, min=1, max=20)
|
132 |
# using 3rd party widget library require wiring up the events manually
|
133 |
# using zoom.value and zoom.set
|
134 |
Map.element( # type: ignore
|
135 |
-
# m = Map.element( # type: ignore
|
136 |
zoom=zoom.value,
|
137 |
on_zoom=zoom.set,
|
138 |
center=center.value,
|
|
|
1 |
import leafmap
|
2 |
from leafmap import pmtiles_style
|
3 |
import solara
|
4 |
+
import ipywidgets as widgets
|
5 |
|
6 |
# THings to come:
|
7 |
# TODO: Calculate some metrics given the area.
|
|
|
12 |
zoom = solara.reactive(2)
|
13 |
center = solara.reactive((20, 0))
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
q_url = "https://storage.googleapis.com/ahp-research/overture/pmtiles/overture.pmtiles"
|
16 |
|
17 |
q_style = {
|
|
|
47 |
],
|
48 |
}
|
49 |
|
|
|
|
|
50 |
|
51 |
class Map(leafmap.Map):
|
52 |
def __init__(self, **kwargs) -> None:
|
53 |
super().__init__(**kwargs)
|
54 |
self.add_basemap("CartoDB.DarkMatter")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
self.add_pmtiles(
|
56 |
q_url,
|
|
|
57 |
style=q_style,
|
58 |
name="Quisheng Layer",
|
59 |
overlay=True,
|
60 |
show=True,
|
61 |
zoom_to_layer=True,
|
62 |
)
|
|
|
|
|
63 |
|
64 |
+
def run_area(self):
|
65 |
+
print(self.user_roi)
|
|
|
66 |
|
67 |
|
68 |
@solara.component
|
69 |
def Page():
|
70 |
+
with solara.Row():
|
71 |
+
solara.Button(label="Area", on_click=Map.run_area)
|
72 |
+
|
73 |
with solara.Column(style={"min-width": "500px"}):
|
74 |
# solara components support reactive variables
|
75 |
# solara.SliderInt(label="Zoom level", value=zoom, min=1, max=20)
|
76 |
# using 3rd party widget library require wiring up the events manually
|
77 |
# using zoom.value and zoom.set
|
78 |
Map.element( # type: ignore
|
|
|
79 |
zoom=zoom.value,
|
80 |
on_zoom=zoom.set,
|
81 |
center=center.value,
|
pages/01_eurocrops.py.bak
ADDED
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import leafmap
|
2 |
+
from leafmap import pmtiles_style
|
3 |
+
import solara
|
4 |
+
import ipyleaflet
|
5 |
+
|
6 |
+
# THings to come:
|
7 |
+
# TODO: Calculate some metrics given the area.
|
8 |
+
# TODO: add a raster to the toy
|
9 |
+
# TODO: Dynamically check the center of the map and change what's displayed depending on that.
|
10 |
+
|
11 |
+
# variables
|
12 |
+
zoom = solara.reactive(2)
|
13 |
+
center = solara.reactive((20, 0))
|
14 |
+
|
15 |
+
# Euromap info
|
16 |
+
eurocrops_pmtiles = "https://s3.us-west-2.amazonaws.com/us-west-2.opendata.source.coop/cholmes/eurocrops/eurocrops-all.pmtiles"
|
17 |
+
|
18 |
+
original_style = {
|
19 |
+
"version": 8,
|
20 |
+
"sources": {
|
21 |
+
"source": {
|
22 |
+
"type": "vector",
|
23 |
+
"url": "pmtiles://https://s3.us-west-2.amazonaws.com/us-west-2.opendata.source.coop/cholmes/eurocrops/eurocrops-all.pmtiles",
|
24 |
+
"attribution": "PMTiles",
|
25 |
+
}
|
26 |
+
},
|
27 |
+
"layers": [
|
28 |
+
{
|
29 |
+
"id": "eurocrops_point",
|
30 |
+
"source": "source",
|
31 |
+
"source-layer": "eurocrops",
|
32 |
+
"type": "circle",
|
33 |
+
"paint": {"circle-color": "#8dd3c7", "circle-radius": 5},
|
34 |
+
"filter": ["==", ["geometry-type"], "Point"],
|
35 |
+
},
|
36 |
+
{
|
37 |
+
"id": "eurocrops_stroke",
|
38 |
+
"source": "source",
|
39 |
+
"source-layer": "eurocrops",
|
40 |
+
"type": "line",
|
41 |
+
"paint": {"line-color": "#8dd3c7", "line-width": 1},
|
42 |
+
"filter": ["==", ["geometry-type"], "LineString"],
|
43 |
+
},
|
44 |
+
{
|
45 |
+
"id": "eurocrops_fill",
|
46 |
+
"source": "source",
|
47 |
+
"source-layer": "eurocrops",
|
48 |
+
"type": "fill",
|
49 |
+
"paint": {"fill-color": "#8dd3c7", "fill-opacity": 0.5},
|
50 |
+
"filter": ["==", ["geometry-type"], "Polygon"],
|
51 |
+
},
|
52 |
+
],
|
53 |
+
}
|
54 |
+
style = original_style
|
55 |
+
del style["version"]
|
56 |
+
del style["sources"]
|
57 |
+
|
58 |
+
q_url = "https://storage.googleapis.com/ahp-research/overture/pmtiles/overture.pmtiles"
|
59 |
+
|
60 |
+
q_style = {
|
61 |
+
"layers": [
|
62 |
+
{
|
63 |
+
"id": "admins",
|
64 |
+
"source": "example_source",
|
65 |
+
"source-layer": "admins",
|
66 |
+
"type": "fill",
|
67 |
+
"paint": {"fill-color": "#BDD3C7", "fill-opacity": 0.1},
|
68 |
+
},
|
69 |
+
{
|
70 |
+
"id": "buildings",
|
71 |
+
"source": "example_source",
|
72 |
+
"source-layer": "buildings",
|
73 |
+
"type": "fill",
|
74 |
+
"paint": {"fill-color": "#FFFFB3", "fill-opacity": 0.5},
|
75 |
+
},
|
76 |
+
{
|
77 |
+
"id": "places",
|
78 |
+
"source": "example_source",
|
79 |
+
"source-layer": "places",
|
80 |
+
"type": "fill",
|
81 |
+
"paint": {"fill-color": "#BEBADA", "fill-opacity": 0.5},
|
82 |
+
},
|
83 |
+
{
|
84 |
+
"id": "roads",
|
85 |
+
"source": "example_source",
|
86 |
+
"source-layer": "roads",
|
87 |
+
"type": "line",
|
88 |
+
"paint": {"line-color": "#FB8072"},
|
89 |
+
},
|
90 |
+
],
|
91 |
+
}
|
92 |
+
|
93 |
+
# self.add_pmtiles(url, name='PMTiles', style=style)
|
94 |
+
|
95 |
+
|
96 |
+
class Map(leafmap.Map):
|
97 |
+
def __init__(self, **kwargs) -> None:
|
98 |
+
super().__init__(**kwargs)
|
99 |
+
self.add_basemap("CartoDB.DarkMatter")
|
100 |
+
# self.add_pmtiles(
|
101 |
+
# eurocrops_pmtiles,
|
102 |
+
# style=style,
|
103 |
+
# name="Euro Crops",
|
104 |
+
# overlay=True,
|
105 |
+
# show=True,
|
106 |
+
# zoom_to_layer=True,
|
107 |
+
# )
|
108 |
+
# print(pmtiles_style(eurocrops_pmtiles))
|
109 |
+
# print(style)
|
110 |
+
self.add_pmtiles(
|
111 |
+
q_url,
|
112 |
+
# style=pmtiles_style(q_url),
|
113 |
+
style=q_style,
|
114 |
+
name="Quisheng Layer",
|
115 |
+
overlay=True,
|
116 |
+
show=True,
|
117 |
+
zoom_to_layer=True,
|
118 |
+
)
|
119 |
+
# self.add_my_pmtiles()
|
120 |
+
# self.add_stac_gui() ## TODO: make sure I need this
|
121 |
+
|
122 |
+
def add_my_pmtiles(self, **kwargs):
|
123 |
+
layer = ipyleaflet.PMTilesLayer(url=eurocrops_pmtiles, style=style)
|
124 |
+
self.add(layer)
|
125 |
+
|
126 |
+
|
127 |
+
@solara.component
|
128 |
+
def Page():
|
129 |
+
with solara.Column(style={"min-width": "500px"}):
|
130 |
+
# solara components support reactive variables
|
131 |
+
# solara.SliderInt(label="Zoom level", value=zoom, min=1, max=20)
|
132 |
+
# using 3rd party widget library require wiring up the events manually
|
133 |
+
# using zoom.value and zoom.set
|
134 |
+
Map.element( # type: ignore
|
135 |
+
# m = Map.element( # type: ignore
|
136 |
+
zoom=zoom.value,
|
137 |
+
on_zoom=zoom.set,
|
138 |
+
center=center.value,
|
139 |
+
on_center=center.set,
|
140 |
+
scroll_wheel_zoom=True,
|
141 |
+
toolbar_ctrl=False,
|
142 |
+
data_ctrl=False,
|
143 |
+
height="780px",
|
144 |
+
)
|