感谢大家,尤其是@stackprotector。我学到了很多东西,并设法弄清楚如何提取我的确切值,包括重要的 N、S、E、W。
为了帮助他人,以下是我的发现:
# Based on answer from @stackprotector (above)
# Create an ImageFile object and load an image file
$image = New-Object -ComObject Wia.ImageFile
$image.LoadFile("D:\temp\toNAS\temp\PXL_20210830_004210948.jpg")
$image.Properties.Item('GpsLatitudeRef').Value
# S
$image.Properties.Item('GpsLatitude').Value
<#
Value Numerator Denominator
----- --------- -----------
37 37 1
51 51 1
43.92 4392 100
>#
# Can rinse and repeat for GpsLongitude
现在提取我想要的。这是一个子集;很容易在 GpsLongitude 中复制另一个 :-)
$image.Properties.Item('GpsLatitude').Value[1].Value
# 37
$image.Properties.Item('GpsLatitude').Value[2].Value
# 51
$image.Properties.Item('GpsLatitude').Value[3].Value
# 43.92
$image.Properties.Item('GpsLatitudeRef').Value
# S
$image.Properties.Item('DateTime').Value
# 2021:08:30 10:42:10
# This is local not UTC
# So final latitude is 37 deg 51 min 43.92 sec S
# Taken on 2021:08:30 10:42:10 local time
相机内的值显示为 -37.8622,拍摄于 2021 年 8 月 30 日当地时间 10:42:10,对此非常满意,包括南方的“-”
我会试试 Exiftool @daniel 看看它是否更容易。我以前用过,很好用。
更新 (2022-02-13)。
我最终选择了 Exiftool。随着我对 JSON 越来越有信心,该工具集对我来说变得更加明显。这是代码的关键sn-ps(如下)。一件小事:这个 exiftool 选项集在运行时没有给出“反馈”。只在最后给出了总结:
# $photoYear is the root folder with the images
$data = (exiftool -if '$gpsdatetime' -s -s -s -json -ext jpg -filename -FileTypeExtension -Directory -CreateDate -GPSDateTime -GPSLatitude -GPSLongitude -n -r $photoYear ) | ConvertFrom-Json
# ...
[int]$n = 0
foreach ($photo in $data){
Write-host $n, " " $photo.CreateDate, $photo.GPSLatitude, $photo.GPSLongitude
$n++
}