Jump to content

Obtain Latitude and Longitude Under Mouse in Google Earth


Recommended Posts

I'd like to obtain the latitude and longitude under the mouse cursor at any given time while operating in Google Earth.  I'm struggling to find a solution.  Does anyone have ideas?  

 

Currently, the information is displayed in a Qwidget on the bottom right hand corner of the screen.  I'd like to be able to retrieve that info with AutoIt.

I've tried using the Window Info tool to find a control that has this info.  Also, the RanorexSpy program that has been suggested for manipulating Qwidgets.  No success with either.

The COM interface for Google Earth is depreciated and the documentation is non-existent on the web anymore.  I'd accept this as a solution, but from what I have found I don't see a function that obtains the current mouse lat/lon.

Any ideas?

 

 

Link to comment
Share on other sites

While the COM may be deprecated, it may still be available, it was earlier eventhough they said it would be removed.

Look through this old code I wrote, especially the "Func Distance()" function.

You cant run the code, alot of files missing, and I cant test it for you as my main rig is down (bad c: drive) so currently on a netbook.

#RequireAdmin
#include <GuiTab.au3>
#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <WinAPI.au3>
#include <File.au3>
#include <GuiStatusBar.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include <UpdownConstants.au3>
#include <ScreenCapture.au3>
#include <Process.au3>
#include <GDIPlus.au3>
#include <Array.au3>
#include <Misc.au3>
#include <Math.au3>
#Include "LZMA.au3"

$sDll = @SystemDir & "\ImageMagickObject.dll"
DllCall($sDll, "long", "DllRegisterServer")

If Not FileExists(@TempDir & "/G2C/") Then DirCreate(@TempDir & "/G2C/")
If Not FileExists(@ScriptDir & "/Heightmaps/") Then DirCreate(@ScriptDir & "/Heightmaps/")

$screen_x = 0
$screen_y = 0
$statbar = 0
Local $statparts[3] = [375, 450, -1]
$oPointOnTerrain = 1
$check = 3
$checkmin = 3
$checkmax = 10
$north = -16.43958581369237
$south = -16.59292569451947
$east = -151.6629524102095
$west = -151.8339435299045
$vbs = 1.25 ; ViewBoundScale
$lon = 0 ; Longitude
$lat = 0 ; Latitude
$alt = 0 ; Altitude of ground
$height = 0 ; Altitude of overlay
$max = 10 ; Altitude of highest elevation
$min = 0 ; Altitude of lowest elevation
$d = 1
$sizeset = 0
$heightset = 0
$oMyError = ObjEvent("AutoIt.Error","MyErrFunc")
$sizeok = 1
$headingok = 1
$tiltok = 1
$texturesize = "100%"
$waterlevel = 16
$answer = 6

;g2c file vars
Global $g2clat, $g2clon, $g2crange, $g2csize 
Opt("PixelCoordMode", 0)
Opt("MouseCoordMode", 2)

;gui
$gui = GUICreate("G2C", 967, 808, 200, 100)

;File menu
$filemenu = GUICtrlCreateMenu("File")
;$new = GUICtrlCreateMenuItem("New", $filemenu)
$openg2c = GUICtrlCreateMenuItem("Open .g2c project...", $filemenu)
$opencb = GUICtrlCreateMenuItem("Paste clipboard data", $filemenu)
;$save = GUICtrlCreateMenuItem("Save", $filemenu)
;$saveas = GUICtrlCreateMenuItem("Save As...", $filemenu)
;$preferences = GUICtrlCreateMenuItem("Preferences", $filemenu)
$seperator = GUICtrlCreateMenuItem("", $filemenu)
$exit = GUICtrlCreateMenuItem("Exit", $filemenu)

;Options menu
$optionsmenu = GUICtrlCreateMenu("Options")
$bench = GUICtrlCreateMenuItem("Benchmark", $optionsmenu)
$settings = GUICtrlCreateMenuItem("Settings", $optionsmenu)

;Help menu
$wtf = GUICtrlCreateMenu("Help")
$help = GUICtrlCreateMenuItem("Help", $wtf)
$about = GUICtrlCreateMenuItem("About", $wtf)

