summaryrefslogtreecommitdiffstats
path: root/photomap/pmap.py
diff options
context:
space:
mode:
authorPhilip Sargent <philip.sargent@gmail.com>2023-10-20 00:36:15 +0300
committerPhilip Sargent <philip.sargent@gmail.com>2023-10-20 00:36:15 +0300
commita823a7b2d85a2aa4548f36b1b5d36feee6ea26c6 (patch)
treec44e9999fc0d6e726cfa90fd101f9fd17d9171ae /photomap/pmap.py
parent0874ca38f45ba3754a9ec391053cf8d238e3653b (diff)
downloadtroggle-a823a7b2d85a2aa4548f36b1b5d36feee6ea26c6.tar.gz
troggle-a823a7b2d85a2aa4548f36b1b5d36feee6ea26c6.tar.bz2
troggle-a823a7b2d85a2aa4548f36b1b5d36feee6ea26c6.zip
New geocoding photos
Diffstat (limited to 'photomap/pmap.py')
-rw-r--r--photomap/pmap.py46
1 files changed, 37 insertions, 9 deletions
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 = """<?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')
+