Enhanced Reverse Geocoding With a Custom Map of Locations of Personal Interest

The Area In Green is “Kyoto Station”
red is the Hotel Granvia Kyoto, blue is Kyoto Tower
Note: plugin version 20131022.209 (October 22, 2013) contains a major update to the personal-location support, but this page does not yet reflect the update.

I've recently added a feature to my Geoencoding-Support plugin for Adobe Lightroom to aid in reverse geocoding (that is, to aid in filling in the “location”, “city”, “state”, and “country” metadata fields, based upon the latitude and longitude associated with the image). In Google Earth, you can mark areas with arbitrarily-complex polygons, and assign names to them, and save the collection in a KML file as your personal location-to-name mapping, and the plugin will use this in preference to the generic, often unuseful reverse-geocoding data from Google Maps.


Geoencoding” is the assignment of appropriate latitude/longitude coordinates to a photo to indicate where on the globe the photo was taken. Some cameras with internal GPS receivers add this automatically, but you can also geoencode photos after the fact in various ways. My plugin allows you to sync to a tracklog (created with a smartphone or GPS unit that you carried while out with the camera), or to pinpoint locations in Google Earth or common online mapping sites, and apply those locations to photos. Other methods include apps with drag-n-drop photo-mapping features.

I geoencode almost all the photos I take, which allows me to include “map” and “nearby photos” links under most photos on my blog.

Reverse Geocoding” takes the latitude/longitude coordinates (however they originally got associated with the photo), and tries to turn them into meaningful human-readable “city”, “state”, “country”, and “location” fields. Having these fields available are not only descriptive, but they can help facilitate image search within Lightroom, and in the larger online world.

For example, “34.985840 North, 135.757639 East” is less readable and less searchable than Kyoto Station, Kyoto, Kyoto Prefecture, Japan, so it's desirable to fill in those fields.

The Problem

It can be arduous to fill in these location-based fields by hand, especially when you're on the go a lot, so we look to automated methods for the bulk of the heavy lifting. My plugins can do the lookups automatically using Google's free (thank you, Google) reverse-geocoding service.

Sometimes the results are good, but they can be very hit and miss.

For example, 40.6892439979, -74.044520002023 returns “Statue of Liberty, Brooklyn, NY 11231, USA” (the state is Brooklyn?), and -33.856779332429, 151.21523811895 returns “Sydney Harbour Tunnel, Port Jackson NSW, Australia” when we'd really like to see “Sydney Opera House, Sydney, NSW, Australia”.

For one site within Kyoto Station that I tested, I got back only “〒600-8711, Japan”, (no city, state, or location, for a place that's the central hub of a city with 1.5 million people), while a location at the other end of the station added a street name, but still no reference to Kyoto. Yet, a location a minute's walk away returns the fully flushed out Japan, Kyoto Prefecture Kyoto Shimogyo Ward 東境町174.

Like I said, automated look-up can be really spotty.

Furthermore, sometimes you'd like to impose your personal feelings about how a place is labeled, such as labeling an area “Grandma and Grandma's house”, or “Home”, or “Billy's friend Eddy's house”, etc.,

The Idea

While discussing geoencoding with Peter Krogh last week, he asked

"Do you think it would be feasible to assign a custom place name according to a GPS point/radius/region?"

to which I replied:

"Sure, just take a collection of polygons that intersect the point, sort on total area, and take the smallest."

and suddenly I wondered it never occurred to me to add this to my plugin.

So I did.

Current Status

This is a work in progress. What's described below is valid as of plugin version 20110526.148. At this early stage, things might change considerably in future versions of the plugin, so be sure to follow the version history when you update.

The plugins geoencoding dialog (brought up via File > Plugin Extras > Geoencode”) now includes a “Reverse Geo” tab, as illustrated here:

On the right side, you can point to a KML file of personal location data that you've built (likely with Google Earth), and where appropriate, the plugin will use that data in preference to the generic Google reverse geocoding lookups.

Building and maintaining your own data file is easy with Google Earth:

  1. Create a new “Folder” in the “Places” sidebar, as illustrated here:

    Name the new folder something like “My Geo Stuff”.

  2. Navigate within Earth to a place you'd like to add, and adjust the zoom so that it's fully visible.

  3. With the folder created in step one selected, click on the “Add Polygon” icon above the map:

    This will bring up a small dialog where you can enter a name, and change the cursor into a special cross-hairs cursor.

  4. Enter a name for your location.

  5. In the dialog, click on the “Style, Color” tab and change the “Area” opacity to “50%”.

  6. Start clicking around the edge of the area you want to define. The shape will change with each click, and you can click and drag on an individual point to move it. The delete key removes the most recent point. Continue until the area is defined as you like.

    Here's an example marking Kobe Airport:

    Kobe Airport

    An area like this in the middle of nowhere need not be complex (I've used seven points), but you can make them as arbitrarily complex as you like. Use as many points as you need, but since more complex polygons take more CPU to work with in the plugin, use only the points you need. This next screenshot is an example of what not to do: rather than click at points around the edge, I dragged the cursor, and it ended up creating a polygon with 88 points:

    needlessly complex
  7. Click the dialog's “OK” button to save the new location.

  8. You can now repeat steps #2 – #6 for as many locations that you'd like to add:

    • You won't need to set the opacity each time, though you can adjust the opacity and color as you like.
    • You can edit a location via the right-click menu “Get Info” item.
    • You can overlap locations, as I did in the example at the top of this post (the red area isolates the on-station hotel). If the plugin finds that more than one matches a location, the one with the smallest area is considered the most specific and so it's the one used.
    • There seems to be a bug in Google Earth that causes the name to be lost if you don't tab out of the name input field before clicking “OK”, so if you end up with “Untitled Polygon”, just edit it to set the name you want.
    • You can organize your locations under your My Geo Stuff main folder by creating new folders in the same way you made My Geo Stuff to begin with, but by right clicking on My Geo Stuff instead of My Places”.
    • If you accidentally create a location outside of your My Geo Stuff folder tree, just drag it in.
  9. When you're ready to save the data, right click on My Geo Stuff and select Save Place As.... Make sure to choose the kml format, and not the kmz format, and save the file somewhere convenient.

  10. You can continue working on your set of locations later, but not that Earth will not save the file automatically, so if you want updates and additions to be made available to the plugin, you'll have to repeat step #9 each time.

And that's it. After referring to the file in the plugin dialog, photos geoencoded to locations within the polygons you defined in the KML file will get the name you defined as their “location”.

As a bonus, the names themselves become available as geoencoding presets in the “Static Location” tab, for when you want to assign geo-coordinates to a photo that doesn't yet have them: the latitude and longitude of the polygon's centroid (center) is used.

But what about “city”, “state”, and “country”? Ah, that brings us to...

Plans for the Future

As of now, this works only with the “location” metadata field, which is nice, but in order to be a reverse-geocoding solution, it's got to handle “city” and the like. A KML file can hold extended metadata like that, but I haven't figured out a way to allow it to be edited and maintained conveniently. I've got some ideas to pursue, but if you've got ideas on other KML editors or solutions, I'd appreciate to hear them.

But even after we can associate a city/state/country with the locations we define, interesting issues remain to be considered:

  • If we allow multiple KML files to be specified to the plugin, community-specific KML files can be built and shared among members of that community. For example, photographers into R/C airplanes might maintain a shared KML file describing popular fields to fly from. Each member would then use that in the plugin, as well as their own KML file for their personal locations.
  • Rather than a “smallest polygon takes all” approach, perhaps all matching polygons should be inspected to derive data. For example, if I have one big polygon that surrounds Japan and associate “country is Japan” with it, and then another polygon that identifies Kyoto Prefecture and associate “state is Kyoto Prefecture”, and another polygon for “city is Kyoto”, then coordinates at a place like Kyoto Station would be within them all, and so the city/state/country could be inherited from them, leaving only “Kyoto Station” to come from the Kyoto-Station-specific location. This alleviates the need to laboriously enter the city/state/country data for every location defined within the city.
  • If data is inherited from more spacious polygons as described above, maybe there should be a way to combine data within a particular field. In the Kyoto Station example, maybe that polygon would have “location is Kyoto Station”, while the hotel polygon within it would have “location is Hotel Granvia”, and the final derived location for a point within the hotel could be “Kyoto Station Hotel Granvia” or maybe “Kyoto Station (Hotel Granvia)”. How should this be handled?
  • If we allow multiple KML files to be specified to the plugin, should we treat their respective polygons equally, or somehow give precedence to one file over another (so that, for example, one's personal KML always overrides a community KML you also use)?

I'm sure there are plenty of problems and opportunities that I'm not thinking of, so please let me know what you think and your ideas/hopes for a feature like this.

I expect the semantics of reverse geocoding in the plugin to change with new versions as these issues are addressed, so be sure to carefully check the version history when updating the plugin.

What I Really Want

I'll be happy to get a good reverse-geocoding solution for my plugin, but this is an idea that could/should go well beyond my own plugins... any geoencoding solution could benefit from this kind of thing. I can imagine that Google would allow registered users to incorporate this kind of data in their Google account, incorporating and sharing datasets with member of the various communities the user is a part of (allowing communities to crowdsource data), and then use this user-specific data to tailor reverse-geocoding responses to the specific user.

Google has a lot out there already, and perhaps something like Google Map Maker is already mostly there, but I haven't found a way to make it work for these purposes. (I'd love to be proven wrong.)

My ultimate goal is everything above, and that this is handled natively within Lightroom, so that I can dispense with the plugin and pick up the camera again.

All 10 comments so far, oldest first...

“and suddenly I wondered it never occurred to me to add this to my plugin.

So I did.”

Heh.. had to chuckle, that sounds vaguely familiar to Kelby’s quote from the recent main topic of conversation 😉

I’m interested in your workflow for geocoding. Do you have many places (ones that you’d have pre-designated using the above method) that you wander in/out of while recording a tracklog?

I find that the most common places I take photos (house, backyard, work) are the ones I wouldn’t normally turn on my GPS for so I’ve set Metadata Presets to fill the Location IPTC with one click. I then filter on those locations and geocode with the Static Presets in the plugin.

Still, I can see this being useful for those areas that I visit every so often that I again wouldn’t use a GPS but encode from GE. I’m very much looking forward to playing with this. Glad it’s a long weekend coming up!

I haven’t actually used the camera since I developed this, but what you mention is useful for the tangential-benefit of geoencoding presets. But since the automated reverse geocoding can’t even fill in Kyoto city when I’m at Kyoto station, it’ll be useful to fill in that data when I use a tracklog. More interesting (especially at the moment since it doesn’t handle city/state/country yet) are the location names, so I can name all the random temples and shrines in the area, that I know I’ll be visiting many times over the years, and once I add to my KML file once, I’ll never have to deal with it again. Only at this beta stage, I’m not going to do a bazillion locations yet, because I’ll probably have to start over once I figure out the city/state/country thing. —Jeffrey

— comment by JasonP on May 27th, 2011 at 7:47am JST (6 years, 7 months ago) comment permalink

Ok, had a quick go with it, and I can definitely see the benefit, more so if you can get the rest of the IPTC fields working too. One bit that was a problem though, once I got it configured, it told me that there were no named locations. I found that I had to put the location name in the large “Description” field (not just the “Name” field) before they were found. This is on Windows 7, GE build 2197, plugin version .149

I’ve pushed a new version that fixes the description thing… that’s not needed, and was a hold over from trying something else. —Jeffrey

— comment by JasonP on May 30th, 2011 at 5:24am JST (6 years, 6 months ago) comment permalink

I have been trying this but no matter what i do, the kml file is being reported as not a valid file or has no named polygons. Can i send you my kml file?

Hahah, it took me a while to figure out why it was working for me but not for you. It turns out that I had made the update to my code, but not committed it to the build. Doh! I’ve just pushed a new version that actually has the update so that descriptions are not required for the polygons. —Jeffrey

— comment by Steve h on June 10th, 2011 at 7:28pm JST (6 years, 6 months ago) comment permalink

Ooooh, this feature looks great! I was looking for something like this to section off parks and stuff. Very cool!

— comment by Daniel on July 11th, 2011 at 5:20am JST (6 years, 5 months ago) comment permalink

this instruction solves some of my problems what can be done in Gooegle Earth, thanks.
– Creating a “custom map of locations” makes sense if you spend considerable time in one city. But I’m trying to work with photos from 2 extensive trips to South America (6 and 5 months). Having travelled overland several thousand kilometers and having taken lots of photos “on the road” I cannot imagine to create adequate sets of maps.
– While in the one by one mode sometimes in “location” the sight and the exact adress are shown (plus city – region – country) these informations on “location”are lost in the next step. Only “city – region – country” is written back.
Maybe, I missunderstood something?
Best regards,
Gottfried, Vienna, Austria

There’s a checkbox by “location” (and each of the others)… make sure they’re all checked if you want them all written back. —Jeffrey

— comment by Gottfried on August 7th, 2011 at 5:38pm JST (6 years, 4 months ago) comment permalink

Hi Jeffrey,

I was just playing around with the reverse geocoding part of our excellent geocoding plugin and I was surprised by the results of the underlaying Google geocoding API (in comparison to the GeoNames webservice). However you are using the legacy Geocoding API V2 which has been deprecated and Google recommends to switch to the new version V3, which they say has many improvements. And indeed the results are much more detailed.
If I use e.g. 34.985840, 135.757639 (guess where it is) with your plugin I get “京都総合観光案内所 600-8216, Japan” as a result (language was set to English btw.) But if I use this lat/lon with the new API I get much more differentiated results. But check it out yourself:

So, if you have plans to further improve your plugin I would be happy to have the new geocoding API V3 in the reverse geocoding part.
And I would be even more happy if you would let the user to define the mapping between the result tags and the EXIF tags in LRx.
For example: sublocality –> Sublocation
locality –> City
administrative_area_level_1 –> State / Province

Another option I would like to see here is the possibility to have those values written as Lightroom keywords.
I don’t know if the final LR4 will have those features builtin natively, but I like your plugin and if I can find them there, even better.

Best regards from Berlin, Germany


I’ll definitely be updating to V3, but it’ll be a big job so I’m going to wait for things to settle down a bit. I just pushed a new huge update with many changes in anticipation of Lr4, and still have plenty of improvements on the plate. —Jeffrey

— comment by Jacques on February 22nd, 2012 at 3:42am JST (5 years, 10 months ago) comment permalink

Hi Jeffrey,

I find this feature (like the rest of the plugin) extremely useful. But for some reason it always chooses the largest polygon instead of the smallest one.

It’s supposed to explicitly use the smallest matching polygon, so if it’s not, please send a log, but make sure you’re using the most recent version, because I’ve just added some extra logging. —Jeffrey

— comment by Erik on April 13th, 2012 at 10:47am JST (5 years, 8 months ago) comment permalink

You have outdone yourself again! Thanks!

— comment by T.J. Powell on October 28th, 2013 at 12:41am JST (4 years, 2 months ago) comment permalink

I am a geologist working on a fiendishly complex small volcano in northwestern Mexico, intrigued with the possibility of “reverse geocoding” my images. I have a Google Earth map dividing the volcano and its lava flows into named zones, some smaller than a hectare. Clearly these are smaller than the country-state-city-location divisions in IMatch 5.5, my digital management system requiring me to re-purpose some other EXIF tags for their names.

I note that most of the dates on your work are a couple of years old so what I want are references I can use to learn the details myself. The ideal would be to find something I could re-purpose for my needs. I haven’t written code for years.

— comment by Dan Lynch on July 8th, 2016 at 7:02am JST (1 year, 5 months ago) comment permalink


Writing from Bethel, CT, USA. Flying to Shanghai tomorrow, to visit my wife’s family, then to Taipei, just to see it.

I am looking for a piece of software, and Google put me to your blog. There is so much info there that I hope you don’t mind if I just ask my question.

My wife’s Mac seems to automagically put place names on photos she takes with her phone, while traveling.

I have got a way to put gps coordinates into the EXIF data from pix on my good cameras (phones do have their advantages), but seek a reverse geotagging solution to look up the actual locations…and take it a step further.

I’m not interested, so much, in results like: “12 Oak St., Anytown, USA”. I’d rather, that the software realize that 12 Oak St. is on the edge of “Oak View Park”, and give me that, instead.

And, if I am not asking too much, I want it to rename the photo with that location, or come up with some way to put that location as a caption, either in Picassa, or Lightroom, which I guess I will eventually switch over to, now that Picassa is a dead end.

It’s clear to me that your geo plugin for lightroom does some of this, but I’m not sure if it does all of it. Does it, and if not, do you know of a product that does?

Thanks in advance.

Mike Hodish

The location info given by Google’s reverse-geo lookup can be a mixed bag… whether it’s what you want perhaps depends on location, so just give it a try and keep your fingers crossed. You can use the Write Data Field feature in my Bag-o-Goodies plugin to populate the Caption with other metadata. —Jeffrey

— comment by Mike Hodish on October 20th, 2016 at 2:15pm JST (1 year, 2 months ago) comment permalink
Leave a comment...

All comments are invisible to others until Jeffrey approves them.

Please mention what part of the world you're writing from, if you don't mind. It's always interesting to see where people are visiting from.

You can use basic HTML; be sure to close tags properly.

Subscribe without commenting