Google maps url to the coordinates

#9
by ybendou - opened
Files changed (1) hide show
  1. app.py +11 -30
app.py CHANGED
@@ -8,7 +8,6 @@ import streamlit as st
8
  from streamlit_folium import st_folium
9
  from utils import legend_macro
10
  from huggingface_hub import HfApi
11
- from folium import plugins
12
 
13
 
14
  TOKEN = os.environ.get("HF_TOKEN", None)
@@ -94,33 +93,28 @@ def parse_latlng_from_link(url):
94
  return None
95
 
96
  def parse_gg_sheet_interventions(url):
97
- url = url.replace("edit#gid=", "export?format=csv&gid=")
98
- print(url)
99
- df = pd.read_csv(url, on_bad_lines='skip')
100
  return df.assign(latlng=df.iloc[:, 3].apply(parse_latlng_from_link))
101
 
102
  def parse_gg_sheet(url):
103
  url = url.replace("edit#gid=", "export?format=csv&gid=")
104
- print(url)
105
- df = pd.read_csv(url, on_bad_lines='warn')
106
 
107
  # parse latlng (column 4) to [lat, lng]
108
  def parse_latlng(latlng):
109
  try:
110
  lat, lng = latlng.split(",")
111
  return [float(lat), float(lng)]
112
- except Exception as e:
113
- print(f"Error parsing latlng: {e}")
114
- return None
115
- if df.shape[1] > 4:
116
- df = df.assign(latlng=df.iloc[:, 4].apply(parse_latlng))
117
- return df
118
 
119
  df = parse_gg_sheet(
120
  "https://docs.google.com/spreadsheets/d/1gYoBBiBo1L18IVakHkf3t1fOGvHWb23loadyFZUeHJs/edit#gid=966953708"
121
  )
122
  interventions_df = parse_gg_sheet_interventions(
123
- "https://docs.google.com/spreadsheets/d/1eXOTqunOWWP8FRdENPs4cU9ulISm4XZWYJJNR1-SrwY/edit#gid=2089222765"
124
  )
125
 
126
  # select requests
@@ -178,21 +172,6 @@ m = folium.Map(
178
  max_bounds=True,
179
  )
180
 
181
- # Add a search bar to the map
182
- plugins.Geocoder(
183
- collapsed=False,
184
- position="topright",
185
- placeholder="Search | البحث",
186
- ).add_to(m)
187
-
188
- # Add Fullscreen button to the map
189
- plugins.Fullscreen(
190
- position='topright',
191
- title='Expand me | تكبير الخريطة',
192
- title_cancel='Exit me | تصغير الخريطة',
193
- force_separate_button=True
194
- ).add_to(m)
195
-
196
  #Satellite View from Mapbox
197
  tileurl = 'https://api.mapbox.com/styles/v1/phd2020/clmer2mra01d001pbgjkictpt/tiles/256/{z}/{x}/{y}@2x?access_token=pk.eyJ1IjoicGhkMjAyMCIsImEiOiJja29lZzFwZmUwNHkzMm5wMjZnYjVvcGltIn0.tE0ritrelQOyLdKUH6hgOw'
198
 
@@ -228,7 +207,9 @@ if show_interventions:
228
 
229
  for index, row in filtered_df.iterrows():
230
  request_type = row['ما هي احتياجاتك؟ (أضفها إذا لم يتم ذكرها)']
231
- display_text = f"<b>Request Type:</b> {request_type}<br><b>Id:</b> {row['id']}"
 
 
232
  icon_name = icon_mapping.get(request_type, 'info-sign')
233
  if row["latlng"] is None:
234
  continue
@@ -302,4 +283,4 @@ st.markdown(
302
  )
303
  if auto_refresh:
304
  time.sleep(number)
305
- st.experimental_rerun()
 
8
  from streamlit_folium import st_folium
9
  from utils import legend_macro
10
  from huggingface_hub import HfApi
 
11
 
12
 
13
  TOKEN = os.environ.get("HF_TOKEN", None)
 
93
  return None
94
 
95
  def parse_gg_sheet_interventions(url):
96
+ df = pd.read_csv(url)
 
 
97
  return df.assign(latlng=df.iloc[:, 3].apply(parse_latlng_from_link))
98
 
99
  def parse_gg_sheet(url):
100
  url = url.replace("edit#gid=", "export?format=csv&gid=")
101
+ df = pd.read_csv(url)
 
102
 
103
  # parse latlng (column 4) to [lat, lng]
104
  def parse_latlng(latlng):
105
  try:
106
  lat, lng = latlng.split(",")
107
  return [float(lat), float(lng)]
108
+ except Exception:
109
+ return parse_latlng_from_link(latlng)
110
+
111
+ return df.assign(latlng=df.iloc[:, 4].apply(parse_latlng))
 
 
112
 
113
  df = parse_gg_sheet(
114
  "https://docs.google.com/spreadsheets/d/1gYoBBiBo1L18IVakHkf3t1fOGvHWb23loadyFZUeHJs/edit#gid=966953708"
115
  )
116
  interventions_df = parse_gg_sheet_interventions(
117
+ "https://docs.google.com/spreadsheets/d/1eXOTqunOWWP8FRdENPs4cU9ulISm4XZWYJJNR1-SrwY/gviz/tq?tqx=out:csv"
118
  )
119
 
120
  # select requests
 
172
  max_bounds=True,
173
  )
174
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  #Satellite View from Mapbox
176
  tileurl = 'https://api.mapbox.com/styles/v1/phd2020/clmer2mra01d001pbgjkictpt/tiles/256/{z}/{x}/{y}@2x?access_token=pk.eyJ1IjoicGhkMjAyMCIsImEiOiJja29lZzFwZmUwNHkzMm5wMjZnYjVvcGltIn0.tE0ritrelQOyLdKUH6hgOw'
177
 
 
207
 
208
  for index, row in filtered_df.iterrows():
209
  request_type = row['ما هي احتياجاتك؟ (أضفها إذا لم يتم ذكرها)']
210
+ long_lat = row['هل يمكنك تقديم الإحداثيات الدقيقة للموقع؟ (ادا كنت لا توجد بعين المكان) متلاً 31.01837503440344,-6.781405948842175']
211
+ maps_url = f"https://maps.google.com/?q={long_lat}"
212
+ display_text = f'<b>Request Type:</b> {request_type}<br><b>Id:</b> {row["id"]}<br><a href="{maps_url}"><b>Google Maps</b></a>'
213
  icon_name = icon_mapping.get(request_type, 'info-sign')
214
  if row["latlng"] is None:
215
  continue
 
283
  )
284
  if auto_refresh:
285
  time.sleep(number)
286
+ st.experimental_rerun()