Commit fcd06b1b authored by Моисеев Николай Денисович's avatar Моисеев Николай Денисович
Browse files

feat: add modern parser

parent e4673091
No related merge requests found
Showing with 73 additions and 0 deletions
+73 -0
import osmnx as ox
from typing import List, Tuple
from PIL import Image
import streetview
def get_points_from_coordinates(
start_lat: float,
start_lon: float,
end_lat: float,
end_lon: float
) -> List[Tuple[float, float]]:
north = max(start_lat, end_lat) + 0.01
south = min(start_lat, end_lat) - 0.01
east = max(start_lon, end_lon) + 0.01
west = min(start_lon, end_lon) - 0.01
graph = ox.graph_from_bbox(
(west, south, east, north),
network_type='drive'
)
start = ox.distance.nearest_nodes(graph, start_lon, start_lat)
end = ox.distance.nearest_nodes(graph, end_lon, end_lat)
route = ox.shortest_path(graph, start, end)
if not route:
return []
gdf = ox.routing.route_to_gdf(graph, route)
points = [i[::-1] for i in gdf.geometry.iloc[0].coords]
for row in gdf.geometry.iloc[1:]:
mas = [i[::-1] for i in row.coords[1:]]
points += mas
return points
def download_pano_images(
start_lat: float,
start_lon: float,
end_lat: float,
end_lon: float,
folder: str
) -> int:
points = get_points_from_coordinates(start_lat, start_lon, end_lat, end_lon)
panoids_buffer = []
print(len(points))
for point in points:
panoids = streetview.panoids(lat=point[0], lon=point[1], closest=True)
if len(panoids) == 0 or panoids[-1]["panoid"] in panoids_buffer:
continue
panorama = streetview.download_panorama_v3(panoids[-1]['panoid'], zoom=2, disp=False)
panoids_buffer.append(panoids[-1]['panoid'])
image = Image.fromarray(panorama)
image.save(f"{folder}/{panoids[-1]['lat']}_{panoids[-1]['lon']}.png")
return len(points)
lat, lon = 55.64735005518794, 37.74272522210102
lat2, lon2 = 55.64709648470947, 37.72037420394722
download_pano_images(lat, lon, lat2, lon2, "test_2")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment