From a823a7b2d85a2aa4548f36b1b5d36feee6ea26c6 Mon Sep 17 00:00:00 2001 From: Philip Sargent Date: Fri, 20 Oct 2023 00:36:15 +0300 Subject: New geocoding photos --- photomap/pmap.py | 46 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) (limited to 'photomap/pmap.py') diff --git a/photomap/pmap.py b/photomap/pmap.py index 8f6fc1a..1fae89d 100644 --- a/photomap/pmap.py +++ b/photomap/pmap.py @@ -2,6 +2,7 @@ import os import folium from pathlib import Path from PIL import Image, ExifTags +from itertools import chain """To do - create gpx file for adding in to existing GPSprune maps @@ -58,20 +59,30 @@ def get_coordinates(photo_path): # Specify the folder containing the photos -photo_folder = Path("../../expoweb") +#photo_folder = Path("../../expoweb") photo_folder = Path("/mnt/d/EXPO/PHOTOS") +#photo_folder = Path("/mnt/d/EXPO/PHOTOS/2019") +#photo_folder = Path("/mnt/d/EXPO/PHOTOS/2022/JonoL") # jpeg +save_gpx = "photos_jpg.gpx" + +# these are generators, not lists +photosjpg = photo_folder.rglob("*.jpg") +photosjpeg = photo_folder.rglob("*.jpeg") +photos = chain(photosjpg, photosjpeg) -photos = photo_folder.rglob("*.jpg") -# for p in photos: - # print(p) # Initialize a Folium map centered at an initial location map = folium.Map(location=[47.691036, 13.821314], zoom_start=13) photoset = [] # Iterate through photos in the folder -for filename in photos: # os.listdir(photo_folder): - photo_path = filename #os.path.join(photo_folder, filename) +for photo_path in photos: + if photo_path.stem.startswith("slide_"): + #print(f" - abort slide") + continue + if photo_path.stem.startswith("thumb_"): + #print(f" - abort thumb") + continue # Extract latitude, longitude, and address from photo latitude, longitude = get_coordinates(photo_path) @@ -81,10 +92,27 @@ for filename in photos: # os.listdir(photo_folder): # Create a marker for each photo with its location and address folium.Marker( location=[latitude, longitude], - popup=f"{filename}", + popup=f"{photo_path}", icon=folium.Icon(color="red", icon="camera"), ).add_to(map) - photoset.append(filename) + photoset.append((photo_path, latitude, longitude)) + # Save the map as an HTML file -map.save("photo_map.html") +map.save("photo_map_jpeg.html") print(f"Found {len(photoset)} GPS located photos in '{photo_folder}' and subdirectories.") + +header = """ + + pmap photo GPS + Troggle photos archive +""" +with open(save_gpx, "w") as f: + f.write(header) + for p in photoset: + photo_path, latitude, longitude = p + f.write(f' [{photo_path.stem}]photo{str(photo_path).replace(str(photo_folder),"")}\n') + f.write(f'\n') + -- cgit v1.2.3