1
1
import math
2
- import os
3
2
import random
4
3
5
- import config
6
4
import folium
7
5
import osmnx as ox
8
6
9
7
10
- def get_rotated_preview (lat : float , lon : float , distance : int , angle : int ):
8
+ def get_rotated_preview (lat : float , lon : float , distance : int , angle : int ) -> folium . Map :
11
9
"""Return the path to the HTML file where the OpenStreetMap data is saved.
12
10
13
11
Arguments:
@@ -17,12 +15,8 @@ def get_rotated_preview(lat: float, lon: float, distance: int, angle: int):
17
15
angle (int): Angle of rotation in degrees.
18
16
19
17
Returns:
20
- str: Path to the HTML file .
18
+ folium.Map: Folium map object .
21
19
"""
22
- save_path = get_rotated_save_path (lat , lon , distance , angle )
23
- if os .path .isfile (save_path ):
24
- return save_path
25
-
26
20
m = folium .Map (zoom_control = False )
27
21
28
22
url = "https://mt0.google.com/vt/lyrs=s&hl=en&x={x}&y={y}&z={z}&s=Ga"
@@ -56,15 +50,18 @@ def get_rotated_preview(lat: float, lon: float, distance: int, angle: int):
56
50
center = get_center (bbox )
57
51
folium .CircleMarker (center , radius = 1 , color = color , fill = True ).add_to (m )
58
52
59
- m . save ( save_path )
60
- return save_path
53
+ return m
54
+
61
55
56
+ def get_preview (bboxes : list [tuple [float , float , float , float ]]) -> folium .Map :
57
+ """Returns the folium map object with the bounding boxes.
62
58
63
- def get_preview (bboxes : list [tuple [float , float , float , float ]]) -> str :
64
- save_path = get_save_path (bboxes )
65
- if os .path .isfile (save_path ):
66
- return save_path
59
+ Arguments:
60
+ bboxes (list[tuple[float, float, float, float]]): List of bounding boxes.
67
61
62
+ Returns:
63
+ folium.Map: Folium map object.
64
+ """
68
65
m = folium .Map (zoom_control = False )
69
66
70
67
for bbox in bboxes :
@@ -86,8 +83,7 @@ def get_preview(bboxes: list[tuple[float, float, float, float]]) -> str:
86
83
# Fit bounds to the last bbox in the list.
87
84
m .fit_bounds ([[south , west ], [north , east ]])
88
85
89
- m .save (save_path )
90
- return save_path
86
+ return m
91
87
92
88
93
89
def get_random_color () -> str :
@@ -105,53 +101,3 @@ def get_bbox(center: tuple[float, float], size_meters: int) -> tuple[float, floa
105
101
(center_lat , center_lon ), size_meters / 2 , project_utm = False
106
102
)
107
103
return north , south , east , west
108
-
109
-
110
- def get_save_path (bboxes : list [tuple [float , float , float , float ]]) -> str :
111
- """Return the path to the HTML file where the OpenStreetMap data is saved.
112
-
113
- Arguments:
114
- lat (float): Latitude of the central point.
115
- lon (float): Longitude of the central point.
116
- size_meters (int): Width of the bounding box in meters.
117
- postfix (str): Optional postfix to add to the filename.
118
-
119
- Returns:
120
- str: Path to the HTML file.
121
- """
122
- file_names = [format_coordinates (bbox ) for bbox in bboxes ]
123
- filename = "_" .join (file_names ) + ".html"
124
- return os .path .join (
125
- config .OSMPS_DIRECTORY ,
126
- filename ,
127
- )
128
-
129
-
130
- def get_rotated_save_path (lat : float , lon : float , size_meters : int , angle : int ) -> str :
131
- """Return the path to the HTML file where the OpenStreetMap data is saved.
132
-
133
- Arguments:
134
- lat (float): Latitude of the central point.
135
- lon (float): Longitude of the central point.
136
- size_meters (int): Width of the bounding box in meters.
137
- angle (int): Angle of rotation in degrees.
138
-
139
- Returns:
140
- str: Path to the HTML file.
141
- """
142
- return os .path .join (
143
- config .OSMPS_DIRECTORY ,
144
- f"{ lat } _{ lon } _{ size_meters } _{ angle } .html" ,
145
- )
146
-
147
-
148
- def format_coordinates (bbox : tuple [float , float , float , float ]) -> str :
149
- """Return a string representation of the coordinates.
150
-
151
- Arguments:
152
- bbox (tuple[float, float, float, float]): The bounding box coordinates.
153
-
154
- Returns:
155
- str: String representation of the coordinates.
156
- """
157
- return "_" .join (map (str , bbox ))
0 commit comments