Guide to GPS metadata in photos (part 1). Geographical coordinates and their extraction from files

25 April 2023 10 minutes Author: Cyber Witcher

Programs for editing meta information for Windows and Linux

We already know that mat and mat2 can view and delete file metadata (many file types are supported). But what if instead of deleting, you need to change the metadata in a photo or document? These programs will not help in this task. There are other tools for this task that can modify the GPS coordinates, date and time of capture, camera information, and any other meta information that the file may contain. They can also selectively remove certain tags. For example, you can delete the GPS coordinates, but leave the information about the camera. On the contrary, you can add comments to the meta information, for example, with a description of the event and other comments about the shot.

In this guide, we’ll look at the different ways to record coordinates — to record or edit something, you need to understand it. We will also learn how to copy the coordinate values from the photo to the map so that you can view the shooting location without downloading the image to third-party services. We’ll also learn how to save metadata to a file so that metadata can be written to another photo, and how to copy metadata between photos. And as a bonus, we will learn to display only the metadata we need and change the format of their display.

In this guide, we will look at three amazing programs at once:

  • ExifTool

  • Exiv2

  • Geotag

They all work on both Linux and Windows – the links for each have detailed installation instructions. The Geotag program also has a graphical interface! That is, GPS spoofing (substitution) in photos is reduced to editing numbers in tablesі.

ExifTool.
Geotag.

When working with editing geographic coordinates, Geotag uses exactly ExifTool, so if you use Geotag on Windows, you also need to install ExifTool and specify the path to the file (everything is already in the instructions with the link above). By the way, mat2 also uses ExifTool to display and remove meta information. And Exiv2 uses, for example, the GIMP photo editor to display and edit meta information. The jhead program can also change metadata, but its capabilities are very limited – for example, it cannot change GPS coordinates in a photo.

Geographic coordinates

Geographic coordinates are latitude and longitude. Latitude defines the “up-down” location on the globe/map. The equator is considered zero. Longitude determines the “right-left” location on the globe/map. Zero is considered Greenwich. We will talk about the numbers themselves and how to guess “by eye” in which part of the planet the coordinates are located, and for now about how they are written, there are many coordinate formats.

Formats for recording geographic coordinates

Coordinates (latitude from -90 ° to +90 °, longitude from -180 ° to +180 °) can be recorded:

  • in ° degrees as a decimal fraction (modern version)

  • in ° degrees and ′ minutes with a decimal fraction

  • in ° degrees, ′ minutes and ″ seconds with a decimal fraction (the historical form of writing)

Negative signs of coordinates are either the sign “−” or letters:

  • “S” or “pd. sh.” – South latitude

  • “W” or “z. d.” – West Longitude

Letters can be both in front and behind. There are no single rules for writing coordinates

A decimal separator can be a period or a comma. Positive signs of the coordinates are represented by the (mostly omitted) sign “+” or letters:

  • “N” or “N. W.” – Northern latitude

  • “E” or “east” – Eastern longitude

An example of a record.

By default, search engine maps show coordinates in degrees with a decimal fraction with a “-” sign for negative longitude. On Google maps and Yandex maps, latitude first, then longitude. These coordinates are visible, for example, when laying routes from arbitrary points. Other formats are also recognized during the search. It is not necessary for us to understand all this in detail. From a practical point of view, we need to remember: you can search on map services (for example, Google Maps) for coordinates in the format “2 numbers with a decimal fraction; the separator of the decimal fraction is a point.”

For example, in the map search window, instead of a geographical name, you can enter two decimal numbers, for example: 12.459444 99.978611. And Maps will show you the place on the planet that is located according to the corresponding coordinates.

Coordinates in decimal numbers.

But in the metadata, the coordinates are stored as three numbers – that’s why programs that show file metadata also show them as three numbers (degrees, minutes and seconds) by default.

Еxiftool

Еxiv2

In principle, the coordinates are easily converted into decimal numbers, but this work can be omitted, more on that below. You can also add that, for example, Google Maps accepts the following formats:

  • Degrees, minutes and seconds: 41°24’12.2″N 2°10’26.5″E

  • Degrees and decimal minutes: 41 24.2028, 2 10.4418

  • Decimal degrees: 41.40338, 2.17403

But it is most convenient to use the decimal format.

Coordinate conversion.

How to output coordinates in decimal numbers from GPS metadata

ExifTool

If you get coordinates from a photo in the form of decimal numbers, you can find their location on map services without even downloading the image itself, but simply by performing a search by coordinates. I found two programs that can display coordinates in decimal form. The first program in which you can output exactly what you want by using options and specifying tag names.

Using the “-lang ru” option, you can display the name of the metadata tags in Russian:

exiftool -lang ru 20190930_095515.jpg

Meta information.

If you add the ‘-*GPS*’ option (quotes are required!), only meta information tags with the string “GPS” in their name will be displayed:

exiftool -lang ru ‘-*GPS*’  20190930_095515.jpg

Metadata with GPS term.

If only latitude and longitude are required, then the name of the tags is “-GPSLatitude -GPSLongitude”:

