How to update XMP-dji-drone data using CSV file

Started by flyinlo, February 08, 2019, 10:37:15 PM

Previous topic - Next topic

flyinlo

I have received help from Stephen Marsh (thank you!!) on the adobe forum and the questions really needed to be on this forum as it applied to ExifTool.  He has helped me alot and I have run into a problem that I hope someone can help solve.

Very quick explanation on project.  DJI has a new drone that writes XMP data regarding the GPS location and the accuracy level of that data.  These XMP tags are read by Pix4D for the purpose of processing Drone Maps.  I have a DJI drone model that does not write these needed tags.  However, I have the XMP Gps data in a CSV file that I need to write to all the images.  The GPS data must be written to the XMP block and not the Exif block. 

The problem is using the setup below ExifTool writes the GpsLatitude and GpsLongitude data into the EXIF block and does not add it to the XMP-dji-drone block.  I have 7 fields that need to be updated or added.  5 of them are fine but the GPS data is not.  I am certain that the problem is because the GPSLatitude and GPSLongitude tags already exist in the EXIF block and that is what gets updated, instead of adding new entries under the XMP-dji-drone section.  Any help will be greatly appreciated.

Config File placed in the ExifTool directory (C:\Exiftool\ )
%Image::ExifTool::UserDefined = (
  'Image::ExifTool::DJI::XMP' => {
        RtkFlag => { Writable => 'rational',  },
        RtkStdLon => { Writable => 'rational',  },
        RtkStdLat => { Writable => 'rational',  },
        RtkStdHgt => { Writable => 'rational',  },
        GpsLongitude => { Writable => 'rational',  },
        GpsLatitude => { Writable => 'rational',  },
        AbsoluteAltitude => { Writable => 'rational',  },
    },
);


Command Line that is being used:
exiftool -config C:\Exiftool\drone-dji.config -sep ',' -csv="M:\Midsouth360\Missions\PPK Test Missions\2018-12-22 Snowden PPK\P4P\Snowden-12-22-Exif-drone-dji-B.csv" -r "M:\Midsouth360\Missions\PPK Test Missions\2018-12-22 Snowden PPK\P4P" -overwrite_original

I tried using the following full tag names in the CSV but that did not work at all. 
SourceFile
XMP-drone-dji:RtkFlag
XMP-drone-dji:RtkStdLon
XMP-drone-dji:RtkStdLat
XMP-drone-dji:RtkStdHgt
XMP-drone-dji:GpsLongitude
XMP-drone-dji:GpsLatitude
XMP-drone-dji:AbsoluteAltitude

Any help will be appreciated.    Please let me know if I need to provide more info.

I am also attaching one image that contains the tags I am trying to add.  This photo had the tags created by the drone when the image was taken.


flyinlo

The CSV file is attached to this post.  2 images are on my Google Drive. 
Image with the red roof is the image I am trying to update via the CSV file.

The other image (crops) contains the XMP tags that were written at the time it was created by the Dji Drone.

https://photos.app.goo.gl/P7ruJeHyNpwCmk9N6

Phil Harvey

Your config file is missing an entry in the Image::ExifTool::XMP::Main table.  Search for "xxx" in the sample config file to see how this is done.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

Previous thread where Stephen and I tried to figure it out.

Phil, isn't there already an entry in the main table?  The attempt was to add it to the XMP contained in DJI.pm.  I have no idea if the data type is correct, as I just threw rational there to get it to work.

I'm able to write those values directly (haven't checked the csv yet, though) using that config file.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

StarGeek

Ah, facepalm moment.  Actually read through your post carefully and looked at the csv file and the answer jumped out.  Your headers are only GPSLatitude/GpsLongitude.  Exiftool will, by default, write those to the EXIF block.  If you want them to be written to the new XMP tags, you must explicitly list them.

Change the headers to XMP-drone-dji:GPSLatitude/XMP-drone-dji:GpsLongitude and it should work for you.  I used your files and was able to get it to work.

"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

flyinlo

@stargeek Thank you very much!!  I will fix that. 
I found out today that I have to update the GPS data in EXIF block and also add it to the XMP block.  I should be able to modify the layout to make this work with the info you provided.  Thanks again!
Tim

StarGeek

If you're adding it to the EXIF block as well, you want to make sure and write the reference tags as well (GPSLatitudeRef/GpsLongitudeRef).  The EXIF GPS tags don't hold the direction in them, though that may not be much of a problem for you since you appear to be North and East, both positive GPS locations. The easiest way to do that would be to copy the EXIF Latitude and Longitude columns and add a trailing "Ref" to the header. 