$statbar = _GUICtrlStatusBar_Create ($gui)
_GUICtrlStatusBar_SetParts ($statbar, $statparts)
_GUICtrlStatusBar_SetText ($statbar, "Ready")
;Tabs
$tab_1 = GUICtrlCreateTab(767, 0, 205, 605)
    $tab_10 = GUICtrlCreateTabitem(" G2C")
    GUICtrlCreateGroup("Google Earth", 777, 30, 185, 160)
    GUICtrlCreateGroup("Size", 782, 45, 75, 45)
    $gesize = GUICtrlCreateLabel("", 787, 60, 65, 25, $SS_CENTER)
    GUICtrlSetBkColor($gesize, 0xFF0000)
    GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
    GUICtrlCreateGroup("Heading", 782, 90, 75, 45)
    $heading = GUICtrlCreateLabel("180°", 787, 105, 65, 25, $SS_CENTER)
    GUICtrlSetFont(-1, 16)
    GUICtrlSetBkColor($heading, 0x00FF00)
    GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
    GUICtrlCreateGroup("Tilt", 782, 135, 75, 45)
    $settilt = GUICtrlCreateLabel("0°", 787, 150, 65, 25, $SS_CENTER)
    GUICtrlSetFont(-1, 16)
    GUICtrlSetBkColor($settilt, 0x00FF00)
    GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
    GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
    GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
    GUICtrlCreateGroup("Heights", 862, 45, 95, 140)
    $auto = GUICtrlCreateRadio("Auto", 867, 60, 40, 20)
    GUICtrlSetTip($auto, "Automatically finds the minimum" & @LF & "and maximum heights." & @LF & "This may fail!")
    GUICtrlSetCursor($auto, 0)
    GUICtrlSetState($auto, $GUI_CHECKED)
    $manual = GUICtrlCreateRadio("Manual", 867, 75, 55, 20)
    GUICtrlSetTip($manual, "Set the heights yourself manually.")
    GUICtrlSetCursor($manual, 0)
    $maxgroup = GUICtrlCreateGroup("Max", 867, 90, 85, 45)
    GUICtrlSetState($maxgroup, $GUI_DISABLE)
    $inputmax = GUICtrlCreateInput("10", 10, 10, 75, 26, $ES_RIGHT)
    GUICtrlSetFont(-1, 12)
    $maxresult = GUICtrlCreateUpdown($inputmax, $UDS_NOTHOUSANDS)
    GUICtrlSetPos($inputmax, 872, 105, 75, 26)
    GUICtrlSetState($inputmax, $GUI_DISABLE)
    GUICtrlCreateGroup("", -99, -99, 1, 1)  ;close group
    $mingroup = GUICtrlCreateGroup("Min", 867, 135, 85, 45)
    GUICtrlSetState($mingroup, $GUI_DISABLE)
    $inputmin = GUICtrlCreateInput("3", 10, 10, 75, 26, $ES_RIGHT)
    GUICtrlSetFont(-1, 12)
    $minresult = GUICtrlCreateUpdown($inputmin, $UDS_NOTHOUSANDS)
    GUICtrlSetPos($inputmin, 872, 150, 75, 26)
    GUICtrlSetState($inputmin, $GUI_DISABLE)
    GUICtrlCreateGroup("", -99, -99, 1, 1)  ;close group
    GUICtrlCreateGroup("", -99, -99, 1, 1)  ;close group
    GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
    GUICtrlCreateGroup("CryEngine²", 777, 200, 185, 190)
    GUICtrlCreateGroup("Terrain", 782, 215, 175, 50)
    GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
    GUICtrlCreateGroup("Level Name", 782, 345, 175, 40)
    $levelname = GUICtrlCreateInput("dont_use_spaces", 787, 360, 165, 20)
    GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
    GUICtrlCreateLabel("Terrain size:", 810, 230)
    GUICtrlCreateGroup("Settings", 782, 265, 175, 80)
    GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
    GUICtrlCreateLabel("Max height:", 812, 325)
    GUICtrlCreateLabel("1024", 870, 325)
    GUICtrlCreateLabel("Meters/unit:", 810, 295)
    $metersunit = GUICtrlCreateLabel("1", 870, 295)
    GUICtrlCreateLabel("Water level:", 810, 310)
    $waterlevellabel = GUICtrlCreateLabel("16", 870, 310)
    GUICtrlCreateLabel("Texture size: ", 807, 245)
    GUICtrlCreateLabel("Heightmap:", 813, 280, 60, 20)
    GUICtrlCreateLabel("512x512", 870, 280, 60, 20)
    $sizelabel = GUICtrlCreateLabel($d & "x" & $d, 870, 230, 60, 20)
    $texturesizelabel = GUICtrlCreateLabel($d/2 & "x" & $d/2, 870, 245, 60, 20)
    GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
    $findh = GUICtrlCreateButton("Find heights", 812, 400, 120, 30)
    GUICtrlSetCursor($findh, 0)
    $renderhm = GUICtrlCreateButton("Render", 812, 540, 120, 30)
    GUICtrlSetCursor($renderhm, 0)
        
GUICtrlCreateTabitem ("")   ; end tabitem definition
$ge = ObjCreate("GoogleEarth.ApplicationGE")
$img = ObjCreate("ImageMagickObject.MagickImage.1")
If Not IsObj($img) Then
    MsgBox(0, "G2C", "IMGOBJ did not create.")
    Exit (-1)
EndIf

; Wait for GE to initialize
If Not IsObj($ge) Then
    MsgBox(0, "G2C", "GEOBJ did not create.")
    Exit (-1)
EndIf
$cam = ObjCreate("GoogleEarth.CameraInfoGE")

If Not IsObj($cam) Then
    MsgBox(0, "G2C", "CAMOBJ did not create.")
    Exit (-1)
EndIf

WinWaitActive("Google Earth") ; Wait for GE to initialize
WinActivate("Google Earth")
;WinSetState("Google Earth", "", @SW_HIDE) ; Let's hide GE
Sleep(99)
If $ge.IsOnline() <> 1 Then
    Exit (-1)
ElseIf $ge.IsInitialized() <> 1 Then
    Exit (-1)
EndIf



Sleep(250)
WinMove("Google Earth", "", 200, 100, 776, 838)
; Let's hide GE
;WinSetState("Google Earth", "", @SW_HIDE)

; Get the handle of the GE render window
$render = $ge.GetRenderHwnd()
$currentview = $ge.GetCamera(1)
; Set our GUI as the Parent for the GE render window
_WinAPI_SetParent($render, $gui)

GUISetState()

;Sleep(500)
redlay()

GuiCtrlSetState($renderhm, $GUI_DISABLE)


While 1
    If _IsPressed("02")Then
        While _IsPressed("02")
            _GUICtrlStatusBar_SetText ($statbar, "Zooming")
            Sleep(10)
        WEnd
    _GUICtrlStatusBar_SetText ($statbar, "Ready")
    distance()
