Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for getlocation.bat

(view source code of getlocation.bat as plain text)

  1. @ECHO OFF
  2. SETLOCAL
  3. IF     "%~1"==""   GOTO Syntax
  4. IF     "%~1"=="/?" GOTO Syntax
  5. IF NOT "%~2"==""   GOTO Syntax
  6. IF NOT EXIST "%~1" (
  7. 	ECHO.
  8. 	ECHO ←[0;1;31mERROR:←[0m File not found
  9. 	GOTO Syntax
  10. )
  11. exiftool.exe >NUL 2>&1
  12. IF ERRORLEVEL 1 (
  13. 	ECHO.
  14. 	ECHO ←[0;1;31mERROR:←[0m EXIFTool.exe not found
  15. 	GOTO Syntax
  16. )
  17. FOR /F "tokens=2 delims=:" %%A IN ('exiftool.exe -a -G -gpslatitude  "%~1"') DO CALL :Calculate Latitude  "%%~A
  18. IF  "%Latitude%"=="" (
  19. 	ECHO.
  20. 	ECHO ←[0;1;31mERROR:←[0m No EXIF data or no GPS values in EXIF data
  21. 	GOTO Syntax
  22. )
  23. FOR /F "tokens=2 delims=:" %%A IN ('exiftool.exe -a -G -gpslongitude "%~1"') DO CALL :Calculate Longitude "%%~A
  24. IF "%Longitude%"=="" (
  25. 	ECHO.
  26. 	ECHO ←[0;1;31mERROR:←[0m No EXIF data or no GPS values in EXIF data
  27. 	GOTO Syntax
  28. )
  29. ECHO %Latitude%, %Longitude%
  30. START "Show on OpenStreetMap" "https://www.openstreetmap.org/?mlat=%Latitude%&mlon=%Longitude%&zoom=16"
  31. ENDLOCAL
  32. EXIT /B 0
  33.  
  34.  
  35. :Calculate
  36. SETLOCAL ENABLEDELAYEDEXPANSION
  37. FOR /F "usebackq tokens=1,3,4 delims=' " %%B IN (`ECHO %~2`) DO (
  38. 	SET Degrees=%%B
  39. 	SET /A Minutes = %%C
  40. 	SET Seconds=%%D
  41. 	SET Seconds=!Seconds:.=!
  42. 	SET /A Fraction = 6000 * !Minutes! + !Seconds!
  43. 	SET /A "Fraction = ( 1800 + 100 * !Fraction! ) / 3600"
  44. )
  45. ENDLOCAL & SET %1=%Degrees%.%Fraction%
  46. GOTO:EOF
  47.  
  48.  
  49. :Syntax
  50. ECHO.
  51. ECHO GetLocation.bat,  Version 1.00
  52. ECHO Open OpenStreetMap on the GPS coordinates of the specified photograph
  53. ECHO.
  54. ECHO Usage:  ←[0;1mGetLocation.bat  photo←[0m
  55. ECHO.
  56. ECHO Where:  ←[0;1mphoto←[0m   is the path to the photograph whose location you want to find
  57. ECHO.
  58. ECHO Notes:  Requires Phil Harvey's ExifTool:
  59. ECHO         ←[0;1;30mhttps://exiftool.org/←[0m
  60. ECHO         The author is in no way affiliated with OpenStreetMap:
  61. ECHO         ←[0;1;30mhttps://www.openstreetmap.org/←[0m
  62. ECHO         ErrorLevel 1 in case of ^(command line^) errors, otherwise 0.
  63. ECHO.
  64. ECHO Written by Rob van der Woude
  65. ECHO https://www.robvanderwoude.com
  66. ENDLOCAL
  67. EXIT /B 1
  68.  

page last modified: 2024-04-16; loaded in 0.0059 seconds