mirror of
https://expo.survex.com/repositories/troggle/.git
synced 2026-02-08 11:28:23 +00:00
New geocoding photos
This commit is contained in:
@@ -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 = """<?xml version="1.0" encoding="windows-1252"?>
|
||||
<gpx version="1.0" creator="troggle pmap"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://www.topografix.com/GPX/1/0"
|
||||
xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd">
|
||||
<name>pmap photo GPS</name>
|
||||
<desc>Troggle photos archive</desc>
|
||||
"""
|
||||
with open(save_gpx, "w") as f:
|
||||
f.write(header)
|
||||
for p in photoset:
|
||||
photo_path, latitude, longitude = p
|
||||
f.write(f'<wpt lat="{latitude:.6f}" lon="{longitude:.6f}"> <name>[{photo_path.stem}]</name><type>photo</type><desc>{str(photo_path).replace(str(photo_folder),"")}</desc></wpt>\n')
|
||||
f.write(f'</gpx>\n')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user