Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,14 +14,14 @@ def load_geojson_data(file_paths):
|
|
| 14 |
geodata.append(gdf)
|
| 15 |
return geodata
|
| 16 |
|
| 17 |
-
|
| 18 |
polygon_geojson = json.loads("""
|
| 19 |
{
|
| 20 |
"type": "FeatureCollection",
|
| 21 |
"features": [
|
| 22 |
{
|
| 23 |
"type": "Feature",
|
| 24 |
-
"properties": {},
|
| 25 |
"geometry": {
|
| 26 |
"type": "Polygon",
|
| 27 |
"coordinates": [[[79.486114,27.577006],[79.5157554,27.5646727],[79.5405574,27.5461701],[79.5695939,27.519081],[79.5756432,27.4938634],[79.5593101,27.4871556],[79.5308786,27.5257868],[79.5003298,27.5319559],[79.4849041,27.5456337],[79.4761327,27.5652089],[79.486114,27.577006]]]
|
|
@@ -36,18 +36,34 @@ st.sidebar.title("Geospatial Data Visualization")
|
|
| 36 |
timestamp = st.sidebar.select_slider("Time", options=[f"{year}-01" for year in range(2016, 2024)])
|
| 37 |
|
| 38 |
# Main title
|
| 39 |
-
st.title("
|
| 40 |
|
| 41 |
|
| 42 |
-
geojson_file_paths = ['
|
| 43 |
geojson_data = load_geojson_data(geojson_file_paths)
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
all_geo_data['lon'] = all_geo_data.geometry.centroid.x
|
| 48 |
all_geo_data['lat'] = all_geo_data.geometry.centroid.y
|
| 49 |
|
| 50 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
polygon_layer = pdk.Layer(
|
| 52 |
"PolygonLayer",
|
| 53 |
all_geo_data,
|
|
@@ -58,37 +74,28 @@ polygon_layer = pdk.Layer(
|
|
| 58 |
auto_highlight=True
|
| 59 |
)
|
| 60 |
|
| 61 |
-
#
|
| 62 |
-
heatmap_layer = pdk.Layer(
|
| 63 |
-
"HeatmapLayer",
|
| 64 |
-
all_geo_data,
|
| 65 |
-
get_position=['lon', 'lat'],
|
| 66 |
-
aggregation=pdk.types.String("MEAN"),
|
| 67 |
-
opacity=0.5
|
| 68 |
-
)
|
| 69 |
-
|
| 70 |
-
# Set the viewport location
|
| 71 |
view_state = pdk.ViewState(
|
| 72 |
latitude=27.5,
|
| 73 |
longitude=79.5,
|
| 74 |
zoom=6,
|
| 75 |
-
pitch=
|
| 76 |
)
|
| 77 |
|
| 78 |
-
|
| 79 |
r = pdk.Deck(
|
| 80 |
-
layers=[
|
| 81 |
initial_view_state=view_state,
|
| 82 |
map_style='mapbox://styles/mapbox/satellite-v9'
|
| 83 |
)
|
| 84 |
|
| 85 |
-
|
| 86 |
st.pydeck_chart(r)
|
| 87 |
|
| 88 |
# Add an informational box
|
| 89 |
with st.expander("View Information"):
|
| 90 |
st.write(f"Selected Time: {timestamp}")
|
| 91 |
num_points = len(all_geo_data)
|
| 92 |
-
total_area = all_geo_data.geometry.area.sum()
|
| 93 |
st.write(f"Number of Features: {num_points}")
|
| 94 |
st.write(f"Total Area: {total_area:.2f} sq km")
|
|
|
|
| 14 |
geodata.append(gdf)
|
| 15 |
return geodata
|
| 16 |
|
| 17 |
+
# Sample Polygon GeoJSON
|
| 18 |
polygon_geojson = json.loads("""
|
| 19 |
{
|
| 20 |
"type": "FeatureCollection",
|
| 21 |
"features": [
|
| 22 |
{
|
| 23 |
"type": "Feature",
|
| 24 |
+
"properties": {"density": 10},
|
| 25 |
"geometry": {
|
| 26 |
"type": "Polygon",
|
| 27 |
"coordinates": [[[79.486114,27.577006],[79.5157554,27.5646727],[79.5405574,27.5461701],[79.5695939,27.519081],[79.5756432,27.4938634],[79.5593101,27.4871556],[79.5308786,27.5257868],[79.5003298,27.5319559],[79.4849041,27.5456337],[79.4761327,27.5652089],[79.486114,27.577006]]]
|
|
|
|
| 36 |
timestamp = st.sidebar.select_slider("Time", options=[f"{year}-01" for year in range(2016, 2024)])
|
| 37 |
|
| 38 |
# Main title
|
| 39 |
+
st.title("Hexagon and Polygon view:")
|
| 40 |
|
| 41 |
|
| 42 |
+
geojson_file_paths = ['chambal_centroids.geojson','kathajodi_centroids.geojson']
|
| 43 |
geojson_data = load_geojson_data(geojson_file_paths)
|
| 44 |
|
| 45 |
+
|
| 46 |
+
if geojson_data:
|
| 47 |
+
all_geo_data = pd.concat(geojson_data + [gpd.GeoDataFrame.from_features(polygon_geojson["features"])])
|
| 48 |
+
else:
|
| 49 |
+
all_geo_data = gpd.GeoDataFrame.from_features(polygon_geojson["features"])
|
| 50 |
+
|
| 51 |
+
# Add centroid coordinates to all_geo_data
|
| 52 |
all_geo_data['lon'] = all_geo_data.geometry.centroid.x
|
| 53 |
all_geo_data['lat'] = all_geo_data.geometry.centroid.y
|
| 54 |
|
| 55 |
+
# Hexagon Layer
|
| 56 |
+
hexagon_layer = pdk.Layer(
|
| 57 |
+
"HexagonLayer",
|
| 58 |
+
all_geo_data,
|
| 59 |
+
get_position=['lon', 'lat'],
|
| 60 |
+
elevation_scale=50,
|
| 61 |
+
radius=2000,
|
| 62 |
+
elevation_range=[0, 3000],
|
| 63 |
+
pickable=True,
|
| 64 |
+
extruded=True,
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
polygon_layer = pdk.Layer(
|
| 68 |
"PolygonLayer",
|
| 69 |
all_geo_data,
|
|
|
|
| 74 |
auto_highlight=True
|
| 75 |
)
|
| 76 |
|
| 77 |
+
# Set viewport location
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
view_state = pdk.ViewState(
|
| 79 |
latitude=27.5,
|
| 80 |
longitude=79.5,
|
| 81 |
zoom=6,
|
| 82 |
+
pitch=40
|
| 83 |
)
|
| 84 |
|
| 85 |
+
|
| 86 |
r = pdk.Deck(
|
| 87 |
+
layers=[hexagon_layer, polygon_layer],
|
| 88 |
initial_view_state=view_state,
|
| 89 |
map_style='mapbox://styles/mapbox/satellite-v9'
|
| 90 |
)
|
| 91 |
|
| 92 |
+
|
| 93 |
st.pydeck_chart(r)
|
| 94 |
|
| 95 |
# Add an informational box
|
| 96 |
with st.expander("View Information"):
|
| 97 |
st.write(f"Selected Time: {timestamp}")
|
| 98 |
num_points = len(all_geo_data)
|
| 99 |
+
total_area = all_geo_data.geometry.area.sum()
|
| 100 |
st.write(f"Number of Features: {num_points}")
|
| 101 |
st.write(f"Total Area: {total_area:.2f} sq km")
|