Okay, I took my advice and created reset_GPS.lua.  It works with my camera,
but I'm not sure if it works with others, so I've commented out all the
action lines and put in print lines to say what it would do.  Run darktable
from a console with -d lua then select an image and click the "reset GPS
info" button in the selected images module.  You can test it against images
with good GPS data and see if the answers match.

Bill

On Mon, Jun 15, 2020 at 2:54 PM William Ferguson <[email protected]>
wrote:

> The low tech way would be go to the map view and drag them back where they
> belong (if you know where that is).
>
> The higher tech way would be to copy clear_GPS_info.lua and rename it to
> reset_GPS_info.lua, then change the inner loop to run exiv2 against the
> file, retrieve the gps info, and set it.
>
> Another way would be to do a feature request for an option to not
> overwrite existing GPS data when doing a geotag.
>
> Bill
>
> On Mon, Jun 15, 2020 at 1:51 PM August Schwerdfeger <
> [email protected]> wrote:
>
>> When applying a geotag to an image from a GPX file, it automatically
>> clobbers any geotag that had been obtained from the file itself on import.
>> At this point, the only way I have found to get the in-file geotag back is
>> to remove the image from the database, delete the XMP sidecar, then
>> re-import.
>>
>> Is there any nicer way of doing this (other than remembering to add a
>> collect-by-geotag rule to exclude already-geotagged images before applying)?
>>
>> --
>> August Schwerdfeger
>> [email protected]
>>
>>
>> ____________________________________________________________________________
>> darktable user mailing list to unsubscribe send a mail to
>> [email protected]
>>
>

____________________________________________________________________________
darktable user mailing list
to unsubscribe send a mail to [email protected]
--[[

    reset_GPS.lua - export and edit with GIMP

    Copyright (C) 2016 Bill Ferguson <[email protected]>.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
]]
--[[
    reset_GPS - clear GPS data from selected image(s)

    This shortcut removes the GPS coordinate data from the selected images.

    ADDITIONAL SOFTWARE NEEDED FOR THIS SCRIPT
    * None

    USAGE
    * require this script from your main lua file
    * select an image or images
    * click the shortcut, clear GPS data

    BUGS, COMMENTS, SUGGESTIONS
    * Send to Bill Ferguson, [email protected]

    CHANGES
]]

local dt = require "darktable"
local du = require "lib/dtutils"
local df = require "lib/dtutils.file"

du.check_min_api_version("3.0.0", "reset_GPS") 

local PS = dt.configuration.running_os == windows and '\\' or '/'

local gettext = dt.gettext

-- not a number
local NaN = 0/0

local exiv2 = df.check_if_bin_exists("exiv2")

if exiv2 then


  -- Tell gettext where to find the .mo file translating messages for a particular domain
  gettext.bindtextdomain("reset_GPS",dt.configuration.config_dir.."/lua/locale/")

  local function _(msgid)
      return gettext.dgettext("reset_GPS", msgid)
  end

  local function extract_altitude(dat)
    return string.match(dat, "(%d-.?%d?) m$")
  end

  local function extract_degrees(dat)
    dt.print_log("dat is " .. dat)
    local deg = nil
    local min = nil

    deg, min = string.match(dat, "(%d-)deg (%d+.?%d+)")

    if deg then
      dt.print_log("deg is " .. deg)
    end

    if mins then
      dt.print_log("min is " .. min)
    end


    if deg then
      if min then
        deg = deg + min / 60.
        dt.print_log("deg is " .. deg)
      end
    end
    if deg then
      dt.print_log("deg is " .. deg)
    else
      dt.print_log("returning nil for dat " .. dat)
    end
    return deg
  end

  local function process_data(ref, dat)
    -- dt.print_log("ref is " .. ref)
    -- dt.print_log("dat is " .. dat)
    local sign = 1
    local result = nil

    if string.match(ref, "Above") then
      sign = 1
      result = extract_altitude(dat) * sign
    elseif string.match(ref, "Below") then
      sign = -1
      result = extract_altitude(dat) * sign
    elseif string.match(ref, "South") or string.match(ref, "West") then
      sign = -1
      result = extract_degrees(dat) * sign
    elseif string.match(ref, "North") or string.match(ref, "East") then
      sign = 1
      result = extract_degrees(dat) * sign
    else
      result = nil
    end

    return result
  end

  local function reset_GPS(images)
    local exiv2_args = " -g GPSInfo "
    for _, image in ipairs(images) do
      -- set the location information to Not a Number (NaN) so it displays correctly
      dt.print_log("processing " .. image.filename)
      local p = io.popen(exiv2 .. exiv2_args .. image.path .. PS .. image.filename)
      if p then
        local altitude = nil
        local latitude = nil
        local longitude = nil
        local GPSLatitudeRef = nil
        local GPSLatitude = nil
        local GPSLongitudeRef = nil
        local GPSLongitude = nil
        local GPSAltitudeRef = nil
        local GPSAltitude = nil
        for line in p:lines() do
          if string.match(line, "GPSLatitudeRef") then
            GPSLatitudeRef = line
          elseif string.match(line, "GPSLatitude") then
            GPSLatitude = line
          elseif string.match(line, "GPSLongitudeRef") then
            GPSLongitudeRef = line
          elseif string.match(line, "GPSLongitude") then
            GPSLongitude = line
          elseif string.match(line, "GPSAltitudeRef") then
            GPSAltitudeRef = line
          elseif string.match(line, "GPSAltitude") then
            GPSAltitude = line
          end
        end
        p:close()
        if GPSAltitudeRef and GPSAltitude then
          altitude = process_data(GPSAltitudeRef, GPSAltitude)
        end
        if GPSLatitudeRef and GPSLatitude then
          latitude = process_data(GPSLatitudeRef, GPSLatitude)
        end
        if GPSLongitudeRef and GPSLongitude then
          longitude = process_data(GPSLongitudeRef, GPSLongitude)
        end
        if latitude and longitude then
          if altitude then 
            --image.elevation = alititude 
            dt.print_log("altitude detected, would set elevation to " .. altitude)
          end
          --image.latitude = latitude 
          dt.print_log("latitude detected, would set latitude to " .. latitude)
          --image.longitude = longitude 
          dt.print_log("longitude detected, would set longitude to " .. longitude)
        else -- no gps info in image, so just clear it
          dt.print_log("no gps data detected, resetting to NaN")
          --image.elevation = NaN
          --image.latitude = NaN
          --image.longitude = NaN
        end
      else
        dt.print("Unable to read GPSInfo from image")
        dt.print_error("Unable to read GPSInfo from image")
      end
    end
  end


  dt.gui.libs.image.register_action(
    _("reset GPS data"),
    function(event, images) reset_GPS(images) end,
    "reset GPS data"
  )

  dt.register_event(
    "shortcut",
    function(event, shortcut) reset_GPS(dt.gui.action_images) end,
    "reset GPS data"
  )
else
  dt.print("Unable to locate exiv2.  Please ensure it is installed and in the path,\nor specifiy it's location using executable manager.")
end

Reply via email to