Could someone develop a script for me please

Started by DigPeter, May 05, 2023, 02:13:43 PM

Previous topic - Next topic

DigPeter

I am too old to write scripts!  

I have an app by Jingo which converts lat/long GPS data, held in the metadata of a jpeg, to British national grid - https://www.photools.com/community/index.php/topic,6870.msg47463.html#msg47463 

This is excellent for single images.  I copy and paste the result to the tag XMP::Album\Notes\Notes\0.  I record wild plants and when out often take photos of them with a smart phone, which automatically records the GPS location in UTM format. After uploading the images to IMatch, it is then a long-winded process to convert each of these individually with the app and then copy/paste.

For all selected image, the script would automatically apply the app to each individual image and then copy the result into the tag.

Any offers would be welcomed - thanks.

Mario

If this is a simple math transform / calculation, maybe I could add this as a variable function?
Which then can be applied to lat/lon and produces the corresponding "thingie" in the BNG?

This would allow users to use this e.g. in a Metadata Template or the Metadata Mechanic to calculate coordinates and store them elsewhere (for any number of files at once). And tho show the grid coordinates in e.g. a File Window. Which would be versatile I guess.

I have no clue how this conversion works and I have not look at user-written scripts.
But if this is a simple calculation (no database or web service lookups etc.) I will consider adding this to IMatch as a variable function, for the benefit of all users who work with the BNG.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

DigPeter

Thanks Mario.  I do not know how Jingo did this.  By placing the unzipped script, available from the link, in  imatch6\webroot\user folder, it appears in the apps panel, so the conversion work is already done.  As it stands it operates only on the individual, focussed file.  The result is shown in the attachment.   In this case I copy the result from the green box to the tag of the focussed file.  I would like an app to to take this further and act on all selected files.

Jingo

Nice to know the APP is still being used..  8)   

I'm sure I can modify the code to apply the calculated values to the selected images with a Copy Button.  Stay tuned!

Mario

Looking at https://www.movable-type.co.uk/scripts/latlong-os-gridref.html, the math seems quite 'involved'.
Did you implement all this yourself or did you use the library from that site?

Looking at all the code, implementing this in form of a variable function would be doable, but waay to much work for just one or a few users.

@Users: How many of you work with the British National Grid system and why?
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Jingo

#5
Nice to know the APP is still being used..  8)  Yes - the Math was quite involved but luckily I had chanced upon an open source JS library to do the conversion so it was as simple as calling a function to convert!

I have modified the app to add a new button that will write the UTM code to all selected images.. just download the attached zip file and extract/overwrite the existing version on your system.. you should see the new button.  Enjoy!

owCnL3MXMh.png

DigPeter

@Jingo
Great - to which tag does it write the converted coords or can this be selected??

Jingo

Welcome Peter - it writes to the tag you mentioned in your other post: "XMP::Album\\Notes\\Notes\\0" - if you need to change this to a different field, you can easily edit the destination tag on line 262 of the index.html file.  Just remember to add the double slashes to tag as noted above and in the code.

Enjoy!

Mario

I found https://www.movable-type.co.uk/scripts/latlong-os-gridref.html as a reference for what's involved.
Quite a lot of math going on, also in the libraries you use in your app.

I guess this will not make it into a variable function, sorry.
Too much work for probably less than a handful of users (or maybe only one).
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

DigPeter

@Jingo
I have tested the new script.  It works beautifully and fast.  However it is the OSGB reference I require.  Grateful if you could amend please.

Jingo

I just modified the code to use OSGB instead of UTM... just overwrite and it should work just fine.  Enjoy!

DigPeter

@Jingo
I am afraid it is not working now.  Neither button produces a result (UTM or OSGB).

DigPeter

@Jingo
Attached is a jpeg to test on

DigPeter


Jingo

#14
Thx Peter - just got back from a trip and took a look at the files.  So, the script is using gps data from the v1/files (not the DB) and it appears the Location and GPS data tags are empty in these two sample files.  Can you confirm the script works after writing the database data back into the files and/or check to be sure the GPS data appears in the files on your end (maybe it didn't export correctly to the 2 sample files)?Thx!

DigPeter

Quote from: Jingo on May 19, 2023, 03:19:39 PMThx Peter - just got back from a trip and took a look at the files.  So, the script is using gps data from the v1/files (not the DB) and it appears the Location and GPS data tags are empty in these two sample files.  Can you confirm the script works after writing the database data back into the files and/or check to be sure the GPS data appears in the files on your end (maybe it didn't export correctly to the 2 sample files)?Thx!
Andy, thanks - The 2 files in my IM database have gps data, deffo.  V1 works OK on both.  I will send two different files to your email.  V3 does not write the UTN or OSGB data.

Jingo

Hi Peter - just sent you a reply email but it looks like the files you sent still do not have GPS metadata within them.  Either the export is not set to include metadata or you are not writing the metadata back to the JPG images but keeping it within the database only instead.

jch2103

@DigPeter - The forum software usually strips out metadata from attached images. Try zipping them before uploading, as that ensures everything (all metadata) is included. 
John

Jingo

Thx for the tip John - Peter wound up sending me 2 photos with GPS data which works with the script.  The issue is how the script is written - it was designed to take the info from the Highlighted photo and apply it to all Selected photos.  I am rewriting it so it will also have an option to simply file a specific field from each Selected photo back to the selected photos XMP field.

Mario

#19
@Jingo: Thanks for helping other users. This gets a from me.

And for all of the friendly other users who help others in this community.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Jingo

Quote from: Mario on May 22, 2023, 02:17:19 PM@Jingo: Thanks for helping other users. This gets a from me.

Always happy to help... my small way to give back to others!

I'll update the original script thread but I have made some modifications for Peter to include a new button that converts each selected images' GPS coords to OSGB and writes that value back to each selected image (instead of using the highlighted value).

Carlo Didier

Quote from: Mario on May 06, 2023, 03:34:14 PM@Users: How many of you work with the British National Grid system and why?
I do, because I'm a lot in Scotland for hillwalking and all my paper maps use BNG.

DigPeter

This script was requested specifically with British National Grid and British maps in mind.  Jingo has added value by including UTM grid which is a universal alternative to Geodetic grid (lat/long) and used with many maps worldwide.