Skip to content

Commit d555cb2

Browse files
authored
Update geoJSON_export.lua
cleanup
1 parent 750d70b commit d555cb2

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

contrib/geoJSON_export.lua

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ local function create_geoJSON_file(storage, image_table, extra_data)
9494

9595
dt.print_error("Will try to export geoJSON file now")
9696

97-
local xportDirectory = dt.preferences.read("geoJSON_export","ExportDirectory","string")
97+
local exportDirectory = dt.preferences.read("geoJSON_export","ExportDirectory","string")
9898

9999
-- Creates dir if not exsists
100100
local imageFoldername = "files/"
@@ -106,8 +106,8 @@ local function create_geoJSON_file(storage, image_table, extra_data)
106106
if ((image.longitude and image.latitude) and
107107
(image.longitude ~= 0 and image.latitude ~= 90) -- Sometimes the north-pole but most likely just wrong data
108108
) then
109-
local path, filename, filetype = string.match(image, "(.-)([^\\/]-%.?([^%.\\/]*))$")
110-
filename = string.upper(string.gsub(filename,"%.", "_"))
109+
local path, filename, filetype = string.match(exported_image, "(.-)([^\\/]-%.?([^%.\\/]*))$")
110+
filename = string.upper(string.gsub(filename,"%.%w*", ""))
111111

112112
-- convert -size 92x92 filename.jpg -resize 92x92 +profile "*" thumbnail.jpg
113113
-- In this example, '-size 120x120' gives a hint to the JPEG decoder that the image is going to be downscaled to
@@ -123,7 +123,7 @@ local function create_geoJSON_file(storage, image_table, extra_data)
123123
end
124124

125125
-- delete the original image to not get into the kmz file
126-
os.remove(image)
126+
os.remove(exported_image)
127127

128128
local pattern = "[/]?([^/]+)$"
129129
filmName = string.match(image.film.path, pattern)
@@ -140,11 +140,24 @@ local function create_geoJSON_file(storage, image_table, extra_data)
140140
]]
141141

142142
for image,exported_image in pairs(image_table) do
143-
filename = string.upper(string.gsub(image.filename,"%.", "_"))
143+
--filename = string.upper(string.gsub(image.filename,"%.", "_"))
144+
-- Extract filename, e.g DSC9784.ARW -> DSC9784
145+
filename = string.upper(string.gsub(image.filename,"%.%w*", ""))
146+
-- Extract extension from exported image (user can choose JPG or PNG), e.g DSC9784.JPG -> .JPG
147+
extension = string.match(exported_image,"%.%w*$")
144148

145149
if ((image.longitude and image.latitude) and
146150
(image.longitude ~= 0 and image.latitude ~= 90) -- Sometimes the north-pole but most likely just wrong data
147151
) then
152+
153+
local image_title, image_description
154+
if (image.title and image.title ~= "") then
155+
image_title = image.title
156+
else
157+
image_title = image.filename
158+
end
159+
image_description = image.description
160+
148161
geoJSON_file = geoJSON_file..
149162
[[ {
150163
"type": "Feature",
@@ -155,8 +168,8 @@ local function create_geoJSON_file(storage, image_table, extra_data)
155168
geoJSON_file = geoJSON_file..
156169
[[ },
157170
"properties": {
158-
"title": "]]..image.title..[[",
159-
"description": "]]..image.description..[[",
171+
"title": "]]..image_title..[[",
172+
"description": "]]..image_description..[[",
160173
"image": "]]..imageFoldername..filename..[[.jpg",
161174
"icon": {
162175
"iconUrl": "]]..imageFoldername.."thumb_"..filename..[[.jpg",
@@ -187,7 +200,7 @@ local function create_geoJSON_file(storage, image_table, extra_data)
187200
<html>
188201
<head>
189202
<meta charset=utf-8 />
190-
<title>2014-05-31 Rieselfelder</title>
203+
<title>]]..filmName..[[</title>
191204
<script src='https://api.tiles.mapbox.com/mapbox.js/v2.2.4/mapbox.js'></script>
192205
<link href='https://api.tiles.mapbox.com/mapbox.js/v2.2.4/mapbox.css' rel='stylesheet' />
193206
<style>

0 commit comments

Comments
 (0)