Hello BobvdMeij,
See updated export script version (it adds a new Custom menu item) that allows to save to the text file the following values from the XMP header: "drone-dji:RelativeAltitude=", "drone-dji:AbsoluteAltitude=", "drone-dji:GpsLatitude=", "drone-dji:GpsLongtitude="
and the following from the project meta information (automatically read by Metashape from XMP and EXIF):
'DJI/RtkStdHgt', 'DJI/RtkStdLat', 'DJI/RtkStdLon', 'Exif/GPSAltitude', 'Exif/GPSLatitude', 'Exif/GPSLongitude'
import Metashape
from xml.dom import minidom
def main_save_meta():
xmp_elements = ["drone-dji:RelativeAltitude=", "drone-dji:AbsoluteAltitude=", "drone-dji:GpsLatitude=", "drone-dji:GpsLongtitude="]
meta_elements = ['DJI/RtkStdHgt', 'DJI/RtkStdLat', 'DJI/RtkStdLon', 'Exif/GPSAltitude', 'Exif/GPSLatitude', 'Exif/GPSLongitude']
if not len(Metashape.app.document.chunks):
print("Empty project, script aborted")
return False
export_path = Metashape.app.getSaveFileName("Specify the export path to the file:", filter = "Text file (*.txt);;All formats (*.*)")
if not export_path:
print("Invalid path, script aborted.")
return False
export = open(export_path, "wt")
chunk = Metashape.app.document.chunk #active chunk
for camera in chunk.cameras:
path = camera.photo.path
with open(path, "rb") as file:
image = file.read()
string = str(image)
xmp_start = string.find('<x:xmpmeta')
xmp_end = string.find('</x:xmpmeta')
file.close()
if xmp_start != xmp_end:
xmpString = string[xmp_start : xmp_end + 12]
export.write(camera.label + "\n")
for element in xmp_elements:
try:
value = string[string.find(element) + len(element) : string.find(element) + len(element) + 10]
value = value.split('\"',3)[1]
export.write("\t{:s}\t{:s}\n".format(element, value))
except IndexError:
export.write("\t" + element + " not found\n")
for element in meta_elements:
if element in camera.photo.meta:
export.write("\t{:s}\t{:s}\n".format(element, camera.photo.meta[element]))
else:
export.write("\t" + element + " not found\n")
export.close()
print("Script finished, file written to:\n" + export_path)
return True
Metashape.app.addMenuItem("Custom menu/Save DJI meta to file", main_save_meta)