HOW TO
This document demonstrates how to programmatically change the coordinate system (projection) of a dataframe.
Note:
Code in ThisDocument code module will only run in the current map document. To store the code in all your map documents, open the Normal.mxt ThisDocument code module.
Code:
Private Sub Change_Projection()
Dim pIMxDoc As IMxDocument
Set pIMxDoc = ThisDocument
Dim pMap As IMap
Set pMap = pIMxDoc.FocusMap
Dim pSpatRefFact As ISpatialReferenceFactory
'Set the spatial reference factory to a new spatial referenceEnvironment
Set pSpatRefFact = New SpatialReferenceEnvironment
Dim pspatref As ISpatialReference
'Read a .prj file with projection data
Set pspatref = pSpatRefFact.CreateESRISpatialReferenceFromPRJFile _
("E:\80testing\states\prj.adf")
If Not pspatref Is Nothing Then
MsgBox "Created Spatial reference successfully"
End If
' put the new spatial reference into the map
If Not pspatref Is Nothing Then
Set pMap.SpatialReference = pspatref
Dim pActView As IActiveView
Set pActView = pMap
pActView.Refresh
MsgBox "done!!!"
End If
Dim pSecSpatRef As ISpatialReference
Set pSecSpatRef = pMap.SpatialReference
If Not pSecSpatRef Is Nothing Then
MsgBox "Assigning Spatial reference to map was successful"
End If
End Sub
Get help from ArcGIS experts
Download the Esri Support App