I have 2 data frames one which has WGS data in it and the other OSGB1936. I am trying to create a button where the user can input decimal degrees (WGS) and it will zoom them to that location in British National GRid (OSGB1936) I have done the code but when it zooms to OSGB data frame it does not convert the decimal degree to meters. It returns incorrect values for Northing and Eastings in meters.
The code does work only if i have done it as a ToolControl_MouseDown but that uses pMxDoc.CurrentLocation.x, pMxDoc.CurrentLocation.y. which i dont want to do because i want the user to enter the value from a text box. Any ideas please?
Private Sub CommandButton2_Click()
Dim pSREnv As ISpatialReferenceFactory2
Set pSREnv = New SpatialReferenceEnvironment
Set m_PCS = pSREnv.CreateProjectedCoordinateSystem(esriSRProjCS_BritishNationalGrid)
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
Dim x As Double
Dim y As Double
y = CDbl(Texty.Text)
x = CDbl(Textx.Text)
Dim pEnvelope As IEnvelope
Dim pMap As IMap
'Set pMap = pMxDox.FocusMap
Dim strName As String
strName = "Layers"
Set pMap = GetMap(strName)
If Not pMap Is Nothing Then
If pMxDoc.ActiveView Is pMxDoc.PageLayout Then
Set pMxDoc.ActiveView.FocusMap = pMap
Else
Set pMxDoc.ActiveView = pMap
End If
End If
Dim pPoint As IPoint
Set pPoint = New Point
pPoint.PutCoords x, y 'pMxDoc.CurrentLocation.x, pMxDoc.CurrentLocation.y
Dim pGeom As IGeometry
Set pGeom = pPoint
Set pGeom.SpatialReference = pMxDoc.FocusMap.SpatialReference
pGeom.Project m_PCS
Set pEnvelope = pMxDoc.ActiveView.Extent
pEnvelope.CenterAt pPoint
pMxDoc.ActiveView.Extent = pEnvelope
pMap.mapScale = 5000
pMxDoc.ActiveView.Refresh
Application.StatusBar.Message(0) = "meters east: " & pPoint.x & ", meters north:" & pPoint.y
End Sub
The below code is the updated but still does not do what it should. When i enter the decimal degrees 53.47574, -2.22553 it returns a value of -512464, -2174656 which is in the incorrect position. So somewhere in the conversion between WSG and OSGB it is going very wrong.
`Private Sub CommandButton2_Click()
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
Dim pEnvelope As IEnvelope
Dim pMap As IMap
Dim pSREnv As ISpatialReferenceFactory2
Set pSREnv = New SpatialReferenceEnvironment
Dim pProjCoordSystem As ISpatialReference
Dim pProjCoordSystem2 As ISpatialReference
Dim pGeoTrans_A As IGeoTransformation
'Dim pGeoTrans_B As IGeoTransformation
Set pProjCoordSystem2 = pSREnv.CreateProjectedCoordinateSystem(esriSRProjCS_BritishNationalGrid)
Set pProjCoordSystem = pSREnv.CreateProjectedCoordinateSystem(esriSRProjCS_WGS1984UTM_14N)
Set pGeoTrans_A = _
pSREnv.CreateGeoTransformation(esriSRGeoTransformationType.esriSRGeoTransformation_OSGB1936_To_WGS1984_1)
Dim strName As String
strName = "Layers"
Set pMap = GetMap(strName)
If Not pMap Is Nothing Then
If pMxDoc.ActiveView Is pMxDoc.PageLayout Then
Set pMxDoc.ActiveView.FocusMap = pMap
Else
Set pMxDoc.ActiveView = pMap
End If
End If
Dim x As Double
Dim y As Double
y = CDbl(Texty.Text)
x = CDbl(Textx.Text)
Dim pPoint As IPoint
Set pPoint = New Point
'Set pPoint = New esriGeometry.Point
Set pPoint.SpatialReference = pProjCoordSystem2
pPoint.PutCoords x, y 'pMxDoc.CurrentLocation.x, pMxDoc.CurrentLocation.y
Dim pGeom As IGeometry2
Set pGeom = pPoint
Set pGeom.SpatialReference = pProjCoordSystem2
pGeom.ProjectEx pProjCoordSystem2, esriTransformForward, pGeoTrans_A, 0, 0, 0
Set pEnvelope = pMxDoc.ActiveView.Extent
pEnvelope.CenterAt pPoint
pMxDoc.ActiveView.Extent = pEnvelope
pMap.mapScale = 5000
pMxDoc.ActiveView.Refresh
Application.StatusBar.Message(0) = "meters east: " & pPoint.x & ", meters north:" & pPoint.y
End Sub'
Set pProjCoordSystem = pSREnv.CreateProjectedCoordinateSystem(esriSRProjCS_WGS1984UTM_14N)
What should i be using if i just want the standard WGS1984? – Daz Feb 21 '13 at 15:38