Debian Codegraph @

html/geolocation.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
3 <html>
4 <head>
5 <meta http-equiv="content-type" content="text/html; charset=utf-8">
6 <title>ExifTool Geolocation Feature</title>
7 <link rel=stylesheet type='text/css' href='style.css' title='Style'>
8 <style type="text/css">
9 <!--
10 pre { color: #800; margin-left: 4em }
11 .indent { margin-left: 22% }
12 table.dl { border: 1px solid gray; border-collapse: collapse }
13 table.dl td { padding: .4em .8em }
14 i.sm { font-size: 12pt }
15 -->
16 </style>
17 </head>
18 <body>
19 <div class='index'>
20 <a href="#Read">Reading Geolocation</a>
21 <br>&nbsp; - <a href="#DefTags">Default tags</a>
22 <br>&nbsp; - <a href="#DefInput">Default input</a>
23 <br>&nbsp; - <a href="#Reg">Regular expressions</a>
24 <br><a href="#Write">Writing Geolocation</a>
25 <br>&nbsp; - <a href="#Geotag">While geotagging</a>
26 <br><a href="#Extra">Extra Features</a>
27 <br>&nbsp; - <a href="#Lang">Language translations</a>
28 <br>&nbsp; - <a href="#Params">Optional parameters</a>
29 <br>&nbsp; - <a href="#Alt">Alternate databases</a>
30 <br>&nbsp; - <a href="#List">Listing the database</a>
31 <br>&nbsp; - <a href="#Custom">Customization</a>
32 <br><a href="#Troubleshooting">Troubleshooting</a>
33 </div>
34 <a name="Geolocation"></a>
35 <h1>ExifTool Geolocation Feature
36 <i class='sm lt'>(aka "Reverse Geocoding")</i></h1>
37
38 <p>ExifTool has the ability to generate geolocation information (including city,
39 region, subregion and country) from GPS coordinates (and visa versa) using an
40 included database of all cities with population 2000 or greater based
41 on a Creative Commons database from <a href="http://www.geonames.org/export/">geonames.org</a>.
42 (An extended version of the ExifTool database is available with cities down to a
43 population of 500. <a href="#Alt">See below</a> for more information.) There are
44 two basic modes of operation: one to generate geolocation information when
45 reading from a file, and another to write geolocation information to a file.</p>
46
47 <a name="Read"></a>
48 <h3>Reading Geolocation Information</h3>
49
50 <blockquote>Geolocation tags may be generated when reading a file by setting the
51 <a href="ExifTool.html#Geolocation">API Geolocation option</a>. For example,
52
53 <pre>exiftool -api geolocation "-geolocation*" test.jpg</pre>
54
55 produces an output similar to this for a file containing GPS coordinates:
56
57 <pre class=blk>Geolocation City : Saint-Hyacinthe
58 Geolocation Region : Quebec
59 Geolocation Subregion : Montérégie
60 Geolocation Country Code : CA
61 Geolocation Country : Canada
62 Geolocation Time Zone : America/Toronto
63 Geolocation Feature Code : PPL
64 Geolocation Feature Type : Populated Place
65 Geolocation Population : 50000
66 Geolocation Position : 45.6307, -72.9571
67 Geolocation Distance : 1.8 km
68 Geolocation Bearing : 226</pre>
69
70 The above tags are generated based on either a GPS position (preferentially), or
71 from city, state/province and country information. Note that the term "City"
72 used in this context may be more aptly called "Feature Name" since the database
73 may include some features which are not cities. Also, the meanings of the
74 resulting region and subregion tags vary by country. In North America for
75 example, region corresponds to state or province, and subregion corresponds to
76 county. The population is rounded to 2 significant digits, and the distance and
77 bearing are generated only when an input GPS position is provided, and give the
78 distance in km and the compass bearing from the input GPS point to the
79 GeolocationPosition of the returned city. See the
80 <a href="TagNames/Extra.html">Extra Tags documentation</a> for a brief description
81 of each Geolocation tag.</blockquote>
82
83 <a name="DefTags"></a>
84 <p><b>Default tags</b></p>
85
86 <blockquote>The Geolocation option has a list of default tags that it looks for
87 in the source file to use as inputs for determining the nearest city. These tags
88 are, in order:
89
90 <blockquote>GPSLatitude, GPSLongitude, GPSLatitudeRef, GPSLongitudeRef,
91 GPSCoordinates, LocationShownGPSLatitude, LocationShownGPSLongitude,
92 XMP:City, State, CountryCode, Country,
93 IPTC:City, Province-State, Country-PrimaryLocationCode, Country-PrimaryLocationName,
94 LocationShownCity, LocationShownProvinceState, LocationShownCountryCode,
95 LocationShownCountryName</blockquote>
96
97 First, the file is checked for GPS tags in this list, and coordinates from the
98 first available of these tags are used as inputs to determine the geolocation.
99 If no GPS position is found, the file is checked for
100 city/state/province/country/countrycode tags in the list, and the inputs are
101 taken from the first available city information. Note that each specified city
102 tag must come before the corresponding state/province, etc. If multiple
103 matches are found, the city with the largest population is returned unless
104 the <code>-a</code> (API <a href="ExifTool.html#Duplicates">Duplicates</a>)
105 option is used in which case all matching cities are returned.</blockquote>
106
107 <blockquote>To override the default list of tags, set the Geolocation option
108 to a comma-separated list of tags beginning with dollar signs, but <b>note that
109 Composite tags may not be used</b>. For example:
110
111 <pre>exiftool -api geolocation="$XMP:GPSLatitude,$XMP:GPSLongitude" test.jpg</pre>
112
113 <i>(Note: On Mac/Linux/PowerShell, use single quotes (<code>'</code>) instead
114 of double quotes (<code>"</code>) around arguments containing a dollar sign
115 (<code>$</code>).)</i></blockquote>
116
117 <a name="DefInput"></a>
118 <p><b>Default input</b></p>
119
120 <blockquote>It may be useful to specify a default input for the case where none
121 of the specified tags are found. For this, the default input is added to the
122 Geolocation setting. For example, the information returned by this command
123 includes Geolocation information for the specified coordinates if none of the
124 default tags listed above are found:
125
126 <pre>exiftool -api geolocation="44.3414,-72,1234" test.jpg</pre>
127
128 Alternately, default city information may be specified. When doing this, the
129 city name comes first, and is optionally followed by region (eg. state or
130 province), subregion (eg. county), country code and/or country name in any
131 order, separated by commas. For example:
132
133 <pre>exiftool -api geolocation="London,England" test.jpg</pre>
134
135 The default tags may be specified at the same time as the default value to
136 override the pre-defined list of default tags, for example:
137
138 <pre>exiftool -api geolocation="$gpslatitude,$gpslatituderef,\
139 $gpslongitude,$gpslongituderef,-37.81,144.96" test.jpg</pre>
140
141 This feature may be used to generate geolocation information with no input file
142 at all. For example, this command:
143
144 <pre>exiftool -api geolocation=Munich,Germany</pre>
145
146 produces this output:
147
148 <pre class=blk>Geolocation City : Munich
149 Geolocation Region : Bavaria
150 Geolocation Subregion : Upper Bavaria
151 Geolocation Country Code : DE
152 Geolocation Country : Germany
153 Geolocation Time Zone : Europe/Berlin
154 Geolocation Feature Code : PPLA
155 Geolocation Feature Type : Seat Of A First-order Administrative Division
156 Geolocation Population : 1300000
157 Geolocation Position : 48.1375, 11.5755</pre>
158
159 If both city name and GPS coordinates are provided, the nearest city
160 matching the specified name(s) is returned, and the result includes the
161 distance and compass bearing from the specified GPS position to this city.
162 For example:
163
164 <pre class=blk>> <span class=code>exiftool -api geolocation=44,-76,Kingston</span>
165 Geolocation City : Kingston
166 Geolocation Region : Ontario
167 Geolocation Subregion : Frontenac County
168 Geolocation Country Code : CA
169 Geolocation Country : Canada
170 Geolocation Time Zone : America/Toronto
171 Geolocation Feature Code : PPL
172 Geolocation Feature Type : Populated Place
173 Geolocation Population : 110000
174 Geolocation Position : 44.2298, -76.4810
175 Geolocation Distance : 46.12 km
176 Geolocation Bearing : 296</pre>
177
178 Multiple nearby cities may be returned instead of just the nearest by adding
179 <code>num=##</code> to the Geolocation option string, where <code>##</code> is the
180 desired number of cities. The returned cities are ordered from nearest to
181 furthest, and distinguished by the family 3 (document number) group which allows
182 them to be output as separate lines with the <code>-p</code> option. For example,
183 the nearest cities to a specified GPS position:
184
185 <pre class=blk>> <span class=code>exiftool -ee -p geo.fmt -api geolocation=49.48,6.37,num=4</span>
186 7.00 km,286 deg,PPLA3,Mondorf-les-Bains,Luxembourg
187 7.24 km,357 deg,PPLA2,Remich,Luxembourg
188 11.55 km,80 deg,PPL,Orscholz,Germany
189 12.32 km,240 deg,PPL,Cattenom,France</pre>
190
191 or the nearest cities to a specified city:
192
193 <pre class=blk>> <span class=code>exiftool -ee -p geo.fmt -api geolocation="new york city,num=5"</span>
194 0.00 km,0 deg,PPL,New York City,United States
195 0.31 km,287 deg,PPL,Tribeca,United States
196 0.74 km,203 deg,PPLX,Financial District,United States
197 0.85 km,77 deg,PPLX,Chinatown,United States
198 0.92 km,255 deg,PPL,Battery Park City,United States</pre>
199
200 Note that the <code>-ee</code> option must be used for the <code>-p</code>
201 option to iterate through the returned cities since they are returned as
202 sub-documents. Here is the "geo.fmt" file used in the above commands:
203
204 <pre>$geolocationdistance,$geolocationbearing deg,$geolocationfeaturecode,$geolocationcity,$geolocationcountry</pre>
205
206 Or for a JSON-format output, a command like this may be useful:
207
208 <pre class=blk><span class=code>exiftool -j -g3 -api geolocation=49.48,6.37,num=4</span></pre>
209 </blockquote>
210
211 <a name="Reg"></a>
212 <p><b>Regular expressions</b></p>
213
214 <blockquote>An advanced feature allows standard Perl regular expressions of the
215 form <code>/expr/</code> to be used to match city, region, etc names. The
216 regular expression may be prefixed by "<code>ci</code>", "<code>re</code>",
217 "<code>sr</code>", "<code>cc</code>" or "<code>co</code>" to apply only to City,
218 Region, Subregion, CountryCode or Country names, otherwise the expression
219 matches any of these. A dash at the start is used to exclude matching entries
220 (eg. <code>-co/Canada/</code> excludes cities in Canada from the search). The
221 <b>regular expression matches are case sensitive</b> unless "<code>i</code>" is
222 added after the expression. For example:
223
224 <pre><span class=blk># this matches "Frontenac" in any place name (case insensitive<sup>&dagger;</sup>)</span>
225 exiftool -api geolocation=/frontenac/i
226
227 <span class=blk># while this matches "Frontenac" only in subregion names</span>
228 exiftool -api geolocation=sr/frontenac/i
229
230 <span class=blk># and this matches the city "Kingston" with "Ontario" in any other field</span>
231 exiftool -api geolocation=kingston,/ontario/i</pre>
232
233 One more feature allows both GPS and place names to be used together if no input
234 tags are found and the default value includes both of these. In this case the
235 closest city matching all of the specified names is returned. For example, to
236 find the closest city in Canada to a specified location, you could do this:
237
238 <pre>exiftool -api geolocation="40.784,-73.966,co/Canada/"</pre>
239
240 This technique may be useful if you were travelling near the border of
241 a country and want to keep the geolocated cities within that country.</blockquote>
242
243 <blockquote><sup>&dagger;</sup> <i>Currently case insensitivity applies only to ASCII characters.</i></blockquote>
244
245 <hr>
246 <a name="Write"></a>
247 <h3>Writing Geolocation Information</h3>
248
249 <blockquote>A write-only <a href="TagNames/Extra.html">Geolocate tag</a> is
250 provided as a convenience to simplify the writing of standard geolocation tags.
251 This is an alternative to using the API <a href="ExifTool.html#Geolocation">Geolocation</a>
252 option and copying the generated Geolocation tags individually to the desired
253 locations, and is completely independent of the API Geolocation setting
254 (although the <a href="#Params">optional parameters</a> still apply).</blockquote>
255
256 <blockquote>Writing the Geolocate tag with GPS coordinates generates city,
257 state/province, country code and country tags. By default, XMP tags are
258 generated (plus Keys:LocationName for videos), but group name(s) may be
259 specified to write tags to other locations (see table below). For example, to
260 write the XMP City, State, CountryCode and Country tags from specified GPS
261 coordinates:
262
263 <pre>exiftool "-geolocate=45.6429,-72.9374" test.jpg</pre>
264
265 or to write the IPTC tags from GPS coordinates in a file:
266
267 <pre>exiftool "-iptc:geolocate&lt;gpsposition" test.jpg</pre>
268
269 Conversely, GPS coordinates may be generated by writing Geolocate with a city
270 name. A region, subregion, country code and/or country name may be added in any
271 order after the city name, separated by commas. Fields must match exactly the
272 entries in the database, but case is not significant<sup>&dagger;</sup>. Regular expressions may
273 also be used in the same format as for the API Geolocation option
274 (<a href="#Reg">see above</a>). If more than one matching city is found then a
275 minor warning is issued and the tags are not written, but the IgnoreMinorErrors
276 option may be used to write tags for the matching city with the largest
277 population. For example, the following command writes XMP:GPSLatitude, etc and
278 IPTC:City, etc for Paris France.
279
280 <pre>exiftool -xmp:iptc:geolocate="paris,fr" test.jpg</pre>
281
282 The table below lists the tags that are written for each group name specified
283 for the Geolocate tag. Multiple group names may be used. In some cases,
284 different tags are written based on whether input GPS coordinates or a city name
285 were used. As mentioned, the Geolocate tag is for convenience only, and makes
286 it easier to write common tags listed in the table below. The API
287 <a href="ExifTool.html#Geolocation">Geolocation</a> option is more flexible and
288 may be used with the <code>-tagsFromFile</code> option to write any combination
289 of tags, but the command may be more complicated.
290
291 <blockquote><table width='90%' class='norm'>
292 <tr><th rowspan='2'>Group Name(s) Specified</th><th colspan='2'>Tags Written based on input...</th></tr>
293 <tr><th width='35%'>GPS coordinates</th><th width='35%'>City name</th></tr>
294 <tr><td align='center'><i>(none)</i></td><td>
295 XMP:City<br>
296 XMP:State<br>
297 XMP:CountryCode<br>
298 XMP:Country<br>
299 Keys:LocationName</td><td>
300 GPSLatitude<br>
301 GPSLongitude<br>
302 GPSLatitudeRef<br>
303 GPSLongitudeRef<br>
304 QuickTime::GPSCoordinates</td></tr>
305 <tr><td align='center'>XMP</td><td>
306 XMP:City<br>
307 XMP:State<br>
308 XMP:CountryCode<br>
309 XMP:Country</td><td>
310 <i>(only if XMP-exif not specified)</i><br>
311 XMP:GPSLatitude<br>
312 XMP:GPSLongitude</td></tr>
313 <tr><td align='center'>XMP-photoshop</td><td colspan='2'><div class='indent'>
314 XMP-photoshop:City<br>
315 XMP-photoshop:State<br>
316 XMP-photoshop:Country</div></td></tr>
317 <tr><td align='center'>XMP-iptcCore</td><td colspan='2'><div class='indent'>
318 XMP-iptcCore:CountryCode</div></td></tr>
319 <tr><td align='center'>XMP-exif</td><td colspan='2'><div class='indent'>
320 XMP-exif:GPSLatitude<br>
321 XMP-exif:GPSLongitude</div></td></tr>
322 <tr><td align='center'>XMP-iptcExt</td><td colspan='2'><div class='indent'>
323 XMP-iptcExt:LocationShownCity<br>
324 XMP-iptcExt:LocationShownProvinceState<br>
325 XMP-iptcExt:LocationShownCountryCode<br>
326 XMP-iptcExt:LocationShownCountryName<br>
327 XMP-iptcExt:LocationShownGPSLatitude<br>
328 XMP-iptcExt:LocationShownGPSLongitude</div></td></tr>
329 <tr><td align='center'>IPTC<br><i>(older IIM spec.)</i></td><td colspan='2'><div class='indent'>
330 IPTC:City<br>
331 IPTC:Province-State<br>
332 IPTC:Country-PrimaryLocationCode<br>
333 IPTC:Country-PrimaryLocationName</div></td></tr>
334 <tr><td align='center'>GPS or EXIF</td><td colspan='2'><div class='indent'>
335 GPS:GPSLatitude<br>
336 GPS:GPSLongitude<br>
337 GPS:GPSLatitudeRef<br>
338 GPS:GPSLongitudeRef</div></td></tr>
339 <tr><td align='center'>Keys</td>
340 <td>Keys:LocationName<br>(with "City, Region, Country")</td>
341 <td>Keys:GPSCoordinates</td></tr>
342 <tr><td align='center'>ItemList</td><td colspan='2'><div class='indent'>
343 ItemList:GPSCoordinates</div></td></tr>
344 <tr><td align='center'>UserData</td><td colspan='2'><div class='indent'>
345 UserData:GPSCoordinates</div></td></tr>
346 <tr><td align='center'>QuickTime</td><td colspan='2'><div class='indent'>
347 <i>(only if not written to Keys, ItemList or UserData)</i><br>
348 QuickTime:GPSCoordinates</div></td></tr>
349 </table></blockquote></blockquote>
350
351 <a name="Geotag"></a>
352 <p><b>While geotagging</b></p>
353
354 <blockquote>The special value of "geotag" may be used to represent the GPS
355 coordinates determined while <a href="geotag.html">geotagging</a> from a GPS
356 track file. For example:
357
358 <pre>exiftool -geolocate=geotag -geotag track.gpx c:\images</pre>
359
360 Regular expressions may be also used when geotagging. For example, to constrain
361 the search to cities within France or Germany:
362
363 <pre>exiftool -geolocate="geotag,co/France|Germany/" -geotag track.gpx c:\images</pre>
364
365 Limiting the search like this will result in better performance when geotagging
366 a large number of files, but the overhead is significant so it would degrade
367 performance if geotagging only a small number of files.</blockquote>
368
369 <hr>
370 <a name="Extra"></a>
371 <h3>Extra Features</h3>
372
373 <a name="Lang"></a>
374 <p><b>Language translations</b></p>
375
376 <blockquote>The exiftool <code>-lang</code> option (API <a href="ExifTool.html#Lang">Lang</a>
377 option) applies to the tags generated by the API
378 <a href="ExifTool.html#Geolocation">Geolocation</a> option.
379 <b>Note that this language translation feature is optional</b>, and requires
380 installation of an <a href="#Alt">alternate database</a>. For example,
381 with an alternate database installed:
382
383 <pre>exiftool -api geolocation=Munich,Germany -lang de</pre>
384
385 gives this output
386
387 <pre class=blk>Geolocation City : Muenchen
388 Geolocation Region : Bayern
389 Geolocation Subregion : Regierungsbezirk Oberbayern
390 Geolocation Country Code : DE
391 Geolocation Country : Bundesrepublik Deutschland
392 Geolocation Time Zone : Europe/Berlin
393 Geolocation Feature Code : PPLA
394 Geolocation Feature Type : Seat Of A First-order Administrative Division
395 Geolocation Population : 1300000
396 Geolocation Position : 48.1375, 11.5755</pre>
397
398 Note that the language coverage currently isn't very comprehensive, and may only
399 be used when reading (ie. not when writing the Geolocate tag or in the API
400 <a href="ExifTool.html#Geolocation">Geolocation</a> option setting), but may be
401 extended via user-defined translations (see <a href="#Custom">Customization</a>
402 below).</blockquote>
403
404 <a name="Params"></a>
405 <p><b>Optional parameters</b></p>
406
407 <blockquote>Four special API options are used as parameters in the geolocation
408 search for both the API Geolocation option and when writing the Geolocate tag.
409
410 <blockquote>
411 <table class='norm'>
412 <tr><th>API Option</th><th>Description</th></tr>
413 <tr><td><a href="ExifTool.html#GeolocMinPop">GeolocMinPop</a></td>
414 <td>Minimum city population to consider when searching for a city in the
415 database. This is compared with the populations from the database which are
416 stored with 2 significant digits. Cities with populations lower than this are
417 not considered in the search.</td></tr>
418 <tr><td><a href="ExifTool.html#GeolocMaxDist">GeolocMaxDist</a></td>
419 <td>When determining geolocation from input GPS coordinates, cities with
420 distances in km greater than this are ignored.</td></tr>
421 <tr><td><a href="ExifTool.html#GeolocFeature">GeolocFeature</a></td>
422 <td>Comma-separated list of feature codes to include in search, or to exclude
423 if the list starts with a dash (-). Valid feature codes are PPL, PPLA, PPLA2,
424 PPLA3, PPLA4, PPLA5, PPLC, PPLCH, PPLF, PPLG, PPLH, PPLL, PPLQ, PPLR, PPLS,
425 PPLW, PPLX, STLMT and Other, plus possible user-included codes if an alternate
426 database is used. See <a href="http://www.geonames.org/export/codes.html#P">here</a>
427 for a description of these codes.</td></tr>
428 <tr><td><a href="ExifTool.html#GeolocAltNames">GeolocAltNames</a></td>
429 <td>Flag to use alternate names if available when search for a city
430 name. Default is 1. See <a href="#Alt">Alternate databases</a> below
431 for more information.</td></tr>
432 </table></blockquote></blockquote>
433
434 <a name="Alt"></a>
435 <p><b>Alternate databases</b></p>
436
437 <blockquote>ExifTool is distributed with a geolocation database of cities
438 with population 2000 or greater (plus adm div down to
439 <a href="http://www.geonames.org/export/codes.html#P">PPLA2</a>), but a larger
440 database of cities with population 500 or greater and adm div down to
441 <a href="http://www.geonames.org/export/codes.html#P">PPLA4</a> may be downloaded
442 from the link below. This database also includes alternate city names and
443 language translations. To use the new database, unzip the downloaded file and add
444 the following line to your <a href="config.html">ExifTool config file</a>:
445
446 <pre>$Image::ExifTool::Geolocation::geoDir = '/PATH/TO/Geolocation500';</pre>
447
448 where <code>/PATH/TO</code> is the name of the directory containing the unzipped
449 Geolocation500 directory. <i>(Note that this may not work in Windows if there
450 are Unicode characters in the path name.)</i> The <code>$geoDir</code> variable
451 may also be set to an empty string to completely disable loading of a
452 Geolocation database, which may be useful for working with only a user-defined
453 database. As a convenience, <code>$geoDir</code> may be set at runtime via the
454 API <a href="ExifTool.html#GeoDir">GeoDir</a> pseudo-option.</blockquote>
455
456 <blockquote>A database of alternate city names and language translation files are
457 also included in the zip file. The alternate names are consulted only when a full
458 city name is provided in a search (ie. not using a regular expression), the API
459 <a href="ExifTool.html#GeolocAltNames">GeolocAltNames</a> option is set (which is
460 the default), and the AltNames.dat file is found and matches the number of
461 entries in the currently loaded Geolocation.dat database. For example, searching
462 for "Big Apple" with the alternate names enabled would return the information for
463 New York City.
464
465 <blockquote><table class='dl'>
466 <tr><td>Download database with cities of population 500 or<br>
467 greater, including alternate names and translations:<br>
468 (requires ExifTool 12.82 or later)</td>
469 <!-- NOTE: geo.txt on the web site is automatically updated by the publish script from this file name -->
470 <td><a href="https://exiftool.org/Geolocation500-20260407.zip">Geolocation500-20260407.zip</a> (8.1 MB)</td></tr>
471 </table></blockquote></blockquote>
472
473 <blockquote>A "build_geolocation" utility script is available to allow users
474 to build their own alternate geolocation databases for ExifTool. This utility
475 requires that the necessary input database files from
476 <a href="https://download.geonames.org/export/dump/">geonames.org</a> have been
477 downloaded, and provides control over the population thresholds and included
478 feature codes on a per-country basis.
479 <a href="build_geolocation.txt">Read the help documentation</a> or
480 <a href="https://exiftool.org/build_geolocation.zip">download the utility</a>
481 (requires Perl to run).</blockquote>
482
483 <blockquote>For example, the command below generates a database including cities
484 of population 2000 or greater, except 500 or greater in Canada and the U.S.,
485 plus all cities with feature class "PPL" regardless of population in Ontario
486 Canada and New York State, with alternate names and translations only for
487 English, French and German:
488
489 <pre>build_geolocation -p 2000 -p ca,us=500 -c "ca.ontario,us.new york=+PPL" -l en,fr,de DIR</pre>
490
491 For this command, the necessary geonames database files must exist in the
492 <code>DIR</code> directory, and the output will go to
493 "DIR/Geolocation_out" but the <code>-o</code> option may be used to specify
494 another directory (see <code>build_geolocation -h</code> for details). The
495 "<code>+PPL</code>" adds PPL to the list of features to always keep (which is
496 "PPLA,PPLA2" by default). Any feature type(s) from the geonames database
497 may be added -- this isn't restricted to just cities.</blockquote>
498
499 <a name="List"></a>
500 <p><b>Listing the database</b></p>
501
502 <blockquote>The exiftool application <code>-listgeo</code> option may be used to
503 list all entries in the Geolocation database, including any user-defined entries
504 (see below for a description of how to create these). For this output, the API
505 <a href="ExifTool.html#GeolocMinPop">GeolocMinPop</a>,
506 <a href="ExifTool.html#GeolocFeature">GeolocFeature</a> and
507 <a href="ExifTool.html#GeolocAltNames">GeolocAltNames</a> options are in effect, and
508 the application <code>-sort</code> and <code>-lang</code> options may be used to
509 sort the output alphabetically and/or apply a language translation.</blockquote>
510
511 <a name="Custom"></a>
512 <p><b>Customization</b></p>
513
514 <blockquote>User-defined database entries and language translations may be added
515 through definitions in the <a href="config.html">ExifTool config file</a>. (Note
516 that the config file must be UTF-8 encoded.)</blockquote>
517
518 <blockquote>Database entries are added in this format:
519
520 <pre>
521 <span class=blk># Add user-defined cities to the Geolocation lookup</span>
522 @Image::ExifTool::UserDefined::Geolocation = (
523 <span class=blk># (city,region,subregion,country_code,country,timezone,feature_code,population,lat,lon)</span>
524 ['Sinemorets','Burgas','Obshtina Tsarevo','BG','','Europe/Sofia','PPL',400,42.06115,27.97833],
525 ['Silistar','Burgas','Obshtina Tsarevo','BG','','Europe/Sofia','PPL',0,42.02199,28.00959],
526 ['Krapets','Dobrich','Obshtina Shabla','BG','','Europe/Sofia','PPL',300,43.62621,28.56669],
527 );</pre>
528
529 The city name, country_code, population and latitude/longitude fields must be
530 filled, but all other fields may be left empty if they are not applicable or not
531 known. If the country name is empty (as above), then the name from the database
532 is used if available, based on the specified country code. An optional
533 comma-separated list of alternate city names may be added as an additional item
534 after the longitude.</blockquote>
535
536 <blockquote>User-defined language translations take this format:
537
538 <pre><span class=blk># Add user-defined language translations (note that user-defined
539 # translations override any preexisting translations)</span>
540 %Image::ExifTool::Geolocation::geoLang = (
541 <span class=blk># translations for the Russian language</span>
542 ru => {
543 <span class=blk># city, region, subregion and/or country names may be specified
544 # alone to provide a translation for any matching name</span>
545 'Sinemorets' =&gt; 'синеморец',
546 'Bulgaria' =&gt; 'Болгария',
547 <span class=blk># a country code and optional region (joined without a comma) and an
548 # optional subregion may be added before the city to be more specific</span>
549 'BGBurgas,Obshtina Shabla,Silistar' =&gt; 'силистар',
550 'BG,Krapets' =&gt; 'Крапец',
551 <span class=blk># the city is omitted to specify only region, subregion or country name</span>
552 'GR,' => 'Греция', <span class=blk># translate country name only</span>
553 'BGBurgas,' => 'Бургас', <span class=blk># translate region name only</span>
554 'BGBurgas,Obshtina Tsarevo,' => 'Муниципалитет Царево',<span class=blk># subregion only</span>
555 },
556 <span class=blk># (add other languages here)</span>
557 );
558 </pre>
559
560 Translations in are organized into sections in the <code>%geoLang</code> hash
561 based on the language code (eg. "<code>ru</code>" in the example above). Within
562 each section are the key/value pairs which are used to apply the translation for
563 that language. The keys on the left are used to match names in the database,
564 translating them to the values on the right. Here is a breakdown of the format
565 of the keys on the left:
566
567 <blockquote><table class='norm'><tr><th>Key format</th><th>Matches...</th></tr>
568 <tr><td>Nnnn</td><td>any city, region, subregion or country with name "Nnnn"</td></tr>
569 <tr><td>,Nnnn</td><td>any city with name "Nnnn" in any region or country</td></tr>
570 <tr><td>CC,Nnnn</td><td>any city with name "Nnnn" in any region and any subregion of the country with code "CC"</td></tr>
571 <tr><td>CCRrrr,Nnnn</td><td>any city with name "Nnnn" in region "Rrrr" and any subregion of the country with code "CC"</td></tr>
572 <tr><td>CCRrrr,Ssss,Nnnn</td><td>any city with name "Nnnn" in region "Rrrr" and subregion "Ssss" of the country with code "CC"</td></tr>
573 <tr><td>CC,</td><td>the country with code "CC"</td></tr>
574 <tr><td>CCRrrr,</td><td>the region "Rrrr" in the country with code "CC"</td></tr>
575 <tr><td>CCRrrr,Ssss,</td><td>the subregion "Ssss" in region "Rrrr" of the country with code "CC"</td></tr>
576 </table></blockquote>
577
578 Entries in the table above are ordered from lowest priority at the top to
579 highest at the bottom, with the match of highest priority taking precedence when
580 translating a name.</blockquote>
581
582 <blockquote>User-defined language translations may be added for the default 'en'
583 language to affect the returned names when no language is specified.</blockquote>
584
585 <hr>
586 <a name="Troubleshooting"></a>
587 <h3>Troubleshooting</h3>
588
589 <a name="TR1"></a>
590 <p>1. <b>"ExifTool returns an unexpected city for the specified GPS coordinates"</b></p>
591
592 <blockquote>First, try listing a number of nearby cities to see if ExifTool is
593 just finding something closer. For example the following command lists the
594 10 cities nearest to a specified GPS position, where "LAT" and "LON" are signed
595 floating-point latitude and longitude:
596
597 <pre>exiftool -api geolocation=LAT,LON,num=10 -a -g3</pre>
598
599 If the expected city is in this list, take note of the feature codes and populations
600 of these cities. The API <a href="ExifTool.html#GeolocFeature">GeolocFeature</a>
601 and API <a href="ExifTool.html#GeolocMinPop">GeolocMinPop</a> options may be used
602 to limit the feature types and/or population of the returned cities according
603 to your requirements. For example, to avoid returning PPLX city types and cities
604 with population less than 10000, you could do this:
605
606 <pre>exiftool -api geolocfeature=-PPLX -api geolocminpop=10000 ...</pre>
607
608 However, if your city doesn't appear in the list, then it is likely that it
609 doesn't exist in the ExifTool Geolocation database. You can check this by
610 searching for the specific city in the ExifTool database. This command returns
611 all cities with name "CITYNAME" exactly (case insensitive):
612
613 <pre>exiftool -api geolocation="CITYNAME" -m -a -g3</pre>
614
615 or this command may be used to match cities with "STRING" anywhere in their name
616 (the added "<code>i</code>" makes the match case insensitive):
617
618 <pre>exiftool -api geolocation="ci/STRING/i" -m -a -g3</pre>
619
620 A city may not appear in the ExifTool Geolocation database if the population
621 is lower than a minimum, which is 2000 for the standard database. An
622 <a href="#Alt">alternate database</a> is available with cities down to population
623 500, but it may be a good idea to first see if the city exists in the source
624 geonames.org database. Use the search field <a href="https://www.geonames.org">here</a>
625 to see if the city does exist and to determine its population and feature codes
626 (click on the appropriate city in the list returned by the search).</blockquote>
627
628 <blockquote>If the city doesn't exist at geonames.org or has incorrect information,
629 there are two things you can do: 1. Create an account and geonames.org and update
630 their database with the correct information. This information will eventually
631 propagate down to ExifTool (probably within a few months), or you can build your
632 own <a href="#Alt">alternate database</a>. Or 2. Create a
633 <a href="#Custom">user-defined entry</a> for your city in the ExifTool config file.
634 </blockquote>
635
636 <hr>
637 <i>Created Mar 12, 2024</i><br>
638 <i>Last revised Apr 7, 2026</i>
639 <p class='lf'><a href="index.html">&lt;-- Back to ExifTool home page</a></p>
640 </body>
641 </html>