OttoYu commited on
Commit
68d8d22
·
verified ·
1 Parent(s): 9f984f0

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +85 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import folium
3
+ from streamlit_folium import folium_static
4
+ import requests
5
+ import json
6
+ import geopandas as gpd
7
+
8
+ st.set_page_config(page_title="No Fly Zones Map", layout="wide")
9
+
10
+ @st.cache_data
11
+ def fetch_data():
12
+ url = "https://esua.cad.gov.hk/web/droneMap/getData"
13
+ try:
14
+ response = requests.get(url)
15
+ response.raise_for_status()
16
+ return response.json() # Directly parse JSON response
17
+ except requests.RequestException as e:
18
+ st.error(f"Error fetching data: {e}")
19
+ return None
20
+
21
+
22
+ def parse_json_data(json_data):
23
+ geojson_list = []
24
+
25
+ try:
26
+ # Extract the list of GeoJSON features from the JSON data
27
+ rfz_features = json_data.get('data', {}).get('rfzFeatures', [])
28
+ for feature_str in rfz_features:
29
+ try:
30
+ geojson = json.loads(feature_str) # Parse the GeoJSON string
31
+ geojson_list.append(geojson)
32
+ except json.JSONDecodeError as e:
33
+ st.warning(f"Could not parse GeoJSON from feature: {feature_str[:100]}... Error: {e}")
34
+
35
+ except Exception as e:
36
+ st.error(f"Error processing JSON data: {e}")
37
+
38
+ return geojson_list
39
+
40
+
41
+ def main():
42
+ st.subheader("Restricted Flying Zones (“RFZ”) from Civil Aviation Department")
43
+ # Fetch data
44
+ with st.spinner("Fetching data..."):
45
+ json_data = fetch_data()
46
+
47
+ if json_data:
48
+ geojson_list = parse_json_data(json_data)
49
+
50
+ if geojson_list:
51
+ m = folium.Map(location=[22.3193, 114.1694], zoom_start=11,
52
+ tiles='https://landsd.azure-api.net/dev/osm/xyz/basemap/gs/WGS84/tile/{z}/{x}/{y}.png?key=f4d3e21d4fc14954a1d5930d4dde3809',
53
+ attr="Map information from Lands Department")
54
+
55
+ folium.TileLayer(
56
+ tiles='https://mapapi.geodata.gov.hk/gs/api/v1.0.0/xyz/label/hk/en/wgs84/{z}/{x}/{y}.png',
57
+ attr="Map Map information from Lands Department"
58
+ ).add_to(m)
59
+
60
+ for geojson in geojson_list:
61
+ gdf = gpd.GeoDataFrame.from_features(geojson['features'])
62
+
63
+ # Set the CRS to EPSG:4326 (WGS 84)
64
+ gdf.set_crs(epsg=4326, inplace=True)
65
+
66
+ folium.GeoJson(
67
+ gdf,
68
+ style_function=lambda feature: {
69
+ 'fillColor': 'red',
70
+ 'color': 'black',
71
+ 'weight': 2,
72
+ 'fillOpacity': 0.3,
73
+ },
74
+ tooltip=folium.GeoJsonTooltip(fields=['name'], aliases=['Name'], localize=True)
75
+ ).add_to(m)
76
+
77
+ folium_static(m, width=1200, height=800)
78
+ else:
79
+ st.error("No valid GeoJSON data found in the response.")
80
+ else:
81
+ st.error("Failed to fetch data. Please try again later.")
82
+ st.write("Restricted Flying Zones (“RFZ”) reflected in this drone map are designated by the Small Unmanned Aircraft Order (Cap. 448G). In connection to other restricted areas/ zones under other legislation or regulation such as the Air Navigation (Flight Prohibition) Order (Cap. 448E), users should refer to other maps for information.")
83
+
84
+ if __name__ == "__main__":
85
+ main()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ folium==0.17.0
2
+ geopandas==1.0.1
3
+ Requests==2.32.3
4
+ streamlit==1.37.1
5
+ streamlit_folium==0.22.0