الاثنين، ٣١ مارس ٢٠٠٨

ArcMap and Google Earth Integration


The movie below shows how to build a tool in ArcMap that will sycronize the current ArcMap extent with Google Earth extent this code is working with wg84 projections. To use this code you should have GE installed on your PC


copy the code below to a mousedown event on UIToolControl on ArcMap VBA

Dim pScreenDisplay As IScreenDisplay
Dim pActiveView As IActiveView
Dim pMxDoc As IMxDocument

Set pMxDoc = Application.Document
Set pActiveView = pMxDoc.FocusMap
Set pScreenDisplay = pActiveView.ScreenDisplay
pScreenDisplay.TrackPan

Dim pMap As IMap
Dim pMapsActiveView As IActiveView
Dim pEnvelope As IEnvelope
Dim pCenterPt As IPoint
Dim pEnvSpatRef As ISpatialReference
Dim pSRI As ISpatialReferenceInfo
Dim pPCS As IProjectedCoordinateSystem
Dim dMetersPerUnit As Double
Dim viewAlt As Double

'Google Earth Parameters

Dim GE As IApplicationGE
Set GE = New ApplicationGE

'Set the ArcMap values
Set pMxDoc = Application.Document
Set pMap = pMxDoc.FocusMap
Set pMapsActiveView = pMap
Set pEnvelope = pMapsActiveView.Extent
Set pCenterPt = New Point
Set pEnvSpatRef = pEnvelope.SpatialReference

'Get current meters per map unit
If pEnvSpatRef Is Nothing Then
MsgBox "Please set a projection for your Map", vbOKOnly, "No Projection Set"
Exit Sub
ElseIf TypeOf pEnvSpatRef Is IUnknownCoordinateSystem Then
MsgBox "Please set a projection for your Map", vbOKOnly, "Projection Unknown"
Exit Sub
ElseIf TypeOf pEnvSpatRef Is IProjectedCoordinateSystem Then
Set pPCS = pEnvSpatRef
dMetersPerUnit = pPCS.CoordinateUnit.MetersPerUnit
Else
dMetersPerUnit = 1
End If

'Set view altitude the same as the width (seems to zoom enough)
'Get width, then convert it to meters using the metersperunit value
viewAlt = Round((pEnvelope.LowerRight.x - pEnvelope.LowerLeft.x) * dMetersPerUnit)

'Create a WGS84 spatial reference for LatLong in Google
Dim pSpRef2 As ISpatialReference
Dim pSpRFc As SpatialReferenceEnvironment
Dim pGCS As IGeographicCoordinateSystem
Set pSpRFc = New SpatialReferenceEnvironment
Set pGCS = pSpRFc.CreateGeographicCoordinateSystem(esriSRGeoCS_WGS1984)
Set pSpRef2 = pGCS
pSpRef2.SetFalseOriginAndUnits -180, -90, 1000000

'Project the envelope to WGS84
pEnvelope.Project pSpRef2

'Get the Center Point: ((XMin + XMax) / 2, (YMin + YMax) / 2)
pCenterPt.PutCoords (pEnvelope.LowerLeft.x + pEnvelope.LowerRight.x) / 2, _
(pEnvelope.LowerLeft.y + pEnvelope.UpperRight.y) / 2

'Send the parameters to Google
'Note: The altitude mode - RelativeToGroundAltitudeGE = 1, AbsoluteAltitudeGE = 2
'If set the speed to 5 or more it snaps to the site (no transition), a lower number
'(i.e. 3.5) helps show movement has taken place

While (GE.IsInitialized = 0)
'In theory this waits for Google Earth to load if it isn't open already
Wend
GE.SetCameraParams pCenterPt.y, pCenterPt.x, 0, 1, viewAlt, 0, 0.01, 3.5

You can find this tool in http://arcscripts.esri.com/ i have added some minor coding to allow this tool to work with mousedown event.

All the best


هناك ٦ تعليقات:

غير معرف يقول...

Muito bom esse poste, parabéns
Como vc chegou a esse código
Um abraço
Sadeck

GIS Developer يقول...

thank you
i used google translator to understand what you wrote

this is the english version for my readers:

Very good this post, congratulations
As you come to this code
A hug
Sadeck

thanks again for sharing

Haitham Al-Amri يقول...

very interesting blog>>>>
well...i've been looking for this script for long time..
however, i am not very good at VB...and i had this error saying 'Compile Error: can't find project or library'

this is a screenshot of what's happening...

http://www3.0zz0.com/2008/08/25/04/441526416.jpg

thanks for this website...

AAA
Oman

Kañaz يقول...

Hi Oman I was just trying your tool to integrate google earth and arcmap but have a mistake when running in Google Earth Parameters can you help me please

Amin

Unknown يقول...

الاخ المهندس بعد التحية لم نستطيع تركيب الشفرة الرجاء الشرح بالتفصيل وجزاك الله خير\
مهندس عبد القادر السودان

غير معرف يقول...

hi,
thank you for your tips to integrate Google earth into arcGIS.
May i know the version of ArcGis you shown is version 9.3?
I have followed your steps and copy your codes into my arcMap..
but still having problem to synchronize google earth to arcGIS.
can you give me some guidance?