News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

what3words

Started by Alan Clifford, December 16, 2020, 02:59:38 PM

Previous topic - Next topic

Alan Clifford

I'm toying with the idea of putting just3words what3words location information into my photos.  I can get the three words from latitude/longtitude.  However, as there is no just3words tag, I'll have to repurpose something else.  Or I could create my own XMP tag.


However, I'm pondering putting the three words into the photographs in multiple languages.  The following are the same square in three of the eleven official languages in South Africa.

nonhumans.diverts.subatomic
doktoraal.halfjaar.kombers
libalele.awutyiwa.zonyuke

I'm totally ignorant about using multi-lingual tags and how to handle them.  I already use a user defined tag for something else;  how would a multi-lingual tag differ?  Or how can I repurpose an existing tag to be multi-lingual?

StarGeek

I'm assuming you mean What3Words?  Or is it something different?

I can't think of anything obvious offhand to repurpose.

In creating your own tag, for the actual tag definition, I'd say copy the definition for XMP:Description
description => { Groups => { 2 => 'Image'  }, Writable => 'lang-alt' },
except instead of Image, you would want it to be part of the the location group, so the result would be
description => { Groups => { 2 => 'Location'   }, Writable => 'lang-alt' },

Then all you need to do is figure out what namespace you want to put it in.

When creating a new XMP tag, I usually find it easiest to figure out what existing tag already has the same properties, then copy/paste/edit from the XMP.pm file.

Let me know what you end up with.  Sounds like a interesting project.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Alan Clifford

Yes, I meant what3words.  Stupid me!  I've changed the subject to that in my first post.

Could you point me towards where to read about lang-alt and how it is used?

edit:  Found some info. in the xmp tag page.

Alan Clifford

After I signed up for a what3words api key, an account manager emailed to asked me how I was going to use it so she could point me in the right direction.  I had a couple of queries.

The answer to query 1 was just irritating.

QuoteFor point 2 - We don't have a XMP tag for what3words, but you can use the
tag for GPS coordinates.

i'd already said that I was matching the 3 words to the gps co-ordinates in the photo metadata.   >:( >:( :'( :'(

But at least I know for sure that I have to roll my own.


StarGeek

Quote from: Alan Clifford on December 17, 2020, 08:10:49 AM
After I signed up for a what3words api key, an account manager emailed to asked me how I was going to use it so she could point me in the right direction.

Now I feel left out.  I got an API key yesterday and they didn't ask me anything.

I looked over the docs and I think I can do something with this.  It'll get me off my butt to clean up another config file I should have posted a while ago.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

StarGeek

Hmmm... Maybe
Quote from: Alan Clifford on December 17, 2020, 08:10:49 AM
QuoteFor point 2 - We don't have a XMP tag for what3words, but you can use the
tag for GPS coordinates.

Hmmm...  maybe if you create a namespace for it, they'll adopt it as their "Official" tag.  Maybe "XMP-W3W"?
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Alan Clifford

Getting the words seems quite straightforword and exiftool can chop out the words from the json.

curl --request GET --url 'https://api.what3words.com/v3/convert-to-3wa?key=XXXX&coordinates=-33.1264743945278%2C18.0585927062028&language=af' | exiftool -s3 -words -

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   312  100   312    0     0   4224      0 --:--:-- --:--:-- --:--:--  4216
doktoraal.halfjaar.kombers


But I'd probably not do it quite like that so that I can do some checking for the GET not getting.


(ps. I've been distracted away from this by a problem with my golf world handicap system spreadsheet and an ill defined algorithm in the documentation.)


Alan Clifford

Quote from: StarGeek on December 17, 2020, 10:51:41 AM

Hmmm...  maybe if you create a namespace for it, they'll adopt it as their "Official" tag.  Maybe "XMP-W3W"?

I guess I could tell them about it and post in any suitable forums I can find.  ;D

StarGeek

Here's a rough draft of the what3words namespace config file.
%Image::ExifTool::UserDefined = (
    # new XMP namespaces (eg. xxx) must be added to the Main XMP table:
    'Image::ExifTool::XMP::Main' => {
        # namespace definition for examples 8 to 11
        w3w => { # <-- must be the same as the NAMESPACE prefix
            SubDirectory => {
                TagTable => 'Image::ExifTool::UserDefined::w3w',
                # (see the definition of this table below)
            },
        },
},
);

# This is a basic example of the definition for a new XMP namespace.
# This table is referenced through a SubDirectory tag definition
# in the %Image::ExifTool::UserDefined definition above.
# The namespace prefix for these tags is 'xxx', which corresponds to
# an ExifTool family 1 group name of 'XMP-xxx'.
%Image::ExifTool::UserDefined::w3w = (
    GROUPS => { 0 => 'XMP', 1 => 'XMP-w3w', 2 => 'Image' },
    NAMESPACE => { 'w3w' => 'http://ns.what3words.com/w3w/1.0/' },
    WRITABLE => 'string', # (default to string-type tags)
    What3Words => { Groups => { 2 => 'Location'   }, Writable => 'lang-alt' },
);

#------------------------------------------------------------------------------
1;  #end


The resulting XMP looks like this
<rdf:Description rdf:about=''
  xmlns:w3w='http://ns.what3words.com/w3w/1.0/'>
  <w3w:What3Words>
   <rdf:Alt>
    <rdf:li xml:lang='x-default'>darker.highs.pans</rdf:li>
    <rdf:li xml:lang='fr'>bradant.digĂ©rer.dĂ©marcheuse</rdf:li>
   </rdf:Alt>
  </w3w:What3Words>
</rdf:Description>


I'm also working on a user-defined tag that will call cURL to do the lookup so it would be easy to add this to file.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Alan Clifford


So I thought I could just check for the world "error" to indentify a bad response.

curl --request GET --url 'https://api.what3words.com/v3/convey=XXXXXXX&coordinates=0'

{"error":{"code":"BadCoordinates","message":"coordinates must be two comma separated lat,lng coordinates"}}

But "error" can be a word in the three words, such as "error.that.hang"

:( :( :(


StarGeek

Passing that result to exiftool will give you tags of ErrorCode and ErrorMessage which I don't think would exist otherwise.  Or you could use try a command line json program like jq
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Alan Clifford

exiftool -what3words=$(echo ${response} | exiftool -s3 -words -) "${filenamestring}"

If curl succeeds, even if the response is an error response, exiftool seems so robust that I can use the above command (in bash script).

Thinks ... hmmm ... -tagsfromfile instead of two calls to exiftool?

Alan Clifford

I changed the tag to words

Words => { Groups => { 2 => 'Location'   }, Writable => 'lang-alt' },

copied the response to a file and used

exiftool -m -tagsfromfile  ${tempresponsefile} -words "${filenamestring}"

which works OK if the words tag is in the json file but if not, I get

Adding what three words to gps1.jpg
Error: HASH(0x7fdbb7651d90) - /tmp/w3wresponse.xrssmP



Alan Clifford

@stargeek
It might be sensible to change the tag to "Words" anyway as that is the tag used in the json file?

StarGeek

I don't feel that's descriptive enough.  Words could mean anything.  What3Words is clear to anyone who knows about the website and to anyone who didn't, it would be top listing on a google search.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).