spatial-data-discovery / sdd-2021

Fall 2021 semester repository.
0 stars 1 forks source link

Sandbox 2 | Where in the world where these taken? #5

Open dt-woods opened 3 years ago

dt-woods commented 3 years ago

The Challenge

A client has asked you to identify where in the world a set of photos were taken. If possible, they would really like to see these locations as points on a map. All you have access to are the original JPEG image files (.zip).

Your challenge is to write a script that reads the coordinates from each image file, save the coordinates to a GeoJSON plain text file noting which image each set of coordinates belongs to, and, display the coordinates on a map to easily identify where the photos were taken.

Save your script to the sandbox folder of this repository and name it with your username (e.g., sb2_dt-woods.py).

Drag-and-drop an image of your point-location map into the Issue comments below. Please respect the repository and scale your images such that they are about 1000 kB or less.

Keep track of the methods you use and the resources you find along the way. Background information is provided for you to help you along your way.

Background

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), which is also referred to by the International Association of Oil & Gas Producers (previously the European Petroleum Survey Group) registry code, EPSG:4326. Given these three pieces of information, we can identify any given point on the globe.

Hellerick, 2013. Licensed CC BY-SA 3.0

The GeoJSON File Format

{
  "type": "Feature",
  "geometry": {
    "type": "Point",
    "coordinates": [125.6, 10.1]
  },
  "properties": {
    "name": "Dinagat Islands"
  }
}

With dimension zero, the most fundamental geometry in the vector data model is the point. To store point data, all you need are its coordinates (the x and the y or the longitude and latitude). Moreover, with spatial data, a given point may have meaning or context that is inherently important to that location (e.g., a name, an address, an elevation, a time-stamped image). These attributes should live with the coordinate in the dataset

One data format for storing such information is the geographic javascript object notation or GeoJSON. This format allows for the storage of all vector data model geometries (points, lines and polygons) as features or feature collections, providing a link to attributes, such as names or titles. This file format is written in plain text format with a file extension .json or .geojson.

There are several Python libraries available for reading/writing to JSON file types or you may simply write to file and follow the current GeoJSON convention.

Help one another out by posting links to the Python package(s) you are using to write to GeoJSON format in the comments below.

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.

There are libraries in the Python programming language that can read and extract GPS data from decoded Exif tags.

Help one another out by posting links to the Python package(s) you are using to read Exif tags from a JPEG image in the comments below.

References

More than you ever wanted to know about GeoJSON by Tom MacWright (2015).

dt-woods commented 3 years ago

Here's the snippet I started in class, most of which is pulled directly from the exifread package documentation site. Note, though, that there is more than one way to go about solving this.

import os
import exifread

my_dir = "photos"
if os.path.isdir(my_dir):
    my_files = os.listdir(my_dir)
    for my_file in my_files:
        my_file = os.path.join(my_dir, my_file)
        f = open(my_file, 'rb')
        tags = exifread.process_file(f)
        for tag in tags.keys():
            if tag not in ('JPEGThumbnail',
                           'TIFFThumbnail',
                           'Filename',
                           'EXIF MakerNote'):
                print("Key: %s, value %s" % (tag, tags[tag]))
LukeD77 commented 3 years ago

Here is my image for sb2!

Cool sandbox image

dt-woods commented 3 years ago

Here's some help for those having trouble with those pesky ratio GPS values:

bswhitneyWM commented 3 years ago

Here are the locations I got:

locationScreenshot

caroline-wall commented 3 years ago

Sandbox2 Point-Location Map:

Sandbox2
shaneevanson commented 3 years ago

Here's my very attractive map of the photo locations photo map

laurabrancati commented 3 years ago

here's a picture of my simple map!

Screen Shot 2021-09-27 at 5 30 19 PM

p!

sjl1970106 commented 3 years ago

map

pterwoo commented 3 years ago

This is the map that I produced!

photos-plotted.png