-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfolium_utils.py
37 lines (34 loc) · 1.67 KB
/
folium_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import geopandas as gpd
import tkinter as tk
def calculate_bounding_box(geojson_data):
# Initialize the bounding box values
min_lng, min_lat, max_lng, max_lat = float('inf'), float('inf'), float('-inf'), float('-inf')
# Iterate over the features in the GeoJSON data
for feature in geojson_data['features']:
coords = feature['geometry']['coordinates']
if feature['geometry']['type'] == 'Point':
lng, lat = coords
min_lng, max_lng = min(min_lng, lng), max(max_lng, lng)
min_lat, max_lat = min(min_lat, lat), max(max_lat, lat)
elif feature['geometry']['type'] in ['LineString', 'MultiPoint']:
for point in coords:
lng, lat = point
min_lng, max_lng = min(min_lng, lng), max(max_lng, lng)
min_lat, max_lat = min(min_lat,lat),max(max_lat,lat)
elif feature['geometry']['type'] in ['Polygon', 'MultiLineString']:
for ring in coords:
for point in ring:
lng,lat=point
min_lng,max_lng=min(min_lng,lng),max(max_lng,lng)
min_lat,max_lat=min(min_lat,lat),max(max_lat,lat)
elif feature['geometry']['type']=='MultiPolygon':
for polygon in coords:
for ring in polygon:
for point in ring:
lng,lat=point
min_lng,max_lng=min(min_lng,lng),max(max_lng,lng)
min_lat,max_lat=min(min_lat,lat),max(max_lat,lat)
# Return the bounding box values
return (min_lng, min_lat, max_lng, max_lat)
def style_function(feature):
return feature['properties'].get('style', {})