I would like to create custom variable or a custom function to extract only "EXIF Camera Direction" of image from URL/path (field) of JPG images into QGIS. So i can directly write the formula within the expression or default value to get the exif camera direction.

I dont want to use ImportPhotos plugin because i already had the points feature and the field of image path, i also have empty field for the value of the camera direction, so how can i start for this learn?

the final custom function use like this:

img_exifdirection('field name of the img path') -----> value of the exif direction

note: im beginner in QGIS, but want to learn basic coding if needed to solve this

1 Answer 1


This works assuming that the camera actually writes the image direction to the EXIF. It seems that most cameras only write the location and maybe the altitude.

from PIL import Image
from PIL import ExifTags
from PIL.ExifTags import TAGS

def gps_azimuth(the_image):
    exifData = {}
    img = Image.open(the_image)
    exifDataRaw = img._getexif()
    for tag, value in list(exifDataRaw.items()):
        decodedTag = ExifTags.TAGS.get(tag, tag)
        exifData[decodedTag] = value
        image_direction = exifData['GPSInfo'][16]
    return image_direction

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.