Overview
This script button will apply GPS coordinates copied from Google Maps to the selected image files.
How to use
- Go to Google Map
- Right click on the desired location and select "More info about this place"
- At the bottom of the map, there will display coordinates link like "40.274721, -92.445195". Click on it.
- The coordinates will display into the search input on the left. Copy them.
- In DOpus, select image files you want coordinates to apply to. (If you select all files in a tab, the script will automatically run on image files only.)
- Click on the button provided here and the GPS metadata will be applied.
- If the clipboard doesn't contain any supported GPS coordinates format, you'll be prompted to paste the coordinates.
How to install button
Download the desired button version and drag & drop it in a Dopus toolbar in customize mode.
Here is the english version:
Here is the french version of the button:
- ADD Google Maps GPS data [FRA].dcf (24.1 KB)
History
v2016.11.06
Fix : "42.018396,-105.234445" format was processed as invalid because the script expected there was a space after the comma such as "42.018396, -105.234445"
v2016.09.16
Fix : If among the selected files there were other file types, the script couldn't apply metadata to the image files
Change: No filter is required anymore. Valid files are automatically handled by the script.
v2016.09.13
Smart behavior: if the clipboard contains valid GPS (like "40.274721, -92.445195"), clicking the button will directly apply them to the selected image files else user will be prompted to enter coordinates.
v2016.09.12
First release: The button prompts user to enter GPS data.
Script Code:
The (English) script code is reproduced here for reference. The same or similar code is contained in the .dcf files above.
' v2016.11.06
' Here is a script button that will apply GPS coordinates copied from Google Maps to the selected image files.
' Source and Update: https://resource.dopus.com/viewtopic.php?f=35&t=27486
Function OnClick(ByRef ClickData)
' Clear the log output
' DOpus.ClearOutput
' ============================================================================
' INITIATE VARIABLES & OBJECT
' ============================================================================
Match = 0
Set cmd = ClickData.Func.command
Set srce = ClickData.Func.sourcetab
Dim GpsInput
' Dialog default values
Title = "GPS coordinates"
Message = "Paste the coordinates you copied from Google Maps."& vbCrLf & vbCrLf &"Valid format is for ex: 47.338388, 0.990228"
Buttons = "&OK|&Cancel"
Icon = "question"
' ============================================================================
' FILTER FILES TO BE PROCESSED
' ============================================================================
' DOpus.Output "Selected files BEFORE filter : " & srce.selected_files.count
' DOpus.Output "Files that will actually be processed BEFORE filter : " & cmd.files.count
cmd.ClearFiles ' All items are removed from the collection so only image files will be added next
' DOpus.Output ""
' DOpus.Output "FILTERING…"
' DOpus.Output ""
n = 1
For Each f In srce.selected_files
' If a selected file can handle GPS metadata, it will be added to files to process
If (f.metadata = "image") then
cmd.AddFile(f)
' DOpus.Output n & ". """ & f.name & """ will be processed"
End if
n = n+1
Next
' DOpus.Output ""
' Select files that will actually be processed
cmd.RunCommand("Select FROMSCRIPT DESELECTNOMATCH MAKEVISIBLE")
srce.Update ' Synchronize changes made by the previous select command to the sourcetab object. It can be useful if you need to use this object later.
' DOpus.Output "Selected files AFTER filter : " & srce.selected_files.count
' DOpus.Output "Files that will actually be processed AFTER filter : " & cmd.files.count
' ============================================================================
' RETRIEVE GPS COORDS
' ============================================================================
' Check if at least 1 file is selected to continue else warn and exit.
If cmd.files.count < 1 Then
Set dlg = ClickData.Func.Dlg
dlg.Request "No file selected or no valid file to process." & vbCrLf & "Please select at least 1 image file and run the command again.", "OK"
Set dlg = Nothing ' destroy dialog
Exit Function
End If
' Check if clipboard contains valid coordinates to apply
If DOpus.GetClipFormat = "text" Then
GpsInput = DOpus.GetClip
' DOpus.Output "GpsInput from CP : """ & GpsInput & """"
' Check if the clipboard content is a valid GPS coordinates
Set re = New RegExp
re.IgnoreCase = True ' No Case-sensitive matching.
re.Global = False ' Only first match will be matched
re.Pattern = "^(-?[1-8]?\d(?:\.\d{1,18})?|90(?:\.0{1,18})?),\s*?(-?(?:1[0-7]|[1-9])?\d(?:\.\d{1,18})?|180(?:\.0{1,18})?)$"
Set matches = re.Execute(GpsInput)
If matches.Count = 1 Then ' Case if values contains valid coordinates
Match = 1
' DOpus.Output "GpsInput from CP is VALID"
' DOpus.Output "Found " & matches.Count & " matches" & vbCRLF & "Match value : " & matches.Item(0).Value
Lat = matches.Item(0).SubMatches(0)
Lon = matches.Item(0).SubMatches(1)
' DOpus.Output "Latitude = " & Lat & vbCrLf & "Longitude = " & Lon
Else ' Case if clipboard doesn't contain valid coordinates
' Prompt the user to enter values, ask coordinates until they are valid
Do While Match = 0
' Create 1st Dialog object.
Set dlg = DOpus.Dlg
' Initialise the object to display a message with 2 buttons and 1 input box
dlg.Window = DOpus.Listers(0)
dlg.title = Title
dlg.message = Message
dlg.buttons = Buttons
dlg.icon = Icon
dlg.max = 128 ' enable the text field
ret = dlg.Show ' Show the dialog
' DOpus.Output "Dialog.Show returned " & ret
' DOpus.Output "The string you entered was " & dlg.input
If ret = 0 then ' When user cancel action, just quit the script
Exit Function
End If
GpsInput = dlg.input
' DOpus.Output "GpsInput from prompt : """ & GpsInput & """"
Set dlg = Nothing ' destroy 1st dialog prompt
' Check if the input content is a valid GPS coordinates
Set re = New RegExp
re.IgnoreCase = True ' No Case-sensitive matching.
re.Global = False ' Only first match will be matched
re.Pattern = "^(-?[1-8]?\d(?:\.\d{1,18})?|90(?:\.0{1,18})?),\s+?(-?(?:1[0-7]|[1-9])?\d(?:\.\d{1,18})?|180(?:\.0{1,18})?)$"
Set matches = re.Execute(GpsInput)
If matches.Count = 1 Then ' Case if values contains valid coordinates
Match = 1
' DOpus.Output "GpsInput from CP is VALID"
' DOpus.Output "Found " & matches.Count & " matches" & vbCRLF & "Match value : " & matches.Item(0).Value
Lat = matches.Item(0).SubMatches(0)
Lon = matches.Item(0).SubMatches(1)
' DOpus.Output "Latitude = " & Lat & vbCrLf & "Longitude = " & Lon
Else ' If fomat is invalid, warn the user and ask if he wants to retry or cancel.
' Just change default values for the 1st dialog that will pop up again because the loop
Title = "Invalid Format"
Message = "Coordinates you input are not a supported format"& vbCrLf & vbCrLf &"Please Try again"
Icon = "warning"
' Clear the log output
' DOpus.ClearOutput
End If
Loop
End If
End If
' ============================================================================
' APPLY GPS DATA
' ============================================================================
' DOpus.Output "Latitude = " & Lat & vbCrLf & "Longitude = " & Lon
' DOpus.Output "Number of selected files that the script will apply GPS : " & ClickData.Func.sourcetab.selected.count
cmd.RunCommand("SetAttr META gpslatitude:"&Lat&" gpslongitude:"&Lon&"")
End Function