Spaces:
Sleeping
Sleeping
Yunus Serhat Bıçakçı
commited on
Commit
•
8f0ec60
1
Parent(s):
532a0d1
update
Browse files- .idea/.gitignore +8 -0
- pages/01_leafmap.py +3 -3
- pages/02_geemap.py +0 -63
- pages/03_mapbox.py +0 -25
- pages/04_cesium.py +0 -28
- pages/05_maplibre.py +0 -26
- pages/06_openlayers.py +0 -24
- pages/07_ipyleaflet.py +0 -44
- pages/08_Coordinate_Converter.py +110 -0
- requirements.txt +2 -0
.idea/.gitignore
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Default ignored files
|
2 |
+
/shelf/
|
3 |
+
/workspace.xml
|
4 |
+
# Editor-based HTTP Client requests
|
5 |
+
/httpRequests/
|
6 |
+
# Datasource local storage ignored files
|
7 |
+
/dataSources/
|
8 |
+
/dataSources.local.xml
|
pages/01_leafmap.py
CHANGED
@@ -2,15 +2,15 @@ import leafmap
|
|
2 |
import solara
|
3 |
from leafmap.toolbar import change_basemap
|
4 |
|
5 |
-
zoom = solara.reactive(
|
6 |
-
center = solara.reactive((
|
7 |
|
8 |
|
9 |
class Map(leafmap.Map):
|
10 |
def __init__(self, **kwargs):
|
11 |
super().__init__(**kwargs)
|
12 |
# Add what you want below
|
13 |
-
self.add_basemap("
|
14 |
change_basemap(self)
|
15 |
|
16 |
|
|
|
2 |
import solara
|
3 |
from leafmap.toolbar import change_basemap
|
4 |
|
5 |
+
zoom = solara.reactive(10)
|
6 |
+
center = solara.reactive((51.50, -0.1))
|
7 |
|
8 |
|
9 |
class Map(leafmap.Map):
|
10 |
def __init__(self, **kwargs):
|
11 |
super().__init__(**kwargs)
|
12 |
# Add what you want below
|
13 |
+
self.add_basemap("ROADMAP")
|
14 |
change_basemap(self)
|
15 |
|
16 |
|
pages/02_geemap.py
DELETED
@@ -1,63 +0,0 @@
|
|
1 |
-
|
2 |
-
import ee
|
3 |
-
import geemap
|
4 |
-
|
5 |
-
import solara
|
6 |
-
|
7 |
-
zoom = solara.reactive(4)
|
8 |
-
center = solara.reactive([40, -100])
|
9 |
-
|
10 |
-
|
11 |
-
class Map(geemap.Map):
|
12 |
-
def __init__(self, **kwargs):
|
13 |
-
super().__init__(**kwargs)
|
14 |
-
self.add_ee_data()
|
15 |
-
self.add_layer_manager()
|
16 |
-
self.add_inspector()
|
17 |
-
|
18 |
-
|
19 |
-
def add_ee_data(self):
|
20 |
-
|
21 |
-
# Add Earth Engine dataset
|
22 |
-
dem = ee.Image('USGS/SRTMGL1_003')
|
23 |
-
landsat7 = ee.Image('LANDSAT/LE7_TOA_5YEAR/1999_2003').select(
|
24 |
-
['B1', 'B2', 'B3', 'B4', 'B5', 'B7']
|
25 |
-
)
|
26 |
-
states = ee.FeatureCollection("TIGER/2018/States")
|
27 |
-
|
28 |
-
# Set visualization parameters.
|
29 |
-
vis_params = {
|
30 |
-
'min': 0,
|
31 |
-
'max': 4000,
|
32 |
-
'palette': ['006633', 'E5FFCC', '662A00', 'D8D8D8', 'F5F5F5'],
|
33 |
-
}
|
34 |
-
|
35 |
-
# Add Earth Engine layers to Map
|
36 |
-
self.addLayer(dem, vis_params, 'SRTM DEM', True, 0.5)
|
37 |
-
self.addLayer(
|
38 |
-
landsat7,
|
39 |
-
{'bands': ['B4', 'B3', 'B2'], 'min': 20, 'max': 200, 'gamma': 2.0},
|
40 |
-
'Landsat 7', False
|
41 |
-
)
|
42 |
-
self.addLayer(states, {}, "US States")
|
43 |
-
|
44 |
-
|
45 |
-
@solara.component
|
46 |
-
def Page():
|
47 |
-
with solara.Column(style={"min-width": "500px"}):
|
48 |
-
# solara components support reactive variables
|
49 |
-
# solara.SliderInt(label="Zoom level", value=zoom, min=1, max=20)
|
50 |
-
# using 3rd party widget library require wiring up the events manually
|
51 |
-
# using zoom.value and zoom.set
|
52 |
-
Map.element( # type: ignore
|
53 |
-
zoom=zoom.value,
|
54 |
-
on_zoom=zoom.set,
|
55 |
-
center=center.value,
|
56 |
-
on_center=center.set,
|
57 |
-
scroll_wheel_zoom=True,
|
58 |
-
add_google_map=True,
|
59 |
-
height="700px"
|
60 |
-
|
61 |
-
)
|
62 |
-
solara.Text(f"Zoom: {zoom.value}")
|
63 |
-
solara.Text(f"Center: {center.value}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pages/03_mapbox.py
DELETED
@@ -1,25 +0,0 @@
|
|
1 |
-
|
2 |
-
import mapwidget.mapbox as mapwidget
|
3 |
-
|
4 |
-
import solara
|
5 |
-
|
6 |
-
zoom = solara.reactive(2)
|
7 |
-
center = solara.reactive((20, 0))
|
8 |
-
|
9 |
-
|
10 |
-
@solara.component
|
11 |
-
def Page():
|
12 |
-
with solara.Column(style={"min-width": "500px", "height": "500px"}):
|
13 |
-
solara.Text("Not fully working yet. Try resizing the window to use the full width.")
|
14 |
-
# solara components support reactive variables
|
15 |
-
solara.SliderInt(label="Zoom level", value=zoom, min=1, max=20)
|
16 |
-
# using 3rd party widget library require wiring up the events manually
|
17 |
-
# using zoom.value and zoom.set
|
18 |
-
mapwidget.Map.element( # type: ignore
|
19 |
-
zoom=zoom.value,
|
20 |
-
center=center.value,
|
21 |
-
height='600px',
|
22 |
-
width="100%"
|
23 |
-
)
|
24 |
-
solara.Text(f"Zoom: {zoom.value}")
|
25 |
-
solara.Text(f"Center: {center.value}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pages/04_cesium.py
DELETED
@@ -1,28 +0,0 @@
|
|
1 |
-
|
2 |
-
import os
|
3 |
-
import mapwidget.cesium as mapwidget
|
4 |
-
|
5 |
-
import solara
|
6 |
-
|
7 |
-
altitude = solara.reactive(400)
|
8 |
-
center = solara.reactive((37.655, -122.4175))
|
9 |
-
|
10 |
-
if os.environ.get('CESIUM_TOKEN') is None:
|
11 |
-
token = 'YOUR-CESIUM-TOKEN'
|
12 |
-
else:
|
13 |
-
token = os.environ.get('CESIUM_TOKEN')
|
14 |
-
|
15 |
-
@solara.component
|
16 |
-
def Page():
|
17 |
-
with solara.Column(style={"min-width": "500px", "height": "500px"}):
|
18 |
-
# solara components support reactive variables
|
19 |
-
solara.SliderInt(label="Zoom level", value=altitude, min=1, max=1000)
|
20 |
-
# using 3rd party widget library require wiring up the events manually
|
21 |
-
# using zoom.value and zoom.set
|
22 |
-
mapwidget.Map.element( # type: ignore
|
23 |
-
center=center.value,
|
24 |
-
altitude=altitude.value,
|
25 |
-
height='600px',
|
26 |
-
width="100%"
|
27 |
-
)
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pages/05_maplibre.py
DELETED
@@ -1,26 +0,0 @@
|
|
1 |
-
|
2 |
-
import mapwidget.maplibre as mapwidget
|
3 |
-
|
4 |
-
import solara
|
5 |
-
|
6 |
-
zoom = solara.reactive(2)
|
7 |
-
center = solara.reactive((20, 0))
|
8 |
-
|
9 |
-
|
10 |
-
@solara.component
|
11 |
-
def Page():
|
12 |
-
with solara.Column(style={"min-width": "500px", "height": "500px"}):
|
13 |
-
solara.Text("Not fully working yet. Try resizing the window to use the full width.")
|
14 |
-
|
15 |
-
# solara components support reactive variables
|
16 |
-
solara.SliderInt(label="Zoom level", value=zoom, min=1, max=20)
|
17 |
-
# using 3rd party widget library require wiring up the events manually
|
18 |
-
# using zoom.value and zoom.set
|
19 |
-
mapwidget.Map.element( # type: ignore
|
20 |
-
zoom=zoom.value,
|
21 |
-
center=center.value,
|
22 |
-
height='600px',
|
23 |
-
width="100%"
|
24 |
-
)
|
25 |
-
solara.Text(f"Zoom: {zoom.value}")
|
26 |
-
solara.Text(f"Center: {center.value}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pages/06_openlayers.py
DELETED
@@ -1,24 +0,0 @@
|
|
1 |
-
|
2 |
-
import mapwidget.openlayers as mapwidget
|
3 |
-
|
4 |
-
import solara
|
5 |
-
|
6 |
-
zoom = solara.reactive(5)
|
7 |
-
center = solara.reactive((53.2305799, 6.5323552))
|
8 |
-
|
9 |
-
|
10 |
-
@solara.component
|
11 |
-
def Page():
|
12 |
-
with solara.Column(style={"min-width": "500px", "height": "500px"}):
|
13 |
-
# solara components support reactive variables
|
14 |
-
solara.SliderInt(label="Zoom level", value=zoom, min=1, max=20)
|
15 |
-
# using 3rd party widget library require wiring up the events manually
|
16 |
-
# using zoom.value and zoom.set
|
17 |
-
mapwidget.Map.element( # type: ignore
|
18 |
-
zoom=zoom.value,
|
19 |
-
center=center.value,
|
20 |
-
height='600px',
|
21 |
-
width="100%"
|
22 |
-
)
|
23 |
-
# solara.Text(f"Zoom: {zoom.value}")
|
24 |
-
# solara.Text(f"Center: {center.value}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pages/07_ipyleaflet.py
DELETED
@@ -1,44 +0,0 @@
|
|
1 |
-
import ipyleaflet
|
2 |
-
import solara
|
3 |
-
import ipywidgets as widgets
|
4 |
-
|
5 |
-
zoom = solara.reactive(2)
|
6 |
-
center = solara.reactive((20, 0))
|
7 |
-
|
8 |
-
|
9 |
-
class Map(ipyleaflet.Map):
|
10 |
-
def __init__(self, **kwargs):
|
11 |
-
super().__init__(**kwargs)
|
12 |
-
self.layout.height = '600px'
|
13 |
-
# Add what you want below
|
14 |
-
|
15 |
-
label = widgets.Label('Clicked location')
|
16 |
-
output = widgets.Output()
|
17 |
-
widget = widgets.VBox([label, output])
|
18 |
-
control = ipyleaflet.WidgetControl(widget=widget, position='bottomright')
|
19 |
-
self.add_control(control)
|
20 |
-
|
21 |
-
def handle_interaction(**kwargs):
|
22 |
-
latlon = kwargs.get("coordinates")
|
23 |
-
if kwargs.get("type") == "click":
|
24 |
-
with output:
|
25 |
-
output.clear_output()
|
26 |
-
print(latlon)
|
27 |
-
|
28 |
-
self.on_interaction(handle_interaction)
|
29 |
-
|
30 |
-
|
31 |
-
@solara.component
|
32 |
-
def Page():
|
33 |
-
with solara.Column(style={"min-width": "500px"}):
|
34 |
-
solara.SliderInt(label="Zoom level", value=zoom, min=1, max=20)
|
35 |
-
Map.element(
|
36 |
-
zoom=zoom.value,
|
37 |
-
on_zoom=zoom.set,
|
38 |
-
center=center.value,
|
39 |
-
on_center=center.set,
|
40 |
-
scroll_wheel_zoom=True,
|
41 |
-
|
42 |
-
)
|
43 |
-
solara.Text(f"Zoom: {zoom.value}")
|
44 |
-
solara.Text(f"Center: {center.value}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pages/08_Coordinate_Converter.py
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Optional, cast
|
2 |
+
import pandas as pd
|
3 |
+
import os
|
4 |
+
import solara
|
5 |
+
from solara.components.file_drop import FileDrop
|
6 |
+
from lat_lon_parser import parse, to_str_deg_min_sec
|
7 |
+
|
8 |
+
|
9 |
+
class State:
|
10 |
+
options = ["Decimal", "Deg_Min_Sec"]
|
11 |
+
option = solara.reactive("")
|
12 |
+
df = solara.reactive(cast(Optional[pd.DataFrame], None))
|
13 |
+
dff = solara.reactive(cast(Optional[pd.DataFrame], None))
|
14 |
+
latitude = solara.reactive(cast(Optional[str], ""))
|
15 |
+
longitude = solara.reactive(cast(Optional[str], ""))
|
16 |
+
extension_check = solara.reactive(True)
|
17 |
+
error_message = solara.reactive("")
|
18 |
+
|
19 |
+
@staticmethod
|
20 |
+
def load_from_file(file):
|
21 |
+
file_name, file_extension = os.path.splitext(file["name"])
|
22 |
+
if file_extension == ".csv":
|
23 |
+
df = pd.read_csv(file["file_obj"], encoding='latin-1')
|
24 |
+
State.df.value = df
|
25 |
+
State.extension_check.value = True
|
26 |
+
State.reset_vars()
|
27 |
+
else:
|
28 |
+
State.extension_check.value = False
|
29 |
+
State.df.value = None
|
30 |
+
State.reset_vars()
|
31 |
+
|
32 |
+
def reset_vars():
|
33 |
+
State.latitude.value = str("")
|
34 |
+
State.longitude.value = str("")
|
35 |
+
State.option.value = str("")
|
36 |
+
State.error_message.value = str("")
|
37 |
+
|
38 |
+
@staticmethod
|
39 |
+
def convert():
|
40 |
+
State.error_message.value = ""
|
41 |
+
try:
|
42 |
+
df = State.df.value
|
43 |
+
df['converted_latitude'] = df.loc[:, str(State.latitude.value)]
|
44 |
+
df['converted_longitude'] = df.loc[:, str(State.longitude.value)]
|
45 |
+
if State.option.value == "Decimal":
|
46 |
+
df['converted_longitude'] = df['converted_longitude'].str.replace('O', 'W')
|
47 |
+
df["converted_latitude"] = df["converted_latitude"].apply(parse)
|
48 |
+
df["converted_longitude"] = df["converted_longitude"].apply(parse)
|
49 |
+
elif State.option.value == "Deg_Min_Sec":
|
50 |
+
df["converted_latitude"] = df["converted_latitude"].apply(to_str_deg_min_sec)
|
51 |
+
df["converted_longitude"] = df["converted_longitude"].apply(to_str_deg_min_sec)
|
52 |
+
df["converted_latitude"] = df["converted_latitude"].apply(
|
53 |
+
lambda x: x.replace("-", "") + "S" if "-" in x else x + "N")
|
54 |
+
df["converted_longitude"] = df["converted_longitude"].apply(
|
55 |
+
lambda x: x.replace("-", "") + "W" if "-" in x else x + "E")
|
56 |
+
except Exception as es:
|
57 |
+
State.error_message.value = f"An error occurred. Please check your latitude and longitude format and ensure the correct conversion format ({es})"
|
58 |
+
else:
|
59 |
+
State.df.value = None
|
60 |
+
State.df.value = df
|
61 |
+
State.dff.value = State.df.value
|
62 |
+
|
63 |
+
|
64 |
+
@solara.component
|
65 |
+
def Page():
|
66 |
+
|
67 |
+
with solara.Column(style={"min-width": "500px", "height": "500px"}):
|
68 |
+
df = State.df.value
|
69 |
+
|
70 |
+
solara.Title("GPS Coordinates Converter")
|
71 |
+
|
72 |
+
with solara.Sidebar():
|
73 |
+
with solara.Column():
|
74 |
+
FileDrop(on_file=State.load_from_file, on_total_progress=lambda *args: None,
|
75 |
+
label="Drag your file CSV here")
|
76 |
+
|
77 |
+
if State.extension_check.value is not True:
|
78 |
+
solara.Warning("Only CSV file are allowed")
|
79 |
+
else:
|
80 |
+
if df is not None:
|
81 |
+
columns = list(map(str, df.columns))
|
82 |
+
solara.Select("Latitude", values=columns, value=State.latitude)
|
83 |
+
solara.Select("Longitude", values=columns, value=State.longitude)
|
84 |
+
solara.Select("Convert To", values=State.options, value=State.option)
|
85 |
+
|
86 |
+
if State.longitude.value == "" or State.latitude.value == "" or State.option.value == "":
|
87 |
+
solara.Info("Select Coordinates Columns and Ouput Format")
|
88 |
+
else:
|
89 |
+
solara.Button("Convert", color="primary", text=True, outlined=True, on_click=State.convert)
|
90 |
+
if State.dff.value is not None:
|
91 |
+
def get_data():
|
92 |
+
return State.dff.value.to_csv(index=False)
|
93 |
+
|
94 |
+
solara.FileDownload(get_data,
|
95 |
+
label=f"Download {len(State.dff.value):,} converted coordinates",
|
96 |
+
filename="converted.csv", )
|
97 |
+
|
98 |
+
if State.df.value is not None:
|
99 |
+
with solara.Column():
|
100 |
+
solara.DataFrame(State.df.value)
|
101 |
+
if State.error_message.value != "":
|
102 |
+
solara.Warning(State.error_message.value)
|
103 |
+
else:
|
104 |
+
solara.Info("Waiting for Data, Please upload a file.")
|
105 |
+
|
106 |
+
|
107 |
+
# @solara.component
|
108 |
+
# def Layout(children):
|
109 |
+
# route, routes = solara.use_route()
|
110 |
+
# return solara.AppLayout(children=children)
|
requirements.txt
CHANGED
@@ -3,3 +3,5 @@ leafmap
|
|
3 |
mapwidget
|
4 |
solara
|
5 |
geopandas
|
|
|
|
|
|
3 |
mapwidget
|
4 |
solara
|
5 |
geopandas
|
6 |
+
pandas
|
7 |
+
lat-lon-parser
|