So your final header would look something like
SourceFile,RtkFlag,RtkStdLon,RtkStdLat,RtkStdHgt,GpsLongitude,GPSLatitude,GpsLongitudeRef,GPSLatitudeRef,XMP-drone-dji:GpsLongitude,XMP-drone-dji:GPSLatitude,AbsoluteAltitude
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

flyinlo

@stargeek, Winner Winner chicken dinner!  Working like a champ.  I actually did not need to worry with the Lat and Lon REF fields because they were already there and would never change.  I am just updating precise GPS accurate data for the coordinates (which are probably not more than 1-5 meters off to start with. 

Thank you, Phil, and Steven for your help.  This is now going to be very slick and easy for updates.  I am going to learn how to make a little script with AutoHotkey so that I can just paste in the CSV file name, Image path, and what ever else could change and then have the script make a copy of the folder, then parse the inputs together to create the Command line for ExifTool.   Ya'll are awesome.  These are my CSV headings.

RtkFlag   RtkStdLon   RtkStdLat   RtkStdHgt   XMP-drone-dji:GpsLongitude   XMP-drone-dji:GpsLatitude   AbsoluteAltitude   GPSLongitude   GPSLatitude   GPSAltitude



%Image::ExifTool::UserDefined = (
  'Image::ExifTool::DJI::XMP' => {
        RtkFlag => { Writable => 'rational',  },
        RtkStdLon => { Writable => 'rational',  },
        RtkStdLat => { Writable => 'rational',  },
        RtkStdHgt => { Writable => 'rational',  },
        GpsLongitude => { Writable => 'rational',  },
        GpsLatitude => { Writable => 'rational',  },
        AbsoluteAltitude => { Writable => 'rational',  },
GPSLongitude => { Writable => 'rational',  },
        GPSLatitude => { Writable => 'rational',  },
    },
  'Image::ExifTool::EXIF' => {
GPSLongitude => { Writable => 'rational',  },
        GPSLatitude => { Writable => 'rational',  },
GPSAltitude => { Writable => 'rational',  },
    },
);

Phil Harvey

Quote from: StarGeek on February 09, 2019, 01:22:27 PM
Phil, isn't there already an entry in the main table?

Right.  Sorry, I forgot about that and was in too much of a hurry to check the docs.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

StarGeek

I would suggest some changes to that config file.  You probably shouldn't redefine the EXIF GPS tags.  Exiftool already knows how to write those.  The same goes for AbsoluteAltitude.  Also, there's duplicates of GPSLongitude and GPSLatitude.  Finally, looking at the exiftool DJI.pm source code, it might be better for these tags to be written as 'real' instead of 'rational', though to be honest, I don't know for sure.  RtkFlag probably needs to be something else as well, depending upon what values can be seen in original files.

Phil, for completeness (and to satisfy my obsessive curiosity), what would it take for to make these compatible with the -c (coordFormat) option?  I see in the XMP source  hashes %latConv/%longConv which lead to a group of PrintConvs.  Would it be enough to simply add %latConv/%longConv or would it require copying of the relevant source?
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

flyinlo

StarGeek,
I realized today that I had the duplicate entries.  I deleted the GPSLatitude and GPSLongitude (as they are incorrect).  It should be Gps not GPS.

As far as the other stuff, that is beyond my abilities.  What I can tell you is that the current setup seems to be working perfectly.  I deleted the extra GPS entries and I also added -F to my command line. 

I will just run with what I have until I am able to learn more about it and figure out better methods. 

The initial RTKflag will have a value of "0".  I then replace it with "50".  So here again as long as there seem to be no errors, I will run with what I have.  I could not have done this without ya'lls help :)

StarGeek

Just a bump since I just realized that this question got lost.

Quote from: StarGeek on February 11, 2019, 12:03:52 PM
Phil, for completeness (and to satisfy my obsessive curiosity), what would it take for to make these compatible with the -c (coordFormat) option?  I see in the XMP source  hashes %latConv/%longConv which lead to a group of PrintConvs.  Would it be enough to simply add %latConv/%longConv or would it require copying of the relevant source?
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Phil Harvey

Ah.  Yes I missed this.  In the config file you can add "use Image::ExifTool::XMP;" to the top of the file, then use "%Image::ExifTool::XMP::latConv" in the tag definition.

- Phil

Edit:  Nope.  That won't work after all.  These are stored differently in the XMP (as 3 separate numbers) compared to the config file, so you shouldn't use the ValueConv from %latConv.  In this situation you should use only the PrintConv functions, which means adding "use Image::ExifTool::GPS" instead, and adding these lines:

    PrintConv    => 'Image::ExifTool::GPS::ToDMS($self, $val, 1, "N")',
    PrintConvInv => 'Image::ExifTool::GPS::ToDegrees($val, 1)',

...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).