PIL Solution
Add three new fields (real type) named "fyd", "gyd", "ra" (fyd: FlightYawDegree, gyd: GimbalYawDegree, ra: RelativeAltitude)
Copy/paste the script to QGIS Python Editor (not to Console), select layer (important) and run.
from xml.etree import ElementTree as ET
layer = iface.activeLayer()
dpr = layer.dataProvider()
fyd_ind = layer.fields().indexFromName("fyd")
gyd_ind = layer.fields().indexFromName("gyd")
ra_ind = layer.fields().indexFromName("ra")
for feature in layer.getFeatures():
file_path = feature["Path"]
print(file_path)
with open(file_path, "rb") as f:
s = str(f.read())
start = s.find('<x:xmpmeta')
end = s.find('</x:xmpmeta')
xmp = s[start:end+12].replace("\\n","\n")
tree = ET.XML(xmp)
fyd = tree[0][0].attrib['{http://www.dji.com/drone-dji/1.0/}FlightYawDegree']
gyd = tree[0][0].attrib['{http://www.dji.com/drone-dji/1.0/}GimbalYawDegree']
ra = tree[0][0].attrib['{http://www.dji.com/drone-dji/1.0/}RelativeAltitude']
dpr.changeAttributeValues({ feature.id():{fyd_ind: fyd,
gyd_ind: gyd,
ra_ind: ra} })
# Other DJI Tags if you need
# {http://www.dji.com/drone-dji/1.0/}GpsLatitude'
# {http://www.dji.com/drone-dji/1.0/}GpsLongitude'
# {http://www.dji.com/drone-dji/1.0/}AbsoluteAltitude'
# {http://www.dji.com/drone-dji/1.0/}GimbalRollDegree'
# {http://www.dji.com/drone-dji/1.0/}GimbalPitchDegree'
# {http://www.dji.com/drone-dji/1.0/}FlightRollDegree'
# {http://www.dji.com/drone-dji/1.0/}FlightPitchDegree'
# {http://www.dji.com/drone-dji/1.0/}CamReverse'
# {http://www.dji.com/drone-dji/1.0/}GimbalReverse'
pyexiv2 Solution
When you run next script, you'll see all metadata includes EXIF, IPTC, XMP .
from pyexiv2 import Image
image = Image("file_path")
metadata = image.read_all() # returns all metadata (EXIF, IPTC, XMP)
print(metadata.keys()) # prints dict_keys(['EXIF', 'IPTC', 'XMP'])
print(metadata["XMP"]) # prints all XMP metadata keys and values
Then, decide tags you want to add, add new fields for them, customize next script, select layer and run the script.
from pyexiv2 import Image
layer = iface.activeLayer()
dpr = layer.dataProvider()
fyd_ind = layer.fields().indexFromName("fyd")
gyd_ind = layer.fields().indexFromName("gyd")
ra_ind = layer.fields().indexFromName("ra")
for feature in layer.getFeatures():
file_path = feature["Path"]
print(file_path)
image = Image(file_path)
metadata = image.read_all()
xmp = metadata["XMP"]
fyd = float(xmp["Xmp.drone-dji.FlightYawDegree"])
gyd = float(xmp["Xmp.drone-dji.GimbalYawDegree"])
ra = float(xmp["Xmp.drone-dji.RelativeAltitude"])
dpr.changeAttributeValues({ feature.id():{fyd_ind: fyd,
gyd_ind: gyd,
ra_ind: ra} })
GimbalYawDegree, FlightYawDegree, RelativeAltitude
tags.