Rename With City/Country Name via openstreemaps?

Started by TippyTurtle, February 25, 2015, 06:06:53 PM

Previous topic - Next topic

TippyTurtle

Help?  I would like to rename my photo's with City/Country name instead of Camera Make/Model. 

Currently I run this:

exiftool -P -r '-FileName</media/FinishedPictures/${CreateDate}(${Make;} ${Model;}).%le' '-FileName</media/FinishedPictures/${FileModifyDate}(${Make;} ${Model;}).%le' '-FileName</media/FinishedPictures/${DateTimeOriginal}(${Make;} ${Model;}).%le' -d '%Y-%m/%Y-%m-%d %Hh%Mm%Ss%%-c' .


Which will rename files like:

2014-10-05 15h19m58s(Motorola XT1039).jpg


If I look at a photo of mine I see the GPS data:
exiftool -P -r -if '$GPSLongitude ne "+0.0000000"'  -FileName -GPSLongitude -GPSLatitude -c "%+.7f" *
======== 2014-10-05 15h19m58s(Motorola XT1039).jpg
File Name                       : 2014-10-05 15h19m58s(Motorola XT1039).jpg
GPS Longitude                   : +12.4883333
GPS Latitude                    : +41.8905556


I can take that data to find the city/country...

http://nominatim.openstreetmap.org/reverse?format=xml&lat=41.8905556&lon=12.4883333&zoom=18&addressdetails=1


Which returns:

<reversegeocode timestamp="Wed, 25 Feb 15 22:54:03 +0000" attribution="Data © OpenStreetMap contributors, ODbL 1.0. http://www.openstreetmap.org/copyright" querystring="format=xml&lat=41.8905556&lon=12.4883333&zoom=18&addressdetails=1">
    <result place_id="127887990" osm_type="relation" osm_id="1842059" ref="Casa di Marco Emilio Scauro" lat="41.8908275" lon="12.488176392899">
        Casa di Marco Emilio Scauro, Via Nova, Campitelli, Municipio Roma I, Rome, Lazio, 00184, Italy
    </result>
    <addressparts>
        <archaeological_site>Casa di Marco Emilio Scauro</archaeological_site>
        <footway>Via Nova</footway>
        <suburb>Campitelli</suburb>
        <city_district>Municipio Roma I</city_district>
        <city>Rome</city>
        <county>Rome</county>
        <state>Lazio</state>
        <postcode>00184</postcode>
        <country>Italy</country>
        <country_code>it</country_code>
    </addressparts>
</reversegeocode>


How do I hook this all up so I add the correct EXIF values for City and Country as well as a file named:

2014-12-14 11h44m20s(Rome, Italy).jpg

...using the XML elements <country> and <city>? Of course I need it to wait a couple minutes between requests to not brutalize openstreetmaps.

Thanks in advance,
Todd

Phil Harvey

Hi Todd,

If you save the XML to a file with the same name as your image, then you can read the tags from this file and copy them into the filename of the image.  The exact syntax is a bit involved, but similar to what is done in this post.  I should have more time tomorrow to help you more if needed.

- 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 ($).