2016-04-03 107 views
1

使用GPSLatitude和GPSLatitude屬性Assign方法設置GPS座標是相當簡單的,但讀取座標讓我難住。我試圖訪問TGPSLongitude類,但沒有任何屬性或方法會使我成爲真正的/浮點數甚至是座標的DMS。如何在Delphi中使用CCR.EXIF從JPG EXIF中讀取GPS座標?

樣品圖片:http://www.cde.co.za/share/IMG_5889.JPG

我這不是編譯當前代碼:

imgJpg: TJpegImageEx; 
GPS_D: Real; 

try 
    imgJpg.LoadFromFile(FolderName+'\'+SR.Name); 
    GPS_D:= imgJpg.ExifData.GPSLatitude.Degrees; 
except 
    GPS_D:= 0; 
end; 

編譯器停在那裏我嘗試分配與錯誤GPS_D「[DCC錯誤] Main.pas(205) :E2010不兼容的類型:'Real'和'TTiffLongWordFraction'「這顯然是因爲我無法將Degrees屬性分配給實際。問題是如何從TGPSLongitude中提取度數或小數值?

+0

*我當前沒有編譯的代碼*哪個編譯器錯誤,哪一行?另外,什麼是'TdmSH'及其方法'DMStoDec'? –

+0

@TomBrunberg DMStoDec需要3個實際值並將其轉換爲GPS Decimal。但是我簡化了源代碼示例。編譯器停止在我嘗試賦值GPS_D的錯誤「[DCC Error] Main.pas(205):E2010不兼容的類型:'Real'和'TTiffLongWordFraction'」這顯然是因爲我無法將Degrees屬性指定給一個真實的。問題是如何從TGPSLongitude中提取度數或小數值?謝謝你的時間。 –

回答

0

在展望深度來源,似乎可以使用「Quotient」屬性。代替存儲十進制浮點數,開發人員選擇存儲組件Numerator,Denominator和Quotient。

我不認爲這是如何使用,但它的工作!感謝大家的時間。

因此,讀取的GPS使用CCR.EXIF從一個JPG文件座標,我做了以下內容:

var 
    imgJpg: TJpegImageEx; 
    d,m,s,lat: real; 

imgJpg.LoadFromFile(FolderName+'\'+SR.Name); {Load the particular JPG File } 
d:= imgJpg.ExifData.GPSLatitude.Degrees.Quotient; {Degrees} 
m:= imgJpg.ExifData.GPSLatitude.Minutes.Quotient; {Minutes} 
s:= imgJpg.ExifData.GPSLatitude.Seconds.Quotient; {Seconds} 

{Now determine the sign} 
if imgJpg.ExifData.GPSLatitude.Direction=ltNorth then 
    ref:= 1 
else 
    ref:= -1; 

{Convert to decimal} 
lat:= ref*(d+(m/60)+(s/60/60)); 

LAT現在包含緯度。當然可以長期使用。

2

從現有的CCRExif內的文檔1.5.1 -

GPS

Exif標準允許設置GPS(即,定位)數據, 其被存儲在它自己的部分/子IFD。使用TExifData,您可以 讀取和寫入,GPS標記的標準集合 作爲該類別的屬性。然而,需要注意的重要一點是,GPS座標可以用兩種不同的方式表示,即 單個十進制值或以度,分和秒錶示。 Exif使用第二種形式,所以如果您希望將GPS座標分配給 圖像,並且所有數值都是表示爲 小數的必需值,則需要先轉換爲其他形式。 (對於「一個 關」的轉換,可以使用以下網址: http://www.fcc.gov/mb/audio/bickel/DDDMMSS-decimal.html)一旦你 有需要的形式座標然而,它們分配到 圖像會爲這樣的:

with TExifData.Create do 
try 
    LoadFromGraphic(ImageFile); 
    GPSLatitude.Assign(51, 25, 32.1, ltNorth); 
    GPSLongitude.Assign(0, 12, 29.2, lnEast); 
    SaveToGraphic(ImageFile); 
finally 
Free; 
end; 

尋找源代碼瘦到裏面:

TGPSLatitude = class(TGPSCoordinate) 

TGPSCoordinate類的聲明在公開區

property Degrees: TExifFraction index 0 read GetValue; 
property Minutes: TExifFraction index 1 read GetValue; 
property Seconds: TExifFraction index 2 read GetValue; 
property Direction: AnsiChar read GetDirectionChar write SetDirectionChar; 

此外,zip文件中還有幾個演示應用程序。

LE:看了評論後,我再次演示了一下,並在ExifList演示中,你有ExifListFrame.pas下面的代碼:

procedure AddValue(const Name: string; Coord: TGPSCoordinate); overload; 
    var 
    DirectionStr: string; 
    {$IFDEF BUGGYCOMPILER} 
    Degrees, Minutes, Seconds: TExifFraction; //work around D2006 compiler bug with intermediate vars 
    {$ENDIF} 
    begin 
    if Coord.MissingOrInvalid then Exit; 
    case Coord.Direction of 
     'N': DirectionStr := 'north'; 
     'S': DirectionStr := 'south'; 
     'W': DirectionStr := 'west'; 
     'E': DirectionStr := 'east'; 
    else DirectionStr := ''; 
    end; 
    {$IFDEF BUGGYCOMPILER} 
    Degrees := Coord.Degrees; 
    Minutes := Coord.Minutes; 
    Seconds := Coord.Seconds; 
    AddValue(Name, '%g°, %g minutes and %g seconds %s', [Degrees.Quotient, 
     Minutes.Quotient, Seconds.Quotient, DirectionStr]); 
    {$ELSE} 
    AddValue(Name, '%g°, %g minutes and %g seconds %s', [Coord.Degrees.Quotient, 
     Coord.Minutes.Quotient, Coord.Seconds.Quotient, DirectionStr]); 
    {$ENDIF} 
    end; 
+0

我的手頭沒有安裝Delphi,所以我無法爲您提供該課程用法的完整示例。 – RBA

+0

謝謝,我已經徹底閱讀了文檔,並且您的摘錄顯示瞭如何分配TGPSCoordinate實例,即寫入它。我有一個現有的地理標記JPG,我需要關閉它的座標。 Degrees,minutes,seconds屬性是TExifFraction類型,這是一個打包的記錄,其組件記錄不清楚如何獲取實際值。看到我在上面添加的源代碼中的嘗試。 –