VBA, the WIA interface, and writing GPS coordinate data (1 Viewer)

SimonL

New member
Local time
Today, 03:59
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

jdraw

Super Moderator
Staff member
Local time
Yesterday, 22:59
Joined
Jan 23, 2006
Messages
14,318
Suggestion: Check Isladogs post in the similar threads at the bottom of this page.
 

SimonL

New member
Local time
Today, 03:59
Joined
Jan 12, 2022
Messages
8
Thanks for the suggestion. It looks good and I may go to Exiftools eventually, but at the moment I'm really frustrated that, having managed to get this far, I can't find a solution for myself. I'm not quite ready to give up and opt for a ready made answer.
 

sonic8

AWF VIP
Local time
Today, 04:59
Joined
Oct 27, 2015
Messages
593
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,
VectorOfUnsignedRationalsImagePropertyType is just an element of the WiaImagePropertyType enum.
You declared that enum, or at least the one constant you use, in your code, didn't you?
 

isladogs

CID VIP
Local time
Today, 03:59
Joined
Jan 14, 2017
Messages
16,219
Here is a Web link to my app:

Sample output:
1642000935246.png
 

SimonL

New member
Local time
Today, 03:59
Joined
Jan 12, 2022
Messages
8
Sorry Sonic 8. Having difficulty in posting anything using the reply button

Yes, I did declare the enum.

I didn't explain my thinking very well I'm afraid. As far as I understand it, the GPS latitude tag is a vector containing 3 values (degrees, minutes and seconds) defining the latitude of the location. The code above loads those three values into objVectorLat, which seems to work fine, then makes objVectorLat the value of the filter, which also seems to work fine. the VBA TypeName and VarType functions both say that each element of objVectorLat is of type Double - which is a signed data type, whereas the filter property type is unsigned, so I'm wondering if that might be where the problem is since the code only fails when it attempts to apply the filter to the file.
 

sonic8

AWF VIP
Local time
Today, 04:59
Joined
Oct 27, 2015
Messages
593
As far as I understand it, the GPS latitude tag is a vector containing 3 values (degrees, minutes and seconds) defining the latitude of the location.
That is correct.
But where did you get the idea to use your type GPSData from?
According to documentation, the values of the Vector should be of type Wia.Rational.
 

SimonL

New member
Local time
Today, 03:59
Joined
Jan 12, 2022
Messages
8
Sonic 8,

A routine elsewhere in the code parses GPS co-ordinates in decimal or degrees/minutes/seconds format (eg from Google Maps) and derives the 4 values required to define each point in the EXIF data: GpsLatitudeRef, GpsLongitudeRef, GpsLatitude, and GpsLongitude (I'm not really interested in any of the other GPS parameters like altitude or speed). It seemed sensible to group them together in a type
 

sonic8

AWF VIP
Local time
Today, 04:59
Joined
Oct 27, 2015
Messages
593
It seemed sensible to group them together in a type
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.
 

isladogs

CID VIP
Local time
Today, 03:59
Joined
Jan 14, 2017
Messages
16,219
Good point. I followed up on the alert from @draw. Should have studied post #1 more carefully!
However, I'm still unclear about the benefit or wisdom of editing EXIF data in photos...
 

sonic8

AWF VIP
Local time
Today, 04:59
Joined
Oct 27, 2015
Messages
593
However, I'm still unclear about the benefit or wisdom of editing EXIF data in photos...
Well, your very own example directly leads to the benefits...
I don't know about Simon's reasons for editing the data, but I myself faced situations in the past where I could have put such a feature to good use.
When I was traveling, I took a lot of photos with a camera that did not add GPS location information to the pictures. Back home I still could remember pretty accurately where each picture was taken. As there usually were multiple photos at one location, I would have liked a tool to retroactively add the GPS info to these photos. I would then be able to use an application such as your example, to visualize the location of the photos years later when I was not able to remember the location anymore.
I actually wrote my own tool to add location info to the description of the JPG file, such as "The beautiful Xyz cove close to the A123 road between TownA and VillageB." - Using GPS coordinates would have been much more accurate and machine readable.
 

isladogs

CID VIP
Local time
Today, 03:59
Joined
Jan 14, 2017
Messages
16,219
However, I'm still unclear about the benefit or wisdom of editing EXIF data in photos...

Yes, I accept that point regarding the possible benefit.
My main concern would be about the wisdom of doing so.
Of course, adding the ability to edit the existing EXIF data means it could also be used to change the date/time/location etc.
In other words, the data could no longer be relied upon to be accurate

Nevertheless, I'll add it to my long list of to do tasks for a possible future update ...
 

sonic8

AWF VIP
Local time
Today, 04:59
Joined
Oct 27, 2015
Messages
593
My main concern would be about the wisdom of doing so.
Of course, adding the ability to edit the existing EXIF data means it could also be used to change the date/time/location etc.
In other words, the data could no longer be relied upon to be accurate
You assume the data could be relied on before. - A bold assumption.
I've taken photos with a camera with the date/time in the camera being incorrectly set.
I've taken photos with my phone with the the GPS info being many miles off, due to bad weather.
 

SimonL

New member
Local time
Today, 03:59
Joined
Jan 12, 2022
Messages
8
Simon
Did you look at my app? Its free and fully working.
Yes, I did. It looks good, but I'd still be frustrated that I wasn't able to solve the WIA problem, so even if I downloaded it I'd still have to find the answer to that...
 

Users who are viewing this thread

Top Bottom