Skip to content

Extracting Latitude Longitude from Images

Thomas Schranz edited this page Jul 25, 2017 · 10 revisions

Extracting Latitude/Longitude from Images

Add [io.joshmiller/exif-processor "0.2.0"] to your :dependencies in project.clj.

(ns exifdemo.core
  (:require [haversine.core      :as haversine]
            [exif-processor.core :as exif]
            [clojure.edn         :as edn]))

(def numbers-pattern #"[0-9]+[.]?[0-9]*")

; turns coordinate information represented as string "50° 49' 8.59" into numbers for degrees, minutes and seconds (50 49 8.59)
(defn parse-coordinate [s]
  (map edn/read-string (re-seq numbers-pattern s)))

(let [metadata (exif/exif-for-filename "/Users/tosh/Downloads/harbor-gps.jpg")
      latitude  (parse-coordinate (get metadata "GPS Latitude"))
      longitude (parse-coordinate (get metadata "GPS Longitude"))]
  (def latlng [latitude longitude]))

(defn dms-to-decimal [degrees minutes seconds]
  (+ degrees
    (/ minutes 60)
    (/ seconds 3600)))

{:latitude  (apply dms-to-decimal (first  latlng))
 :longitude (apply dms-to-decimal (second latlng))}
Clone this wiki locally