exiftool -lang ru -GPSLatitude -GPSLongitude 20190930_095515.jpg

Latitude and longitude metadata.

If you specify the -n option, the coordinates will be displayed in decimal form:

exiftool -lang ru -GPSLatitude -GPSLongitude -n20190930_095515.jpg

Опція -n.

To display only the six digits after the dot, and to use the minus sign instead of letters to indicate the hemispheres, you need to specify the -c ‘%+.6f’ option:

exiftool -lang ru -GPSLatitude -GPSLongitude -c ‘%+.6f’ 20190930_095515.jpg

Option -c ‘%+.6f’

Another program, Geotag is the addition of geographic identification metadata to various media such as geotagged photos or videos, websites, SMS messages, QR codes, or RSS feeds, and is a form of geospatial metadata. But you have to remember some important things. With the -n option, no letters will be used to indicate hemispheres, and negative numbers will be output if required.

The -c option allows you to set the format of the displayed coordinates. For example, if you have too many (or too few) digits after the decimal point, you can change their number with this option. Also, with the help of the -c option, you can configure not only the decimal format, but also any other – you can make absolutely any form of coordinate output.

Metadata from Geotag.

How to determine an exemplary location on the globe by coordinates

What can you say by looking at the following coordinates?

If nothing else, now we will learn to “by eye” determine an exemplary location by coordinates even without a map – at least in which hemispheres the coordinate is located and how far it is from the equator, Greenwich and the poles. Latitude determines the “up-down” location on the globe/map: 0 ° – the equator, 90 ° – the north pole (top of the globe), -90 ° – the south pole (bottom of the globe). Longitude defines the “right-to-left” location on the globe/map: 0 – Greenwich (London/UK), 0° to +180° east (right) and 0° to -180° west (left). Note that the latitude range is 180 degrees (half a circle) and the longitude range is 360 degrees (full circle). The range of longitude allows you to “move” around the entire circle of the globe (along the equator). And the range of latitude allows you to move only along the visible half – if you need to move beyond the north/south pole, then for this you need to change the longitude, that is, move to another part of the equator. Therefore, 180 ° latitude is enough, but 360 ° longitude is necessary. According to international agreement, the meridian that passes through the Greenwich Observatory (London, Great Britain) was assigned the value of 0° longitude, in other words, it was chosen as the longitude reference point on the globe. The longitude of other places is measured as the angle east or west of the prime meridian, ranging from 0° to +180° east and from 0° to −180° west”.

So, let’s go back to our coordinates

Latitude 12 (a positive number) means above the equator, but not much, about 1/7 of the height from the equator to the North Pole (90/12.46=7.22). Longitude 99 means a significant distance from the Greenwich line to the east – about a quarter of a turn of the globe East (180/99.97=0.55). (0.55 is about half of the eastern hemisphere, which is ½ of the entire earth). If the first number (latitude) were negative, the coordinate would be slightly below the equator. And if the second number were negative (longitude), then the displacement would be just as large, but to the west (from Greenwich/London).

How to find out the place where the photo was taken without using third-party services

If you do not want to upload a photo to any site or service, then this is a completely understandable desire. The first method is already shown above – remove the coordinates from the image, go to Google Maps and enter them in one of the following formats (separated by spaces and commas separating the numbers):

  • +12.459444 +99.978611

  • +12.459444, +99.978611

  • +12.459444,+99.978611

It is not necessary to write the + (plus) sign, but the minus sign (if present) must be written. If suddenly the coordinate does not have decimal digits, then add “.0” to it, otherwise the service will not understand that these are coordinates – both numbers must have a period and a number after it. The second way is to use Geotag. In one click, this program launches its local web server that hosts the map web page, opens the browser, and displays the photos on the map.

Start Geotag and add photos. Now we select the photos we want to see on the map (you can choose one or more or all). Right-click on the list of images and select.

Let’s start Geotag.

A browser will open with the following page. It should be noted that this is not a static picture, it is an interactive map with all the names. The address of the page is localhost, and the map has a menu with possible actions.

Interactive map.

Conversion of coordinates to decimal form and minutes/seconds

Before moving on to editing coordinates, let’s learn how to transform them. As mentioned above, coordinates are stored in three numbers (degrees, minutes and seconds). Some programs accept the new value of the coordinates in decimal form, and some in the form in which they are stored in the metadata (three rational numbers). Therefore, it is not superfluous to learn how to convert coordinates.

Conversion into decimal form is carried out according to the following formula:

DEGREE + MINUTES/60 + SECONDS/3600

The degree remains as it is, and the minutes and seconds are divided by 60 and 3600, respectively. If the line contains the letters S (south) or W (west), then the number is preceded by a minus sign.

In order not to count manually (besides, when converting to minutes and seconds, you need to perform several actions), we will write a small script that will do it for us. Let’s create a geoconverter.php file:

And copy all the data we have to it.

Example script.

1st method:

In this case, the coordinate will be calculated in the format of minutes and seconds.

2nd method:

In this case, the coordinate will be calculated in the format of a decimal number.

Other related articles
Found an error?
If you find an error, take a screenshot and send it to the bot.