Update geoToolbox.lua
changed camel case to "_"
This commit is contained in:
@@ -42,24 +42,24 @@ end
|
|||||||
local labelDistance = dt.new_widget("label")
|
local labelDistance = dt.new_widget("label")
|
||||||
labelDistance.label = "Distance:"
|
labelDistance.label = "Distance:"
|
||||||
|
|
||||||
local labelCopyGPSlat = dt.new_widget("check_button")
|
local label_copy_gps_lat = dt.new_widget("check_button")
|
||||||
{
|
{
|
||||||
label = "latitude:",
|
label = "latitude:",
|
||||||
value = true
|
value = true
|
||||||
}
|
}
|
||||||
local labelCopyGPSlon = dt.new_widget("check_button")
|
local label_copy_gps_lon = dt.new_widget("check_button")
|
||||||
{
|
{
|
||||||
label = "longitude:",
|
label = "longitude:",
|
||||||
value = true
|
value = true
|
||||||
}
|
}
|
||||||
local labelCopyGPSele = dt.new_widget("check_button")
|
local label_copy_gps_ele = dt.new_widget("check_button")
|
||||||
{
|
{
|
||||||
label = "elevation:",
|
label = "elevation:",
|
||||||
value = true
|
value = true
|
||||||
}
|
}
|
||||||
-- </GUI>
|
-- </GUI>
|
||||||
|
|
||||||
local function selectWithGPS()
|
local function select_with_gps()
|
||||||
local selection = {}
|
local selection = {}
|
||||||
for _,image in ipairs(dt.database) do
|
for _,image in ipairs(dt.database) do
|
||||||
if (image.longitude and image.latitude) then
|
if (image.longitude and image.latitude) then
|
||||||
@@ -69,7 +69,7 @@ local function selectWithGPS()
|
|||||||
dt.gui.selection(selection)
|
dt.gui.selection(selection)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function selectWithoutGPS()
|
local function select_without_gps()
|
||||||
local selection = {}
|
local selection = {}
|
||||||
for _,image in ipairs(dt.database) do
|
for _,image in ipairs(dt.database) do
|
||||||
if (not image.longitude and not image.latitude) then
|
if (not image.longitude and not image.latitude) then
|
||||||
@@ -88,7 +88,7 @@ function isnan(x) return x ~= x end
|
|||||||
-- into a Unix timestamp (number of seconds since Jan 1, 1970, the standard
|
-- into a Unix timestamp (number of seconds since Jan 1, 1970, the standard
|
||||||
-- used by most systems). So we use the string.match() method to fetch the
|
-- used by most systems). So we use the string.match() method to fetch the
|
||||||
-- various date and time parts into their own variables: xyear, xmonth,etc.
|
-- various date and time parts into their own variables: xyear, xmonth,etc.
|
||||||
function makeTimeStamp(dateString)
|
function make_time_stamp(dateString)
|
||||||
local convertedTimestamp
|
local convertedTimestamp
|
||||||
--dt.print_error(dateString)
|
--dt.print_error(dateString)
|
||||||
if (dateString) then
|
if (dateString) then
|
||||||
@@ -115,7 +115,7 @@ local first_longitude = ''
|
|||||||
local first_elevation = ''
|
local first_elevation = ''
|
||||||
local first_image_date = 0
|
local first_image_date = 0
|
||||||
|
|
||||||
local function getFirstCoordinate()
|
local function get_first_coordinate()
|
||||||
local sel_images = dt.gui.selection()
|
local sel_images = dt.gui.selection()
|
||||||
|
|
||||||
first_latitude = ''
|
first_latitude = ''
|
||||||
@@ -139,7 +139,7 @@ local function getFirstCoordinate()
|
|||||||
first_elevation = image.elevation
|
first_elevation = image.elevation
|
||||||
end
|
end
|
||||||
if (image.exif_datetime_taken) then
|
if (image.exif_datetime_taken) then
|
||||||
first_image_date = makeTimeStamp(image.exif_datetime_taken)
|
first_image_date = make_time_stamp(image.exif_datetime_taken)
|
||||||
--dt.print_error(image.exif_datetime_taken)
|
--dt.print_error(image.exif_datetime_taken)
|
||||||
--dt.print_error(first_image_date)
|
--dt.print_error(first_image_date)
|
||||||
end
|
end
|
||||||
@@ -154,7 +154,7 @@ local second_longitude = ''
|
|||||||
local second_elevation = ''
|
local second_elevation = ''
|
||||||
local second_image_date = 0
|
local second_image_date = 0
|
||||||
|
|
||||||
local function getSecondCoordinate()
|
local function get_second_coordinate()
|
||||||
local sel_images = dt.gui.selection()
|
local sel_images = dt.gui.selection()
|
||||||
|
|
||||||
second_latitude = ''
|
second_latitude = ''
|
||||||
@@ -178,14 +178,14 @@ local function getSecondCoordinate()
|
|||||||
second_elevation = image.elevation
|
second_elevation = image.elevation
|
||||||
end
|
end
|
||||||
if (image.exif_datetime_taken) then
|
if (image.exif_datetime_taken) then
|
||||||
second_image_date = makeTimeStamp(image.exif_datetime_taken)
|
second_image_date = make_time_stamp(image.exif_datetime_taken)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local calcInBetweenSlider = dt.new_widget("slider")
|
local calc_in_between_slider = dt.new_widget("slider")
|
||||||
{
|
{
|
||||||
label = "Position between",
|
label = "Position between",
|
||||||
soft_min = 0, -- The soft minimum value for the slider, the slider can't go beyond this point
|
soft_min = 0, -- The soft minimum value for the slider, the slider can't go beyond this point
|
||||||
@@ -196,11 +196,11 @@ local calcInBetweenSlider = dt.new_widget("slider")
|
|||||||
}
|
}
|
||||||
|
|
||||||
--ToDo: this needs more love
|
--ToDo: this needs more love
|
||||||
local function calcInBetween()
|
local function calc_in_between()
|
||||||
local sel_images = dt.gui.selection()
|
local sel_images = dt.gui.selection()
|
||||||
for _,image in ipairs(sel_images) do
|
for _,image in ipairs(sel_images) do
|
||||||
if image then
|
if image then
|
||||||
image_date = makeTimeStamp(image.exif_datetime_taken)
|
image_date = make_time_stamp(image.exif_datetime_taken)
|
||||||
if (first_have_data and second_have_data) then
|
if (first_have_data and second_have_data) then
|
||||||
local start_new = 0
|
local start_new = 0
|
||||||
local end_new = second_image_date - first_image_date
|
local end_new = second_image_date - first_image_date
|
||||||
@@ -212,7 +212,7 @@ local function calcInBetween()
|
|||||||
else
|
else
|
||||||
percent_in_between = image_date_new/end_new
|
percent_in_between = image_date_new/end_new
|
||||||
end
|
end
|
||||||
calcInBetweenSlider.value = percent_in_between * 100
|
calc_in_between_slider.value = percent_in_between * 100
|
||||||
dt.print_error(percent_in_between)
|
dt.print_error(percent_in_between)
|
||||||
local in_between_latitude = first_latitude + (second_latitude - first_latitude) * percent_in_between
|
local in_between_latitude = first_latitude + (second_latitude - first_latitude) * percent_in_between
|
||||||
local in_between_longitude = first_longitude + (second_longitude - first_longitude) * percent_in_between
|
local in_between_longitude = first_longitude + (second_longitude - first_longitude) * percent_in_between
|
||||||
@@ -233,59 +233,59 @@ dt.print_error(in_between_elevation)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local copyGPS_have_data = false
|
local copy_gps_have_data = false
|
||||||
local copyGPS_latitude = ''
|
local copy_gps_latitude = ''
|
||||||
local copyGPS_longitude = ''
|
local copy_gps_longitude = ''
|
||||||
local copyGPS_elevation = ''
|
local copy_gps_elevation = ''
|
||||||
|
|
||||||
local function copyGPS()
|
local function copy_gps()
|
||||||
local sel_images = dt.gui.selection()
|
local sel_images = dt.gui.selection()
|
||||||
|
|
||||||
copyGPS_latitude = ''
|
copy_gps_latitude = ''
|
||||||
copyGPS_longitude = ''
|
copy_gps_longitude = ''
|
||||||
copyGPS_elevation = ''
|
copy_gps_elevation = ''
|
||||||
|
|
||||||
for _,image in ipairs(sel_images) do
|
for _,image in ipairs(sel_images) do
|
||||||
if not image then
|
if not image then
|
||||||
copyGPS_have_data = false
|
copy_gps_have_data = false
|
||||||
else
|
else
|
||||||
copyGPS_have_data = true
|
copy_gps_have_data = true
|
||||||
if (image.latitude and labelCopyGPSlat.value) then
|
if (image.latitude and label_copy_gps_lat.value) then
|
||||||
copyGPS_latitude = image.latitude
|
copy_gps_latitude = image.latitude
|
||||||
end
|
end
|
||||||
if (image.longitude and labelCopyGPSlon.value) then
|
if (image.longitude and label_copy_gps_lon.value) then
|
||||||
copyGPS_longitude = image.longitude
|
copy_gps_longitude = image.longitude
|
||||||
end
|
end
|
||||||
if (image.elevation and labelCopyGPSele.value) then
|
if (image.elevation and label_copy_gps_ele.value) then
|
||||||
copyGPS_elevation = image.elevation
|
copy_gps_elevation = image.elevation
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
labelCopyGPSlat.label = "latitude: " .. copyGPS_latitude
|
label_copy_gps_lat.label = "latitude: " .. copy_gps_latitude
|
||||||
labelCopyGPSlon.label = "longitude: " ..copyGPS_longitude
|
label_copy_gps_lon.label = "longitude: " ..copy_gps_longitude
|
||||||
labelCopyGPSele.label = "elevation: " .. copyGPS_elevation
|
label_copy_gps_ele.label = "elevation: " .. copy_gps_elevation
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function pastGPS(image)
|
local function past_gps(image)
|
||||||
local sel_images = dt.gui.selection()
|
local sel_images = dt.gui.selection()
|
||||||
|
|
||||||
for _,image in ipairs(sel_images) do
|
for _,image in ipairs(sel_images) do
|
||||||
if (labelCopyGPSlat.value) then
|
if (label_copy_gps_lat.value) then
|
||||||
image.latitude = copyGPS_latitude
|
image.latitude = copy_gps_latitude
|
||||||
end
|
end
|
||||||
if (labelCopyGPSlon.value) then
|
if (label_copy_gps_lon.value) then
|
||||||
image.longitude = copyGPS_longitude
|
image.longitude = copy_gps_longitude
|
||||||
end
|
end
|
||||||
if (labelCopyGPSele.value) then
|
if (label_copy_gps_ele.value) then
|
||||||
image.elevation = copyGPS_elevation
|
image.elevation = copy_gps_elevation
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function openLocationInGnomeMaps()
|
local function open_location_in_gnome_maps()
|
||||||
|
|
||||||
if not df.check_if_bin_exists("gnome-maps") then
|
if not df.check_if_bin_exists("gnome-maps") then
|
||||||
dt.print_error(_("gnome-maps not found"))
|
dt.print_error(_("gnome-maps not found"))
|
||||||
@@ -323,7 +323,7 @@ end
|
|||||||
|
|
||||||
-- I used code from here:
|
-- I used code from here:
|
||||||
-- http://stackoverflow.com/questions/27928/how-do-i-calculate-distance-between-two-latitude-longitude-points
|
-- http://stackoverflow.com/questions/27928/how-do-i-calculate-distance-between-two-latitude-longitude-points
|
||||||
local function getDistance(lat1, lon1, ele1, lat2, lon2, ele2)
|
local function get_distance(lat1, lon1, ele1, lat2, lon2, ele2)
|
||||||
|
|
||||||
local earthRadius = 6371; -- Radius of the earth in km
|
local earthRadius = 6371; -- Radius of the earth in km
|
||||||
local dLat = math.rad(lat2-lat1); -- deg2rad below
|
local dLat = math.rad(lat2-lat1); -- deg2rad below
|
||||||
@@ -346,7 +346,7 @@ local function getDistance(lat1, lon1, ele1, lat2, lon2, ele2)
|
|||||||
return distance
|
return distance
|
||||||
end
|
end
|
||||||
|
|
||||||
local function calcDistance()
|
local function calc_distance()
|
||||||
|
|
||||||
local sel_images = dt.gui.selection()
|
local sel_images = dt.gui.selection()
|
||||||
|
|
||||||
@@ -388,7 +388,7 @@ local function calcDistance()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local distance = getDistance(lat1, lon1, ele1, lat2, lon2, ele2)
|
local distance = get_distance(lat1, lon1, ele1, lat2, lon2, ele2)
|
||||||
|
|
||||||
if (distance < 1) then
|
if (distance < 1) then
|
||||||
distance = distance * 1000
|
distance = distance * 1000
|
||||||
@@ -400,12 +400,12 @@ local function calcDistance()
|
|||||||
return string.format("Distance: %.2f %s", distance, distanceUnit)
|
return string.format("Distance: %.2f %s", distance, distanceUnit)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function printCalcDistance()
|
local function print_calc_distance()
|
||||||
dt.print(calcDistance())
|
dt.print(calc_distance())
|
||||||
end
|
end
|
||||||
|
|
||||||
local function toolboxCalcDistance()
|
local function toolbox_calc_distance()
|
||||||
labelDistance.label = calcDistance()
|
labelDistance.label = calc_distance()
|
||||||
end
|
end
|
||||||
|
|
||||||
local altitude_file_chooser_button = dt.new_widget("file_chooser_button")
|
local altitude_file_chooser_button = dt.new_widget("file_chooser_button")
|
||||||
@@ -423,7 +423,7 @@ local altitude_filename = dt.new_widget("entry")
|
|||||||
reset_callback = function(self) self.text = "text" end
|
reset_callback = function(self) self.text = "text" end
|
||||||
}
|
}
|
||||||
|
|
||||||
local function altitudeProfile()
|
local function altitude_profile()
|
||||||
dt.print("Start export")
|
dt.print("Start export")
|
||||||
local sel_images = dt.gui.selection()
|
local sel_images = dt.gui.selection()
|
||||||
|
|
||||||
@@ -467,7 +467,7 @@ local function altitudeProfile()
|
|||||||
if (i == 1) then
|
if (i == 1) then
|
||||||
distanceFromStart = 0
|
distanceFromStart = 0
|
||||||
else
|
else
|
||||||
local distance = getDistance(lat1, lon1, ele1, lat2, lon2, ele2)
|
local distance = get_distance(lat1, lon1, ele1, lat2, lon2, ele2)
|
||||||
distanceFromStart = distanceFromStart + distance;
|
distanceFromStart = distanceFromStart + distance;
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -508,29 +508,29 @@ dt.register_lib(
|
|||||||
{
|
{
|
||||||
label = "select geo images",
|
label = "select geo images",
|
||||||
tooltip = "Select all images with GPS information",
|
tooltip = "Select all images with GPS information",
|
||||||
clicked_callback = selectWithGPS
|
clicked_callback = select_with_gps
|
||||||
},
|
},
|
||||||
dt.new_widget("button")
|
dt.new_widget("button")
|
||||||
{
|
{
|
||||||
label = "select not geo images",
|
label = "select not geo images",
|
||||||
tooltip = "Select all images without GPS information",
|
tooltip = "Select all images without GPS information",
|
||||||
clicked_callback = selectWithoutGPS
|
clicked_callback = select_without_gps
|
||||||
},
|
},
|
||||||
separator,--------------------------------------------------------
|
separator,--------------------------------------------------------
|
||||||
dt.new_widget("button")
|
dt.new_widget("button")
|
||||||
{
|
{
|
||||||
label = "copy GPS data",
|
label = "copy GPS data",
|
||||||
tooltip = "Copy the GPS data",
|
tooltip = "Copy the GPS data",
|
||||||
clicked_callback = copyGPS
|
clicked_callback = copy_gps
|
||||||
},
|
},
|
||||||
labelCopyGPSlat,
|
label_copy_gps_lat,
|
||||||
labelCopyGPSlon,
|
label_copy_gps_lon,
|
||||||
labelCopyGPSele,
|
label_copy_gps_ele,
|
||||||
dt.new_widget("button")
|
dt.new_widget("button")
|
||||||
{
|
{
|
||||||
label = "past GPS data",
|
label = "past GPS data",
|
||||||
tooltip = "Past the GPS data",
|
tooltip = "Past the GPS data",
|
||||||
clicked_callback = pastGPS
|
clicked_callback = past_gps
|
||||||
},
|
},
|
||||||
separator2,--------------------------------------------------------
|
separator2,--------------------------------------------------------
|
||||||
--ToDo: This need a better UI
|
--ToDo: This need a better UI
|
||||||
@@ -539,28 +539,28 @@ dt.register_lib(
|
|||||||
{
|
{
|
||||||
label = "get 1st coordinate",
|
label = "get 1st coordinate",
|
||||||
tooltip = "Select first image and click this button",
|
tooltip = "Select first image and click this button",
|
||||||
clicked_callback = getFirstCoordinate
|
clicked_callback = get_first_coordinate
|
||||||
},
|
},
|
||||||
dt.new_widget("button")
|
dt.new_widget("button")
|
||||||
{
|
{
|
||||||
label = "get 2nd coordinate",
|
label = "get 2nd coordinate",
|
||||||
tooltip = "Select second image and click this button",
|
tooltip = "Select second image and click this button",
|
||||||
clicked_callback = getSecondCoordinate
|
clicked_callback = get_second_coordinate
|
||||||
},
|
},
|
||||||
dt.new_widget("button")
|
dt.new_widget("button")
|
||||||
{
|
{
|
||||||
label = "calc in between",
|
label = "calc in between",
|
||||||
tooltip = "Select third image and click this button",
|
tooltip = "Select third image and click this button",
|
||||||
clicked_callback = calcInBetween
|
clicked_callback = calc_in_between
|
||||||
},
|
},
|
||||||
calcInBetweenSlider,
|
calc_in_between_slider,
|
||||||
separator3,--------------------------------------------------------
|
separator3,--------------------------------------------------------
|
||||||
]]
|
]]
|
||||||
dt.new_widget("button")
|
dt.new_widget("button")
|
||||||
{
|
{
|
||||||
label = "Open in Gnome Maps",
|
label = "Open in Gnome Maps",
|
||||||
tooltip = "Open Location in Gnome Maps",
|
tooltip = "Open Location in Gnome Maps",
|
||||||
clicked_callback = openLocationInGnomeMaps
|
clicked_callback = open_location_in_gnome_maps
|
||||||
},
|
},
|
||||||
separator4,--------------------------------------------------------
|
separator4,--------------------------------------------------------
|
||||||
dt.new_widget("label"){label = "altitude CSV export"},
|
dt.new_widget("label"){label = "altitude CSV export"},
|
||||||
@@ -570,7 +570,7 @@ dt.register_lib(
|
|||||||
{
|
{
|
||||||
label = "export altitude CSV file",
|
label = "export altitude CSV file",
|
||||||
tooltip = "create an altitude profile using the GPS data in the metadata",
|
tooltip = "create an altitude profile using the GPS data in the metadata",
|
||||||
clicked_callback = altitudeProfile
|
clicked_callback = altitude_profile
|
||||||
},
|
},
|
||||||
labelDistance
|
labelDistance
|
||||||
},
|
},
|
||||||
@@ -580,11 +580,11 @@ dt.register_lib(
|
|||||||
|
|
||||||
|
|
||||||
-- Register
|
-- Register
|
||||||
dt.register_event("shortcut",printCalcDistance,_("Calculate the distance from latitude and longitude in km"))
|
dt.register_event("shortcut",print_calc_distance,_("Calculate the distance from latitude and longitude in km"))
|
||||||
dt.register_event("mouse-over-image-changed",toolboxCalcDistance)
|
dt.register_event("mouse-over-image-changed",toolbox_calc_distance)
|
||||||
|
|
||||||
dt.register_event("shortcut", selectWithGPS, _("Select all images with GPS information"))
|
dt.register_event("shortcut", select_with_gps, _("Select all images with GPS information"))
|
||||||
dt.register_event("shortcut", selectWithoutGPS, _("Select all images without GPS information"))
|
dt.register_event("shortcut", select_without_gps, _("Select all images without GPS information"))
|
||||||
|
|
||||||
-- vim: shiftwidth=2 expandtab tabstop=2 cindent syntax=lua
|
-- vim: shiftwidth=2 expandtab tabstop=2 cindent syntax=lua
|
||||||
-- kate: hl Lua;
|
-- kate: hl Lua;
|
||||||
|
|||||||
Reference in New Issue
Block a user