【问题标题】:How do I convert these image EXIF GPS coordinates into Decimal Lat/Lng?如何将这些图像 EXIF GPS 坐标转换为十进制纬度/经度?
【发布时间】:2013-10-03 13:38:09
【问题描述】:

我正在编写一些图像处理代码,并且我正在提取 GPS 坐标,但是它们是某种整数数组,我无法弄清楚如何转换为度/分/秒或十进制形式.

Lat: (38,0,0,0,1,0,0,0,54,0,0,0,1,0,0,0,168,73,5,0,16,39,0,0)
Lng: (77,0,0,0,1,0,0,0,2,0,0,0,1,0,0,0,60,122,0,0,16,39,0,0)

根据 windows 的 D/M/S 版本是:

VB.NET 代码最有帮助,但我可以将它从任何语言转换。

【问题讨论】:

  • 没见过这么白痴的格式,24字节,4字节就够了。

标签: .net vb.net gps exif geotagging


【解决方案1】:

这是使用 .NET 调用在 C# 中工作的代码(在 VB 中应该很简单)

Double deg = (Double)BitConverter.ToInt32(data,0)/ BitConverter.ToInt32(data,4);
Double min = (Double)BitConverter.ToInt32(data,8)/ BitConverter.ToInt32(data,12);
Double sec = (Double)BitConverter.ToInt32(data,16)/ BitConverter.ToInt32(data,20);

格式记录在这里http://en.wikipedia.org/wiki/Geotagging

【讨论】:

    【解决方案2】:

    数组的布局如下:

    bytes(0 -> 3) / bytes(4 -> 7) = degree
    (bytes(8 -> 11) / bytes(12 -> 15)) / 60= minute
    (bytes(16 -> 19) / bytes(20 -> 23)) / 3600 = second
    

    *注意 - 每个byte(x -> y) 数量是范围的总和。

    下面会将给定的 lat 数组解码为十进制形式。

        Dim coord(5) As Decimal
        Dim j As Integer = 0
        Dim coordinate As Decimal
    
        For i As Integer = 0 To lat.Length - 1
            coord(j) = coord(j) + lat(i)
    
            'If i is a multiple of 4, goto the next index
            If ((i + 1) Mod 4 = 0) And i <> 0 Then
                j += 1
            End If
    
        Next
    
        coordinate = (coord(0) / coord(1)) + ((coord(2) / coord(3))) / 60 + ((coord(4) / coord(5)) / 3600)
    

    只需将引用的数组更改为解码 lng。

    【讨论】:

    • 这段代码是错误的。字节没有“求和”。它们是 little-endian 4 字节整数。如果整数小于 256(度和分钟为真),它会意外工作,但对于秒字段它会失败。
    猜你喜欢
    • 2013-01-11
    • 1970-01-01
    • 2013-04-14
    • 1970-01-01
    • 1970-01-01
    • 2012-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多