You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用PowerShell直接提取JPG图片属性中的GPS经纬度信息

PowerShell 提取JPG图片GPS经纬度方法

实现原理

Windows 资源管理器展示的扩展属性(包括GPS分组下的纬度、经度)不属于FileInfo对象的原生属性,无法通过$img.属性名的方式直接读取,需要调用Shell.ApplicationCOM对象读取指定索引的扩展属性值。

完整可用脚本

# 初始化Shell COM对象
$shell = New-Object -ComObject Shell.Application
# 替换为你需要扫描的图片文件夹路径
$imgFolderPath = "C:\你的图片存储路径"
$folder = $shell.Namespace($imgFolderPath)

# Windows 10系统默认GPS纬度、经度对应的扩展属性索引,其他系统版本若读取失败可运行下方注释代码查询对应索引
$gpsLatitudeIndex = 207
$gpsLongitudeIndex = 208

# 遍历目标路径下所有jpg文件,支持递归扫描子文件夹
Get-ChildItem -Path $imgFolderPath -Filter *.jpg -Recurse | ForEach-Object {
    $file = $folder.ParseName($_.Name)
    $latitude = $folder.GetDetailsOf($file, $gpsLatitudeIndex)
    $longitude = $folder.GetDetailsOf($file, $gpsLongitudeIndex)
    
    # 输出结构化结果,可按需修改为导出CSV、写入文件等逻辑
    [PSCustomObject]@{
        文件全路径 = $_.FullName
        GPS纬度 = $latitude
        GPS经度 = $longitude
    }
}

# <可选> 索引不匹配时运行以下代码,查询当前系统的GPS经纬度属性对应索引
<#
for ($i=0; $i -le 300; $i++) {
    $propName = $folder.GetDetailsOf($folder.Items(), $i)
    if ($propName -like "*纬度*" -or $propName -like "*经度*") {
        Write-Host "索引$i : $propName"
    }
}
#>

注意事项

  • 仅能读取已写入GPS Exif信息的图片,无GPS信息的文件对应字段返回空值
  • 默认读取到的经纬度为度分秒格式,如需转换为十进制度可自行添加数值转换逻辑
  • 该方法直接调用系统原生接口,相比第三方工具执行效率更高,适合批量处理大量图片文件

内容的提问来源于stack exchange,提问作者dwids

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 16:57:05