VBA, the WIA interface, and writing GPS coordinate data

SimonL

New member
Local time
Today, 20:41
Joined
Jan 12, 2022
Messages
8
I'm new on here so apologise in advance for any inadvertent breaches of etiquette.

I've been developing an Access database to store details of my photo collection, almost all *JPGs, and using the Windows Image Acquisition API to read/write EXIF data from/to the image files. The documentation at Windows Image Acquisition (WIA) - Win32 apps | Microsoft Docs is fairly limited, but I managed to get everything working OK until it came to dealing with GPS latitude and longitude co-ordinates. I can read them fine, but when I try to write them to an image file I get an error message as follows:

"Run-time error '-2147467259 (80004005)': Unspecified error"

That is is not really very helpful, I think you'll agree.

The essence of the code I'm trying to get to work is:

Code:
Set objImg = New WIA.ImageFile
Set objIP = New WIA.ImageProcess
Set objVectorLat = New WIA.Vector

    With objIP
        .Filters.Add (.FilterInfos("Exif").FilterID)
        .Filters(1).Properties("ID") = IMG_GPSLAT '= 2
        .Filters(1).Properties("Type") = VectorOfUnsignedRationalsImagePropertyType '= 1106
        With objVectorLat
            .Add GPSData.GPSLat(0), 0
            .Add GPSData.GPSLat(1), 0
            .Add GPSData.GPSLat(2), 0
        End With
        .Filters(1).Properties("Value") = objVectorLat

        objImg.LoadFile strImgPathCurrent 'Load file for filter application
        Set objImg = .Apply(objImg) 'apply filter
        objImg.SaveFile strImgPathNew 'save updated image to new/temporary file
    End With

Where GPSData is a user defined type containing, inter alia, a GPS latitude in degrees/minutes/seconds in a 3 element array of double precision floating point numbers.

The code fails on Set objImg = .Apply(objImg). I'm thinking that the problem is something to do with getting data into the VectorOfUnsignedRationalsImagePropertyType, since there isn't such an animal as an unsigned rational in VBA, but the documentation on how to use vectors of that type is extremely thin, and I have now tried everything I can think of to get things to work and have now run out of ideas. Does anyone have any suggestions?
 
Last edited:
Solution
I agree.
I missed that you do not add the type as a whole to the Vector but only the double values of the latitude array.
Nevertheless, as you assumed yourself, adding the Doubles is the problem. If you use Wia.Rationals instead the error will go away.
Works like a charm. Thanks for the help
there is a discussion here that Successfully put the GPS meta data to 10 images (in csv file) using ExifTools.
you can put Exiftools in Attachment field and Extract it when needed to your folder of choice.
then run it from there.

Add GPS Coordinates to EXIF (exiftool.org)
 
I don't know about Simon's reasons for editing the data,
Apart from the digital photos taken with non GPS fitted equipment, around 5,000 of my collection are scans from transparencies or prints. Although it's fairly labour intensive I have found that I can almost always identify the location on Google Maps or via Street View - at least to a level of precision that's useful if not completely accurate - so as part of a cataloguing exercise I've started adding GPS data to the img files, but have had to use one of the fields editable via Windows as a temporary measure while I tried to find a way of doing it through the database I've been working on.

Also, as Sonic8 pointed out above, devices sometimes err dramatically in GPS. It's true it doesn't seem to happen very often, but I've been located several times by my Iphone in the middle of the waters of the Forth, when I was actually well South of Edinburgh
 
I agree.
I missed that you do not add the type as a whole to the Vector but only the double values of the latitude array.
Nevertheless, as you assumed yourself, adding the Doubles is the problem. If you use Wia.Rationals instead the error will go away.
Works like a charm. Thanks for the help
 
Solution

Users who are viewing this thread

Back
Top Bottom