I have hundreds of geotagged JPEG photos, with camera default naming, that are taken somewhere out there but always inside the borders of a shapefile. I need to rename them all with the shapefile id field (or other field).
Is there any reasonable way to do this? Other than manually go through every (shocking job). I have QGIS 3.24.2.
Add the attribute (that will be used to rename the photo) of the polygon to the point. There are meany ways to do this, but the easiest maybe is to use the Join attributes by location tool. It should look like this:
where New scratch layer is the polygon layer and in Fields to add you must set the field that contains the new name (in my screenshot is empty because i had only one field).
Now you have a table with some properties of the photos (one of this the path) and the polygon to which it belongs. There's a problem, when more than one image has been taken in the same polygon they will have the same value in the field that will be used to rename them. So it will be necessary to create an Id that will be joined with the value of the field from the polygon. To do this, open the field calculator in the joined layer and calculate a new string field (please name it New_name for simplicity) and paste this expression:
Replace Polygon with the name of the field that was joined from the polygons layer. It should look something like this:
Now we have a table containing the path to the photo and the new name. To rename this photos I will use a simple script in python. Paste the following python script in the QGIS python console and remember to set the joined layer name.
project = QgsProject.instance()
p_layer_name = '' # put inside the quotes the name of the joined layer
p_layer = project.mapLayersByName(p_layer_name)
for point in p_layer.getFeatures():
os.rename(point['photo'], os.path.join(point['directory'], point['New_name'] + '.jpg'))