spatial-data-discovery / spatial-data-discovery.github.io

Organization website
https://spatial-data-discovery.github.io/
4 stars 0 forks source link

Sandbox Challenge - Where in the World? #7

Closed dt-woods closed 5 years ago

dt-woods commented 5 years ago

The Challenge

A client has asked you to identify where in the world a set of photos were taken. All you have access to are the original JPEG image files. How do you identify where they are from?

Write a script that reads the coordinates from each image file, write the coordinates to a plain text file, and map the coordinates in a GIS with a basemap to identify where the photos were taken.

Save your script to the sandbox folder in our repository with the file name "yourname.py" (e.g., davis.py). You may overwrite any existing file with the same name.

Background

The JPEG Image File Format

The modern JPEG (.jpg or .jpeg) file format allows for more than just compressed image data. Notably, the format allows for several types of metadata to be stored within the image file. The application-specific metadata known as Exif (exchangeable image file format) tags store several key pieces of information, including what is commonly referred to as location services metadata (aka spatial data). These metadata are stored thanks to the proliferation of inexpensive GPS receivers in modern smartphones.

Python has a library called exifread (available install using pip3 install exifread) that decodes the exif tags from image files.

The Vector Data Model

The vector data model for geographic information systems includes geometries for points, lines, and polygons (aka areas). For photographs, it is of interest to map point locations associated with where the photos were taken. To map point locations on the globe, there are three key pieces of information needed:

  1. angular unit of measurement
  2. origin
  3. datum

The angular unit of measure for our global coordinate reference system (CGS) is defined by the lines of longitude and latitude measured in degrees from the origin. For most geographic coordinate systems (GCS), the origin is assumed to be where the equator touches the prime meridian. A model for Earth's surface (or datum) is also provided for a given GCS. The most commonly used GCS for the whole world is the 1984 World Geodetic System (WGS84). Given these three pieces of information, we can identify a point on the globe.

A GIS can prescribe different origins and datums based on the user's choice CRS. The angular units of measurement are given as coordinate pairs of (latitude, longitude). Coordinates can be defined in decimal degrees or degrees minutes seconds (DMS). Longitude is measured east and west of the prime meridian, where east is defined positively and west is given a negative value. The anti-prime meridian (at 180 degrees) can be defined as either positive or negative. Latitude is measured north and south of the equator, where north is defined positively and south is given a negative number.

On the Map

Once you have found the coordinates from each of the image files, you can map them in QGIS as xy point data. The file format for loading xy point data into QGIS is as follows.

ID,LAT,LON,NAME
0,0.00,0.00,image001.jpg
1,0.00,0.00,image002.jpg
...

Note that each row following the header line represents one coordinate point to be mapped.