Sort Photos Into Folders by Location (City Names)
How to turn GPS coordinates into city names and file photos into folders by place, what reverse geocoding involves, and what goes wrong.
You want a folder called Paris with the Paris photos in it. The photos have GPS. What they do not have is the word "Paris" anywhere, and no file manager can sort by a pair of coordinates.
What is in the file
A geotagged photo carries latitude and longitude in EXIF. Nothing else. No city, no country, no street. When Apple Photos or Google Photos shows "Paris, France" under a picture, it looked that up from the numbers, on the fly, using a map service.
Turning coordinates into a place name is called reverse geocoding. To get a folder per city, something has to do that lookup for every photo, then move the file.
Where the names come from
There are two ways to reverse geocode.
Online. Send the coordinates to a service, get a name back. OpenStreetMap's Nominatim is free and public, with a limit of about one request per second. Apple, Google and others run their own. Only the numbers are sent, not the photo, but it is still a network request per location.
Offline. Download a database of place names with coordinates, typically a few hundred megabytes from GeoNames, and search it locally. digiKam can do this. It is private and fast, but the download is large and the names are cruder than a live service gives.
Most tools use the online route and cache results, so ten thousand photos from one holiday become a handful of lookups.
What goes wrong
Names are inconsistent. The same beach might come back as the town, the district, the municipality or the region depending on which service you ask and how the boundary data is drawn. Photos from one holiday can land in three folders that mean the same place.
Borders and coasts. A photo taken on a ferry or from a plane has coordinates in the sea. There is no town there. Some services return the nearest land, some return nothing.
Precision. Phone GPS can be off by a hundred metres indoors. Near a border between two districts, half the photos go one way and half the other.
Missing GPS. Most libraries are mixed. Camera photos, scans, WhatsApp forwards and anything shot with location off have no coordinates. A pure location layout leaves those homeless.
For all these reasons, location works better as the second level under year than as the top level. 2019/Paris fails gracefully: photos with no place stay in 2019. Paris/2019 has nowhere to put them.
Doing it by hand
exiftool can move photos into folders by GPS, but it only has the coordinates, so the folder names would be numbers. To get names you need to reverse geocode first and write the result into a tag, usually City or Location, then sort by that tag.
digiKam does the whole chain: its reverse geocoding tool fills in city and country tags from coordinates, either through OpenStreetMap or from an offline database, and its advanced rename or move tool can then file by those tags. It is free on all three platforms and it is the most complete free option for this job. Expect an evening of setup.
A script with exiftool and the Nominatim API works on Linux or macOS. Rate-limit to one request per second, cache by rounded coordinate, and write -City per file. It is a couple of hours of scripting.
Doing it with the app
Takeout JSON Metadata Fixer has two folder templates that use place names, Year/Location and Location/Year, and a naming template that puts the place in the filename.
For each photo with GPS it looks up a place name, using OpenStreetMap on Windows and Linux and Apple's geocoder on macOS. Results are cached, nearby photos share one lookup, and requests are spaced to stay within OpenStreetMap's policy. Only coordinates are sent, never the image. If you are offline or pick a template without location, no request is made at all.
Photos without GPS are handled the way the layout suggests: in Year/Location they stay in the year folder, and in the Date-Time + Location naming template the location part is simply dropped. Nothing goes into an "Unknown" bin.
For photos that come from Google Takeout, the GPS is read from the .json sidecar, which is the only place it survives in many exports. If a whole folder has no GPS and you know where it was taken, you can type one place for all of them. That is covered in /blog/add-location-to-photos-without-gps.
Dry run shows the folder tree before anything is moved. Runs on macOS, Windows and Linux. Free for 500 photos, $9.99 one-time for unlimited.
Frequently asked questions
Do my photos get uploaded to look up place names?
No. Only the coordinates, rounded, are sent. The photo stays on your disk. If that still bothers you, use a template without location and nothing is sent.
Why did one trip end up in several folders?
Different neighbourhoods returned different names, or the boundary data put some coordinates in an adjacent municipality. Merge the folders by hand afterwards. It takes a minute and is the price of automatic naming.
Can I get the country instead of the city?
Not as a template option in the app. Most lookup services return several levels, and city is the one that reads best in a folder name. exiftool and digiKam let you pick any level if you script it.
What about photos taken at home?
They will go into a folder named for your town, and there will be a lot of them. Many people prefer Year/Month for home and Year/Location for travel, and run the two sets separately.