EndIf

If _IsPressed("04")Then
        While _IsPressed("04")
            $currentview = $ge.GetCamera(1)
            _GUICtrlStatusBar_SetText ($statbar, "Tilting")
            Sleep(10)
        WEnd
    _GUICtrlStatusBar_SetText ($statbar, "Ready")
    If $currentview.Tilt() <> 0 Then
        GUICtrlSetState($renderhm, $GUI_DISABLE)
        GUICtrlDelete($settilt)
        $settilt = GUICtrlCreateLabel(Round($currentview.Tilt()) & "°", 787, 150, 65, 25, $SS_CENTER)
        GUICtrlSetFont(-1, 16)
        GUICtrlSetBkColor($settilt, 0xFF0000)
        $tiltok = 0
    Else
        If $headingok = 1 And $sizeok = 1 Then GUICtrlSetState($renderhm, $GUI_ENABLE)
        GUICtrlDelete($settilt)
        $settilt = GUICtrlCreateLabel(Round($currentview.Tilt()) & "°", 787, 150, 65, 25, $SS_CENTER)
        GUICtrlSetFont(-1, 16)
    GUICtrlSetBkColor($settilt, 0x00FF00)
    $tiltok = 1
        EndIf
EndIf

If _IsPressed("01")Then
        While _IsPressed("01")
            $currentview = $ge.GetCamera(1)
            _GUICtrlStatusBar_SetText ($statbar, "Panning")
            Sleep(10)
        WEnd
    _GUICtrlStatusBar_SetText ($statbar, "Ready")
    If Round($currentview.Azimuth()) <> 0 Then
        GUICtrlDelete($heading)
        $heading = GUICtrlCreateLabel(Round($currentview.Azimuth()) & "°", 787, 105, 65, 25, $SS_CENTER)
        GUICtrlSetFont(-1, 16)
        GUICtrlSetBkColor($heading, 0xFF0000)
        GUICtrlSetState($renderhm, $GUI_DISABLE)
        $headingok = 0
    distance()
    Else
        GUICtrlDelete($heading)
        $heading = GUICtrlCreateLabel(Round($currentview.Azimuth()) & "°", 787, 105, 65, 25, $SS_CENTER)
        GUICtrlSetFont(-1, 16)
    GUICtrlSetBkColor($heading, 0x00FF00)
    If $tiltok = 1 And $sizeok = 1 Then GUICtrlSetState($renderhm, $GUI_ENABLE)
    $headingok = 1
    distance()
        EndIf
    EndIf
    
    If GUICtrlRead($inputmin) <> $checkmin Then
        $height = GUICtrlRead($inputmin)
        setlatlonbox()
        $checkmin = GUICtrlRead($inputmin)
        $min = $checkmin
    EndIf
    
    If GUICtrlRead($inputmax) <> $checkmax Then
        $height = GUICtrlRead($inputmax)
        setlatlonbox()
        $checkmax = GUICtrlRead($inputmax)
        $max = $checkmax
    EndIf
    

    
    Switch GUIGetMsg()
    Case $openg2c
        $g2cdata = FileOpenDialog("Open .g2c project", "\", "g2c project (*.g2c)")
Case $settilt
    tilt()
Case $auto
    GUICtrlSetState($inputmax, $GUI_DISABLE)
    GUICtrlSetState($inputmin, $GUI_DISABLE)
    GUICtrlSetState($maxgroup, $GUI_DISABLE)
    GUICtrlSetState($mingroup, $GUI_DISABLE)
Case $manual
    GUICtrlSetState($inputmax, $GUI_ENABLE)
    GUICtrlSetState($inputmin, $GUI_ENABLE)
    GUICtrlSetState($maxgroup, $GUI_ENABLE)
    GUICtrlSetState($mingroup, $GUI_ENABLE)
Case $renderhm
    If FileExists(@ScriptDir & "/Heightmaps/" & GUICtrlRead($levelname) & "/") Then
    $answer = MsgBox(4, "G2C: Confirm Level name", GUICtrlRead($levelname) & " already exists, Overwrite ?")
Else 
    DirCreate(@ScriptDir & "/Heightmaps/" & GUICtrlRead($levelname) & "/")
    EndIf
    If $answer = 6 Then renderdraft3()
    
Case $findh
    findheights()
    ;renderdraft2()
Case $GUI_EVENT_CLOSE
    ControlSend("Google Earth", "", "", "{DEL}")
    Sleep(100)
    ControlSend("Google Earth", "", "", "{ENTER}")
    WinClose("Google Earth")
 Exit
    EndSwitch

WEnd

Func redlay()
$redlay = "<?xml version=""1.0"" encoding=""UTF-8""?>" & _
"<kml xmlns=""http://www.opengis.net/kml/2.2"">" & _
"<ScreenOverlay>" & _ 
"<name>G2C Screenoverlay</name>" & _
"<Icon>" & _
"<href>" & @ScriptDir & "/redlaybig.png</href>" & _
"</Icon>" & _
"<overlayXY x=""0"" y=""1"" xunits=""fraction"" yunits=""fraction""/>" & _
"<screenXY x=""0"" y=""1"" xunits=""fraction"" yunits=""fraction""/>" & _
"<rotationXY x=""0"" y=""0"" xunits=""fraction"" yunits=""fraction""/>" & _
"<size x=""0"" y=""0"" xunits=""fraction"" yunits=""fraction""/>" & _
"</ScreenOverlay>" & _
"</kml>"
$ge.loadKmlData($redlay)
EndFunc

Func renderdraft2()
    
    $compcolor = ($min-$min)+1
    _FileWriteToLine(@ScriptDir & "/kmltest2.kml", 6, "<href>" & @ScriptDir & "/overlay.png</href>", 1)
    $img.Convert("-size","512x512","xc:black","-depth","16","-compress","none",@TempDir & "/G2C/result.pgm")
    For $height = $min to $max step 1
        _FileWriteToLine(@ScriptDir & "/kmltest2.kml", 9, "<altitude>" & $height & "</altitude>", 1)
        $openkml = $ge.openkmlfile(@ScriptDir & "/kmltest2.kml", 1)
        While $ge.StreamingProgressPercentage() <> 100
        WEnd
        Sleep(100)
        _ScreenCapture_CaptureWnd(@TempDir & "/G2C/hg1.png", $gui, 132, 169, 643, 680)
        ControlSend("Google Earth", "", "", "{DEL}")
        ControlSend("Google Earth", "", "", "{ENTER}")

$convert = $img.Convert(@TempDir & "/G2C/hg1.png","-depth","16", @TempDir & "/G2C/hg1.pgm")
$convert = $img.Convert("(",@TempDir & "/G2C/hg1.pgm","-threshold","1","-fill","#" & Hex(($compcolor+1)*64,4) & Hex(($compcolor+1)*64,4) & Hex(($compcolor+1)*64,4),"-opaque","white",")","-compose","lighten","-compress","none",@TempDir & "/G2C/result.pgm","-composite","-compress","none",@TempDir & "/G2C/result.pgm")
If PixelChecksum(132, 169, 643, 680) = 11796481 Then ExitLoop
                    ;_GUICtrlStatusBar_SetText ($statbar, PixelChecksum(132, 169, 643, 680))
    $compcolor = $compcolor+1               
Next

_FileWriteToLine(@ScriptDir & "/kmltest2.kml", 6, "<href>" & @ScriptDir & "/overlay1.png</href>", 1)
        $openkml = $ge.openkmlfile(@ScriptDir & "/kmltest2.kml", 1)
        ControlSend("Google Earth", "", "", "{DEL}")
        ControlSend("Google Earth", "", "", "{ENTER}")
        While $ge.StreamingProgressPercentage() <> 100
        WEnd
        _ScreenCapture_CaptureWnd(@TempDir & "/G2C/texture.bmp", $gui, 132, 169, 643, 680)

$checkmax = GUICtrlRead($inputmax)
$checkmin = GUICtrlRead($inputmin)
;$clutted = $img.Convert(@TempDir & "/G2C/result.pgm","clut2.pgm","-interpolate","BiLinear","-clut","-compress","none",@TempDir & "/G2C/final.pgm")

$blurred = $img.Convert(@TempDir & "/G2C/result.pgm","-compress","none","-blur","2x2", @ScriptDir & "/Heightmaps/" & GUICtrlRead($levelname) & "/" & GUICtrlRead($levelname) & ".pgm")
$img.Convert(@TempDir & "/G2C/texture.bmp","-resize",$texturesize, @ScriptDir & "/Heightmaps/" & GUICtrlRead($levelname) & "/" & GUICtrlRead($levelname) & ".bmp")
$img.Convert(@ScriptDir & "/Heightmaps/" & GUICtrlRead($levelname) & "/" & GUICtrlRead($levelname) & ".pgm","-resize","64x64","-depth","8", @ScriptDir & "/Heightmaps/" & GUICtrlRead($levelname) & "/" & GUICtrlRead($levelname) & "_8b.pgm")

$smallmapraw = FileRead(@ScriptDir & "/Heightmaps/" & GUICtrlRead($levelname) & "/" & GUICtrlRead($levelname) & "_8b.pgm")
$smallmapraw = StringTrimLeft($smallmapraw, 13)
$mapfile = FileOpen(@ScriptDir & "/Heightmaps/" & GUICtrlRead($levelname) & "/" & GUICtrlRead($levelname) & "_8b.pgm", 18)
FileWrite($mapfile, $smallmapraw)
FileClose($mapfile)

Dim $g2cpgm = Binary(FileRead(@ScriptDir & "/Heightmaps/" & GUICtrlRead($levelname) & "/" & GUICtrlRead($levelname) & ".pgm"))
Dim $g2cjpg = Binary(FileRead(@ScriptDir & "/Heightmaps/" & GUICtrlRead($levelname) & "/" & GUICtrlRead($levelname) & ".jpg"))

Dim $g2cpgmpacked = _LZMA_Compress($g2cpgm, 9)
Dim $g2cjpgpacked = _LZMA_Compress($g2cjpg, 9)

Dim $g2cfile = Binary("G2C1") & $g2cpgm


EndFunc

Func renderdraft3()
    
    $compcolor = ($min-$min)+1
    _FileWriteToLine(@ScriptDir & "/kmltest2.kml", 6, "<href>" & @ScriptDir & "/overlay.png</href>", 1)
    ;$img.Convert("-size","512x512","xc:black","-depth","16","-compress","none",@TempDir & "/G2C/result.pgm")
    $img.Convert("-size","512x512","xc:black","-colorspace","Gray","-depth","16","-compress","none",@TempDir & "/G2C/result.pgm")
    For $height = $min to $max step 1
        _FileWriteToLine(@ScriptDir & "/kmltest2.kml", 9, "<altitude>" & $height & "</altitude>", 1)
        $openkml = $ge.openkmlfile(@ScriptDir & "/kmltest2.kml", 1)
        While $ge.StreamingProgressPercentage() <> 100
        WEnd
        ;Sleep(100)
        _ScreenCapture_CaptureWnd(@TempDir & "/G2C/hg1.png", $gui, 132, 169, 643, 680)
        ControlSend("Google Earth", "", "", "{DEL}")
        ControlSend("Google Earth", "", "", "{ENTER}")

$convert = $img.Convert(@TempDir & "/G2C/hg1.png","-depth","16", @TempDir & "/G2C/hg1.pgm")
$convert = $img.Convert("(",@TempDir & "/G2C/hg1.pgm","-threshold","1","-fill","#" & Hex(($compcolor+1)*64,4) & Hex(($compcolor+1)*64,4) & Hex(($compcolor+1)*64,4),"-opaque","white",")","-compose","lighten","-compress","none",@TempDir & "/G2C/result.pgm","-composite","-compress","none",@TempDir & "/G2C/result.pgm")
If PixelChecksum(132, 169, 643, 680) = 11796481 Then ExitLoop
                    ;_GUICtrlStatusBar_SetText ($statbar, PixelChecksum(132, 169, 643, 680))
    $compcolor = $compcolor+1               
Next

_FileWriteToLine(@ScriptDir & "/kmltest2.kml", 6, "<href>" & @ScriptDir & "/overlay1.png</href>", 1)
        $openkml = $ge.openkmlfile(@ScriptDir & "/kmltest2.kml", 1)
        ControlSend("Google Earth", "", "", "{DEL}")
        ControlSend("Google Earth", "", "", "{ENTER}")
        While $ge.StreamingProgressPercentage() <> 100
        WEnd
        _ScreenCapture_CaptureWnd(@TempDir & "/G2C/texture.bmp", $gui, 132, 169, 643, 680)

$checkmax = GUICtrlRead($inputmax)
$checkmin = GUICtrlRead($inputmin)
;$clutted = $img.Convert(@TempDir & "/G2C/result.pgm","clut2.pgm","-interpolate","BiLinear","-clut","-compress","none",@TempDir & "/G2C/final.pgm")

$blurred = $img.Convert(@TempDir & "/G2C/result.pgm","-compress","none","-blur","2x2", @ScriptDir & "/Heightmaps/" & GUICtrlRead($levelname) & "/" & GUICtrlRead($levelname) & ".pgm")
$img.Convert(@TempDir & "/G2C/texture.bmp","-resize",$texturesize, @ScriptDir & "/Heightmaps/" & GUICtrlRead($levelname) & "/" & GUICtrlRead($levelname) & ".bmp")
$img.Convert(@ScriptDir & "/Heightmaps/" & GUICtrlRead($levelname) & "/" & GUICtrlRead($levelname) & ".pgm","-resize","64x64","-depth","8", @ScriptDir & "/Heightmaps/" & GUICtrlRead($levelname) & "/" & GUICtrlRead($levelname) & "_8b.pgm")

$smallmapraw = FileRead(@ScriptDir & "/Heightmaps/" & GUICtrlRead($levelname) & "/" & GUICtrlRead($levelname) & "_8b.pgm")
$smallmapraw = StringTrimLeft($smallmapraw, 13)
$mapfile = FileOpen(@ScriptDir & "/Heightmaps/" & GUICtrlRead($levelname) & "/" & GUICtrlRead($levelname) & "_8b.pgm", 18)
FileWrite($mapfile, $smallmapraw)
FileClose($mapfile)

EndFunc

Func distance()
    $pi = 4 * ATan(1)
    $degToRad = $pi/180
    $coords = $ge.GetPointOnTerrainFromScreenCoords(0.66,0)
    $lat1 = $coords.Latitude()
    $lat1check = Round($lat1, 6)
    $lon1 = $coords.Longitude()
    $lon1check = Round($lon1, 6)
    $coords = $ge.GetPointOnTerrainFromScreenCoords(-0.66,0)
    $lat2 = $coords.Latitude()
    $lat2check = Round($lat2, 6)
    $lon2 = $coords.Longitude()
    $lon2check = Round($lon2, 6)
    $R = 6378135 ; // earth's mean radius; moon=1738000 mars=3396190
    $dLat = ($lat2 - $lat1) * $degToRad
    $dLon = _Radian($lon2 - $lon1)
    $lat1 = _Radian($lat1)
    $lat2 = _Radian($lat2)
    $a = Sin($dLat / 2) * Sin($dLat / 2) + Cos($lat1) * Cos($lat2) * Sin($dLon / 2) * Sin($dLon / 2)
    $C = 2 * ATan(Sqrt($a) / Sqrt(1 - $a));
    $d = $R * $C
    $d = Round($d)
    _GUICtrlStatusBar_SetText ($statbar, "latlon: " & $lat1check & " " & $lon1check & " " & $lat2check & " " & $lon2check)
    
    Switch Int($d)
    Case 512
        If $headingok = 1 And $tiltok = 1 Then GUICtrlSetState($renderhm, $GUI_ENABLE)
        GUICtrlDelete($gesize)
        $gesize = GUICtrlCreateLabel($d & "²", 787, 60, 65, 25, $SS_CENTER)
        GUICtrlSetFont(-1, 16)
        GUICtrlSetBkColor(-1, 0x00FF00)
        GUICtrlSetData($sizelabel, "512x512")
        GUICtrlSetData($texturesizelabel, "256x256")
        GUICtrlSetData($metersunit, "1")
        $sizeok = 1
        $texturesize = "50%"
    
    Case 507 To 517
        If $headingok = 1 And $tiltok = 1 Then GUICtrlSetState($renderhm, $GUI_ENABLE)
        GUICtrlDelete($gesize)
        $gesize = GUICtrlCreateLabel($d & "²", 787, 60, 65, 25, $SS_CENTER)
        GUICtrlSetFont(-1, 16)
        GUICtrlSetBkColor(-1, 0xFFFF00)
        GUICtrlSetData($sizelabel, "512x512")
        GUICtrlSetData($texturesizelabel, "256x256")
        GUICtrlSetData($metersunit, "1")
        $sizeok = 1
        $texturesize = "50%"
    
    Case 1024
        If $headingok = 1 And $tiltok = 1 Then GUICtrlSetState($renderhm, $GUI_ENABLE)
        GUICtrlDelete($gesize)
        $gesize = GUICtrlCreateLabel($d & "²", 787, 60, 65, 25, $SS_CENTER)
        GUICtrlSetFont(-1, 16)
        GUICtrlSetBkColor(-1, 0x00FF00)
        GUICtrlSetData($sizelabel, "1024x1024")
        GUICtrlSetData($texturesizelabel, "512x512")
        GUICtrlSetData($metersunit, "2")
        $sizeok = 1
        $texturesize = "100%"
    
    Case 1014 To 1034
        If $headingok = 1 And $tiltok = 1 Then GUICtrlSetState($renderhm, $GUI_ENABLE)
        GUICtrlDelete($gesize)
        $gesize = GUICtrlCreateLabel($d & "²", 787, 60, 65, 25, $SS_CENTER)
        GUICtrlSetFont(-1, 16)
        GUICtrlSetBkColor(-1, 0xFFFF00)
        GUICtrlSetData($sizelabel, "1024x1024")
        GUICtrlSetData($texturesizelabel, "512x512")
        GUICtrlSetData($metersunit, "2")
        $sizeok = 1
        $texturesize = "100%"

    Case 2048
        If $headingok = 1 And $tiltok = 1 Then GUICtrlSetState($renderhm, $GUI_ENABLE)
        GUICtrlDelete($gesize)
        $gesize = GUICtrlCreateLabel($d & "²", 787, 60, 65, 25, $SS_CENTER)
        GUICtrlSetFont(-1, 16)
        GUICtrlSetBkColor(-1, 0x00FF00)
        GUICtrlSetData($sizelabel, "2048x2048")
        GUICtrlSetData($texturesizelabel, "1024x1024")
        GUICtrlSetData($metersunit, "4")
        $sizeok = 1
        $texturesize = "200%"
    
    Case 2028 To 2068
        If $headingok = 1 And $tiltok = 1 Then GUICtrlSetState($renderhm, $GUI_ENABLE)
        GUICtrlDelete($gesize)
        $gesize = GUICtrlCreateLabel($d & "²", 787, 60, 65, 25, $SS_CENTER)
        GUICtrlSetFont(-1, 16)
        GUICtrlSetBkColor(-1, 0xFFFF00)
        GUICtrlSetData($sizelabel, "2048x2048")
        GUICtrlSetData($texturesizelabel, "1024x1024")
        GUICtrlSetData($metersunit, "4")
        $sizeok = 1
        $texturesize = "200%"

    Case 4096
        If $headingok = 1 And $tiltok = 1 Then GUICtrlSetState($renderhm, $GUI_ENABLE)
        GUICtrlDelete($gesize)
        $gesize = GUICtrlCreateLabel($d & "²", 787, 60, 65, 25, $SS_CENTER)
        GUICtrlSetFont(-1, 16)
        GUICtrlSetBkColor(-1, 0x00FF00)
        GUICtrlSetData($sizelabel, "4096x4096")
        GUICtrlSetData($texturesizelabel, "2048x2048")
        GUICtrlSetData($metersunit, "8")
        $sizeok = 1
        $texturesize = "400%"

    Case 4054 To 4136
        If $headingok = 1 And $tiltok = 1 Then GUICtrlSetState($renderhm, $GUI_ENABLE)
        GUICtrlDelete($gesize)
        $gesize = GUICtrlCreateLabel($d & "²", 787, 60, 65, 25, $SS_CENTER)
        GUICtrlSetFont(-1, 16)
        GUICtrlSetBkColor(-1, 0xFFFF00)
        GUICtrlSetData($sizelabel, "4096x4096")
        GUICtrlSetData($texturesizelabel, "2048x2048")
        GUICtrlSetData($metersunit, "8")
        $sizeok = 1
        $texturesize = "400%"

    Case 8192
        If $headingok = 1 And $tiltok = 1 Then GUICtrlSetState($renderhm, $GUI_ENABLE)
        GUICtrlDelete($gesize)
        $gesize = GUICtrlCreateLabel($d & "²", 787, 60, 65, 25, $SS_CENTER)
        GUICtrlSetFont(-1, 16)
        GUICtrlSetBkColor(-1, 0x00FF00)
        GUICtrlSetData($sizelabel, "8192x8192")
        GUICtrlSetData($texturesizelabel, "4096x4096")
        GUICtrlSetData($metersunit, "16")
        $sizeok = 1
        $texturesize = "800%"

    Case 8112 To 8272
        If $headingok = 1 And $tiltok = 1 Then GUICtrlSetState($renderhm, $GUI_ENABLE)
        GUICtrlDelete($gesize)
        $gesize = GUICtrlCreateLabel($d & "²", 787, 60, 65, 25, $SS_CENTER)
        GUICtrlSetFont(-1, 16)
        GUICtrlSetBkColor(-1, 0xFFFF00)
        GUICtrlSetData($sizelabel, "8192x8192")
        GUICtrlSetData($texturesizelabel, "4096x4096")
        GUICtrlSetData($metersunit, "16")
        $sizeok = 1
        $texturesize = "800%"
    
    Case Else
        GUICtrlSetState($renderhm, $GUI_DISABLE)
        GUICtrlDelete($gesize)
        $gesize = GUICtrlCreateLabel($d & "²", 787, 60, 65, 25, $SS_CENTER)
        GUICtrlSetFont(-1, 16)
        GUICtrlSetBkColor(-1, 0xFF0000)
        GUICtrlSetData($sizelabel, "- - - x - - -")
        GUICtrlSetData($texturesizelabel, "- - - x - - -")
        GUICtrlSetData($metersunit, "--")
        $sizeok = 0
    EndSwitch
    
    EndFunc


Func setlatlonbox()
    _FileWriteToLine(@ScriptDir & "/kmltest2.kml", 6, "<href>" & @ScriptDir & "/overlay.png</href>", 1)
    $coords = $ge.GetPointOnTerrainFromScreenCoords(0,1)
    _FileWriteToLine(@ScriptDir & "/kmltest2.kml", 12, "<north>" & $coords.latitude & "</north>", 1)
    $coords = $ge.GetPointOnTerrainFromScreenCoords(0,-1)
    _FileWriteToLine(@ScriptDir & "/kmltest2.kml", 13, "<south>" & $coords.latitude & "</south>", 1)
    $coords = $ge.GetPointOnTerrainFromScreenCoords(-1,0)
    _FileWriteToLine(@ScriptDir & "/kmltest2.kml", 14, "<east>" & $coords.longitude & "</east>", 1)
    $coords = $ge.GetPointOnTerrainFromScreenCoords(1,0)
    _FileWriteToLine(@ScriptDir & "/kmltest2.kml", 15, "<west>" & $coords.longitude & "</west>", 1)
    _FileWriteToLine(@ScriptDir & "/kmltest2.kml", 9, "<altitude>" & $height & "</altitude>", 1)
    Sleep(100)
    
        ControlSend("Google Earth", "", "", "{DEL}")
        Sleep(100)
        ControlSend("Google Earth", "", "", "{ENTER}")
    $openkml = $ge.openkmlfile(@ScriptDir & "/kmltest2.kml", 1)
    ControlSend("Google Earth", "", "", "{DEL}")
    Sleep(100)
    ControlSend("Google Earth", "", "", "{ENTER}")
    $checkmax = GUICtrlRead($inputmax)
    $checkmin = GUICtrlRead($inputmin)
    
EndFunc

Func findheights()
    Dim $heights[7]
    $coords = $ge.GetPointOnTerrainFromScreenCoords(0,0)
    $heights[0] = $coords.altitude()
    $coords = $ge.GetPointOnTerrainFromScreenCoords(0.5,0.5)
    $heights[1] = $coords.altitude()
    $coords = $ge.GetPointOnTerrainFromScreenCoords(0.5,0)
    $heights[2] = $coords.altitude()
    $coords = $ge.GetPointOnTerrainFromScreenCoords(-0.5,0)
    $heights[3] = $coords.altitude()
    $coords = $ge.GetPointOnTerrainFromScreenCoords(0,0.5)
    $heights[4] = $coords.altitude()
    $coords = $ge.GetPointOnTerrainFromScreenCoords(0,-0.5)
    $heights[5] = $coords.altitude()
    $coords = $ge.GetPointOnTerrainFromScreenCoords(-0.5,-0.5)
    $heights[6] = $coords.altitude()
    _ArraySort($heights)
    $min = $heights[2]
    $max = $heights[5]
    _FileWriteToLine(@ScriptDir & "/kmltest2.kml", 6, "<href>" & @ScriptDir & "/overlay.png</href>", 1)
    $coords = $ge.GetPointOnTerrainFromScreenCoords(0,1)
    _FileWriteToLine(@ScriptDir & "/kmltest2.kml", 12, "<north>" & $coords.latitude & "</north>", 1)
    $coords = $ge.GetPointOnTerrainFromScreenCoords(0,-1)
    _FileWriteToLine(@ScriptDir & "/kmltest2.kml", 13, "<south>" & $coords.latitude & "</south>", 1)
    $coords = $ge.GetPointOnTerrainFromScreenCoords(-1,0)
    _FileWriteToLine(@ScriptDir & "/kmltest2.kml", 14, "<east>" & $coords.longitude & "</east>", 1)
    $coords = $ge.GetPointOnTerrainFromScreenCoords(1,0)
    _FileWriteToLine(@ScriptDir & "/kmltest2.kml", 15, "<west>" & $coords.longitude & "</west>", 1)
    _FileWriteToLine(@ScriptDir & "/kmltest2.kml", 9, "<altitude>" & $min & "</altitude>", 1)
        ControlSend("Google Earth", "", "", "{DEL}")
        ControlSend("Google Earth", "", "", "{ENTER}")
        Sleep(50)
        $nooverlay = PixelChecksum(132, 169, 643, 680)
        Sleep(50)
    $openkml = $ge.openkmlfile(@ScriptDir & "/kmltest2.kml", 1)
    While $ge.StreamingProgressPercentage() <> 100
    WEnd
    Sleep(50)

While PixelChecksum(132, 169, 643, 680) <> $nooverlay
    $min = $min - 1
        _FileWriteToLine(@ScriptDir & "/kmltest2.kml", 9, "<altitude>" & $min & "</altitude>", 1)
        ControlSend("Google Earth", "", "", "{DEL}")
        ControlSend("Google Earth", "", "", "{ENTER}")
    $openkml = $ge.openkmlfile(@ScriptDir & "/kmltest2.kml", 1)
While $ge.StreamingProgressPercentage() <> 100
WEnd
Sleep(50)
WEnd

If $min < 0 Then
    $waterlevel = Round(Abs($min)+3)
Else
    $waterlevel = 0
EndIf

GUICtrlSetData($waterlevellabel, $waterlevel)
While PixelChecksum(132, 169, 643, 680) <> 11796481
        $max = $max + 1
        _FileWriteToLine(@ScriptDir & "/kmltest2.kml", 9, "<altitude>" & $max & "</altitude>", 1)
        ControlSend("Google Earth", "", "", "{DEL}")
        ControlSend("Google Earth", "", "", "{ENTER}")
    $openkml = $ge.openkmlfile(@ScriptDir & "/kmltest2.kml", 1)
    While $ge.StreamingProgressPercentage() <> 100
    WEnd
    Sleep(50)
    WEnd

GUICtrlSetData($inputmin, Round($min))
GUICtrlSetData($inputmax, Round($max))

; end findheights
EndFunc

Func tilt()
    $currentview = $ge.GetCamera(1)
    $cam.FocusPointLatitude() = $currentview.FocusPointLatitude()
    $cam.FocusPointLongitude() = $currentview.FocusPointLongitude()
    $cam.Range = $currentview.Range() 
    $cam.Tilt() = 0 
    $cam.Azimuth() = $currentview.Azimuth()  
    $setcam = $ge.SetCamera($cam, 6)
EndFunc

Func MyErrFunc()
  $HexNumber=hex($oMyError.number,8)
  Msgbox(0,"COM Error Test","We intercepted a COM Error !"   & @CRLF  & @CRLF & _
             "err.description is: " & @TAB & $oMyError.description   & @CRLF & _
             "err.windescription:"   & @TAB & $oMyError.windescription & @CRLF & _
             "err.number is: "   & @TAB & $HexNumber        & @CRLF & _
             "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _
             "err.scriptline is: "   & @TAB & $oMyError.scriptline   & @CRLF & _
             "err.source is: "   & @TAB & $oMyError.source       & @CRLF & _
             "err.helpfile is: "       & @TAB & $oMyError.helpfile   & @CRLF & _
             "err.helpcontext is: " & @TAB & $oMyError.helpcontext _
            )
  SetError(1); to check for after this function returns
Endfunc

Func makeg2c()
    
    $g2c = FileOpen("test.txt", 1)

; Check if file opened for writing OK
If $g2c = -1 Then
    MsgBox(0, "Error", "Unable to create file.")
    Exit
EndIf
$currentview = $ge.GetCamera(1)
FileWriteLine($file, "[Location]")
FileWriteLine($file, "Latitude=" & $currentview.Latitude())
FileWriteLine($file, "Longitude=" & $currentview.Longitude())
FileWriteLine($file, "Range=" & $currentview.Range())
FileWriteLine($file, "[Settings]")
FileWriteLine($file, "Levelname=" & $levelname)
FileWriteLine($file, "Waterlevel=")
FileWriteLine($file, "Maxheight=" & @CRLF)
FileWriteLine($file, "Minheight=")

FileClose($file)
EndFunc

Func gotog2c()
    $cam.FocusPointLatitude = -16.50000000
    $cam.FocusPointLongitude = -151.73900000
    $cam.Range = $fly 
    $cam.Tilt = 0 
    $cam.Azimuth = 0 
    $setcam = $ge.SetCamera($cam, 6)
    
EndFunc

Some guy's script + some other guy's script = my script!

Link to comment
Share on other sites

COM still seems to work for me, Thanks for that example.

;~ Google Earth Object
$vGoogleEarth = ObjCreate("GoogleEarth.ApplicationGE")

$vCoords = $vGoogleEarth.GetPointOnTerrainFromScreenCoords(0.66,0)

;~ Latitude and Logitude
$vLatitude = $vCoords.Latitude()
$vLongitude = $vCoords.Longitude()

;~ Print Lat & Long to console
ConsoleWrite("Lat: " & $vLatitude & " Long: " & $vLongitude)

[font="'courier new', courier, monospace;"]Pastebin UDF | Prowl UDF[/font]

Link to comment
Share on other sites

Thanks for the ideas.  I've played around with the COM interface.  GetPointOnTerrainFromScreenCoords seems to work.  The format for the arguments is a relative position from the center of the render window.  So the middle of the render window is 0,0.  The top left is -1,1...top right is 1,1...bottom left is -1,-1...bottom right is 1,-1.

You have to take into account the window size, client size, mouse position, border widths (top and sides) to get the correct absolution position on the screen.  Then convert that to the fractional coordinate format the COM call requires.  Perhaps this can be made easier with the Opt's you used would make these calculations easier (I converted everything to absolute screen positions...looks like the Options make this much simpler to handle).

The returns from the COM call are a bit sluggish to make it "real time".  But I think this is on the right track.

Thanks for the help.

Link to comment
Share on other sites

Be aware that Google throttles certain requests, not sure about lat and lon, I guess those are unlimited, but requesting Altitude is limited to 25000 requests per IP per 24 hours.

When that limit is reached everything begins getting slow, with very limited bandwidth from google, so one has to wait 24 hours for the next 25k batch.

Some guy's script + some other guy's script = my script!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...