Skip to content

Robinlovelace/photomapr

Repository files navigation

photomapr

Travis build status AppVeyor build status

The goal of photomapr is to make it easier to create photomaps. A photomap is an interactive map which shows the location of places where photos have been taken. Ideally, photomaps should be able to display the photo of interest when you click on it.

Why create your own photomaps?

Photomaps and photo albums are a great way to share experiences and remember good times. A good example of a photomap is that created by default by Flickr when an album of geotagged photos has been created. The image below shows a publicly available Flickr photomap, showing photos taken during a cycling holiday from the Knepp Estate rewilding project to Lewes, which ended by passing though Marble Arch in London.

This approach has limitations, however. You must sign-up to Flickr and other services that create photomaps ‘in the cloud’, creating a barrier to entry. Furthermore, creating a photomap online often involves sending valuable and sometimes highly personal data to corporations. That can be problematic, as outlined in the book and podcast series Team Human by Douglas Rushkoff.

This package aims to make it easy to create photomaps locally and, if you want, deploy the results online. An example of photomaps is bookdown.org/robinlovelace/madrid-santiago-2019, a photomap developed using an early version of this package, a screenshot of which is shown below (see here to see how the package was used to create this photobook containing photomaps).

Installation

Install development version from GitHub with:

# install.packages("devtools")
devtools::install_github("robinlovelace/photomapr")

Usage

The first stage is to decide the photos you want. The package cannot help you with that, but once you do have a number of photo files, represented by photo_files below, you can convert them to a geographic data frame with the function photos_sf():

library(photomapr)

(photo_files = geotagged_photo_paths())
#> [1] "/home/robin/R/x86_64-pc-linux-gnu-library/4.2/photomapr/photos/IMG_20190523_120605_logo.jpg"
#> [2] "/home/robin/R/x86_64-pc-linux-gnu-library/4.2/photomapr/photos/IMG_20190523_135034_logo.jpg"
#> [3] "/home/robin/R/x86_64-pc-linux-gnu-library/4.2/photomapr/photos/IMG_20190524_104545_logo.jpg"
#> [4] "/home/robin/R/x86_64-pc-linux-gnu-library/4.2/photomapr/photos/IMG_20190524_110720_logo.jpg"
#> [5] "/home/robin/R/x86_64-pc-linux-gnu-library/4.2/photomapr/photos/IMG_20190524_200945_logo.jpg"
photos_geo = photos_sf(photo_files)
plot(photos_geo["DateTimeOriginal"], key.pos = 1)

Let’s create a simple photomap, using data shipped in the package:

photomap(photo_files)

You can also preview your photos with a slideshow in RStudio:

slideshow(photo_files) 

How it works

The package works bringing together functionality from a number of excellent packages, including:

  • leaflet for interactive maps
  • magick which provides powerful tools for image processing
  • exifr for extracting metadata (critically the GPS location) from photos
  • sf for providing a class system for spatial data

Thanks to the developers of these packages, and to everyone making and using open source software. Without you this project would be impossible.

Example workflow

library(tidyverse)
photos_zip = "/media/robin/T7/ColwallHerefordshire/Colwallgeotaggedimages.zip"
photos_path = gsub(pattern = ".zip", replacement = "", x = photos_zip)
dir.create(photos_path)
unzip(zipfile = photos_zip, exdir = photos_path)
list.files(photos_path)
photos_path = file.path("/media/robin/T7/ColwallHerefordshire/Colwallgeotaggedimages/mPix12Oct/")
list.files(photos_path)
photos_files = list.files(photos_path, full.names = TRUE)
p_sf = photos_sf(photos_files)
photos_to_keep = 1:9
p_sf_test = p_sf |> 
  slice(photos_to_keep) |> 
  transmute(file = basename(path = SourceFile)) |> 
  mutate(file = paste0('<a href="', file, '">', file, '</a>'))

dir.create("testphotofolder")
file.copy(from = photos_files[photos_to_keep], to = "testphotofolder")
f = list.files("testphotofolder", full.names = TRUE)
library(leaflet)
l = leaflet() |> 
  addTiles() |> 
  addMarkers(data = p_sf_test, popup = p_sf_test$file)
l
htmlwidgets::saveWidget(widget = l, file = "testphotofolder/index.html")
browseURL("testphotofolder/index.html")
p_sf_test
system("zip -r testphotofolder.zip testphotofolder")
piggyback::pb_upload("testphotofolder.zip")
piggyback::pb_download_url("testphotofolder.zip")

Next steps

  • Clicking on photos in photomap opens photo
  • Auto-generation of photo albums with maps
  • Deployment of photomaps online?

About

Package for converting geotagged photos into maps and albums/booklets

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages