Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bash script to copy Mapillary pictures from an iPhone, and update the EXIF data
#!/bin/bash
# This bash script copies pictures from Mapillary folders stored on an iPhone
# then update the pictures EXIF data to get the GPS and timestamp
# written by Christian Quest - August 2016
# requires jq and exiftool, if missing: apt install jq exiftool
# tested on Ubuntu 16.04
# copy Mapillary internal json data (contains GPS info, and more)
rsync /run/user/1000/gvfs/afc*/com.mapillary.app/cameras/internal/ internal -a
# copy picture files without thumbnails and keep a list of newfiles
rsync /run/user/1000/gvfs/afc*/com.mapillary.app/20* ./ -av --exclude *thumb.jpg | grep jpg > newfiles
# for each new file, get GPS data from Mapillary json (using jq)
for f in `cat newfiles`; do
# location of Mapillary json
json=`echo $f | sed 's!^.*/!internal/!;s!jpg!json!'`
# extract lat/lon/heading/precision from json using jq
lat=`jq -r .MAPLatitude $json`
lon=`jq -r .MAPLongitude $json`
heading=`jq -r .MAPCompassHeading.TrueHeading $json`
dop=`jq -r .MAPGPSAccuracyMeters $json`
# heading is offset by 90° on my iPhone... fix that ;)
heading=`echo "($heading+90)%360" | bc`
# get date/time from picture filename
time=`echo $json | sed 's!internal/...........!!;s!_....json$!!;s!_!:!g'`
date=`echo $f | sed 's!^.*/!!;s!..............jpg!!;s!_!/!g'`
# printout what we found...
echo "$json : $lon $lat $heading $dop $date $time"
# put these data back in the picture file EXIF data using exiftool
exiftool $f \
-P -q -overwrite_original \
-GPSLatitude=$lat -GPSLatitudeRef=N \
-GPSLongitude=$lon -GPSLongitudeRef=E \
-GPSImgDirection=$heading -GPSImgDirectionRef=T \
-GPSHPositioningError=$dop \
-GPSTimeStamp=$time -GPSDateStamp=$date -DateTimeOriginal="$date $time"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.