Can I batch geotag JPEGs from a CSV by matching each photo’s keyword or ID?
Asked 11/21/2022
1 views
2 answers
0
I have many JPEG photos that need GPS coordinates added. Separately, I have a CSV lookup table with a unique ID for each photographed object and its X/Y coordinates. My goal is to manually add the matching ID as a keyword/tag to each photo, then batch-apply the correct GPS data from the CSV so the images can later be shown as accurately placed points in QGIS.
Example CSV structure: ID, X, Y.
Is there a relatively simple workflow to match a photo’s tag/keyword to the CSV entry, convert those coordinates if needed, and write proper EXIF GPS data to each image without renaming the files?
Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0
Photography Stack Exchange contributor
3y ago
2 Answers
2
It seems your main problem is:
How can I show photos on a map in QGIS?
You have the following at your disposal:
- A set of photos
- A lookup table with IPTC keywords and their corresponding coordinates (in the EPSG:25832 coordinate system)
This can be divided into the following sub-problems:
- Identify which keyword(s) a photo has
- If one of the keywords of the photo matches one in the lookup table:
- Lookup the coordinates that corresponds with that tag
- Reproject the EPSG:25832 coordinates to WGS84 (EPSG:4326) latitude and longitude coordinates
- Convert the lat/lon coordinates to a format suitable for the EXIF GPS tag
- Write the EXIF GPS tag of the photo
- Read in the photo into a QGIS map
The stackexchange network is not a coding service, so I cannot provide you with ready to go scripts, but I have suggestions on how to solve the sub-problems.
1. Identify which keyword(s) a photo has
- Using ExifTool, no need to install, it's a self-contained executable.
- Using a Python library such as:
- exif
- PyExifTool
- Pillow using the
_getexif()method
2a. Lookup the coordinates that corresponds with that tag
This can be done in a myriad of ways, but I am familiar with Python where you can e.g. use a dictionary to store your lookup table:
lookup = {
'A4166': [546043.0552, 6189132.4628],
'A4165': [546031.2343, 6189128.3107],
etc...
}
Alternatively you could use a pandas DataFrame:
import pandas as pd
lookup = pd.read_csv('/path/to/file.csv')
coords = lookup.loc[lookup.ID == 'A4166']
2b. Reproject the EPSG:25832 coordinates to WSG84
Again, many ways, but in Python I would use geopandas to do any kind of reprojecting of coordinates. Assuming you would have used a Dataframe in the previous step:
import geopandas as gpd
gdf = gpd.GeoDataFrame(lookup, geometry=gpd.points_from_xy(lookup.X, lookup.Y)
# Let geopandas know that the data is in EPSG:25832
gdf.set_crs(epsg=25832)
# Reproject it to
gdf.to_crs(epsg=4326, inplace=True)
Now you have a lookup table in the variable gdf with the coordinates in the WGS84 coordinate system.
2c. Convert the lat/lon coordinates to a format suitable for the EXIF GPS tag
The ExifTool documentation describes how the GPS tags look. You will have to create some conditions based on the coordinate sign on when to write N or S in the GPSLatitudeRef and E or W in the GPSLongitudeRef fields.
2d. Write the EXIF GPS tag of the photo
The same libraries from step 2a can be used to write to the appropriate fields.
3. Read in the photo into a QGIS map
This tutorial was the first hit on Google when I looked for "place photos in QGIS". Roughly the steps are:
- Import Geotagged Photos via Processing Toolbar > Vector Creation > Import Geotagged Photos
- View photos in popup: set the HTML Map Tip in the Display property of the layer to:
<img src="file:///[% photo %]" width="350" height="250">
If you run into any issues with solving one of the sub-problems you are very welcome to edit your question (or post a new one) showing what you've tried and where you get stuck.
Originally by user9161. Source · Licensed CC BY-SA 4.0
user9161
3y ago
0
Generated from our catalog & community — verify before relying on it.
Yes—this is possible in principle, but it’s a metadata workflow rather than a simple one-click photo feature.
The basic process is:
- Add a unique keyword/ID to each photo.
- Use that keyword to match each image to the corresponding row in your CSV.
- Look up the stored X/Y coordinates.
- If those coordinates are not already WGS84 latitude/longitude, reproject them to EPSG:4326.
- Convert the result into the format required for EXIF GPS tags.
- Write the GPS metadata into each JPEG.
You do not need to rename the photos if you use keywords/tags as the match field.
The key limitation is that this usually requires metadata tooling or scripting to read the photo keywords, match them against the CSV, and write EXIF GPS fields. Once the GPS tags are written correctly, QGIS can use the photos as mapped points.
So: yes, your proposed keyword-to-CSV workflow is valid, but expect to use a metadata utility and possibly a small custom script or batch process.
Recommended products
UniqueBot
AI3y ago
Your Answer
Related Questions
How can I batch geotag JPGs from a CSV of filenames and coordinates on Windows?
Can I use Google Location History to geotag photos from a non-GPS camera?
How can I batch-add keywords to JPEG files from a database before importing into Lightroom?
How can I turn a photo's GPS coordinates into location keywords automatically?
How can I derive cyan, magenta, and yellow chromaticity coordinates from known RGB primaries on a CIE xy diagram?