import sys
import os
litte hack because somehow, exif didn’t install correctly
localapp = os.getenv(r’LOCALAPPDATA’)
sys.path.append(os.path.join(localapp, r’python-3.9.12-embed-amd64\Lib\site-packages’))
“”" Import packages “”"
from exif import Image # package to import exif-data
from pyproj import Transformer # package to perform coordinate transformation
import re # needed to get the filename, quiet sloppy
acceptable image formats
formats = (“.JPG”, “.jpg”, “.PNG”, “.png”)
EPSG-Code-From (Image)
EPSG_from = “EPSG:4326” # world geodetic system, GPS Standard
EPSG-Code-To (Output)
EPSG_to = “EPSG:31256” # e.g. UTM32N
“”" Extract necessary exif data “”"
function to convert Degrees/Minutes/Seconds to decimal degrees (account for N/E; S/W)
def decimal_coords(coords, ref):
decimal_degrees = coords[0] + coords[1] / 60 + coords[2] / 3600
if ref == “S” or ref == ‘W’:
decimal_degrees = -decimal_degrees
return decimal_degrees
function to extract necessary exif-data in the desired format
def image_coordinates(image_path):
with open(image_path, ‘rb’) as src: # rb = byte-data!
img = Image(src)
# get image name using regex (a bit ugly, but exif documentation doesn't help with img.name)
applyregex = re.search(r"^(.\*\\\\)(.\*)", image_path)
imgname = applyregex.group(2)
# 'has_exif' doesn't seem to do the job well enough, check manually instead
checklat = getattr(img, 'gps_latitude', None)
checklong = getattr(img, 'gps_longitude', None)
checkdir = getattr(img, 'gps_img_direction', None)
if checklat **and** checklong **and** checkdir:
try:
# Convert coordinates to decimal degree
coords = (decimal_coords(img.gps_latitude,
img.gps_latitude_ref),
decimal_coords(img.gps_longitude,
img.gps_longitude_ref))
# Transform coordinates using pyproj
transformation = Transformer.from_crs(EPSG_from, EPSG_to)
transformation_raw = (transformation.transform(coords\[0\], coords\[1\]))
# Return results
return (
{"Name": imgname,
"FullPath": image_path,
"Manufacturer": img.make,
"Model": img.model,
"Date": img.datetime_original,
"Geolocation_lat": coords\[0\],
"Geolocation_long": coords\[1\],
"Geolocation_transformed_X": transformation_raw\[0\],
"Geolocation_transformed_Y": transformation_raw\[1\],
"ImageDirection": img.gps_img_direction,
"Elevation": img.gps_altitude})
except AttributeError:
pass
# return("Can't process coordinates.")
else:
pass
# return("The Image has no EXIF information")
Apply funtions:
image_paths = IN[0]
output_raw =
for image in image_paths:
output_raw.append(image_coordinates(image))
OUT = output_raw