This document is archived and information here might be outdated.  Recommended version.


Change Map Spatial Reference Snippet (ArcObjects .NET 10.5 SDK)
ArcObjects Library Reference

Change Map Spatial Reference Snippet

Use the SpatialReferenceDialog to change the coordinate system or spatial reference of the map.

[C#]
///<summary>Use the SpatialReferenceDialog to change the coordinate system or spatial reference of the map.</summary>
///
///<param name="hWnd">The application window handle.</param>
///<param name="map">An IMap interface.</param>
/// 
///<remarks></remarks>
public void ChangeMapSpatialReference(System.Int32 hWnd, ESRI.ArcGIS.Carto.IMap map)
{
  if(map == null)
  {
    return;
  }
  
  ESRI.ArcGIS.CatalogUI.ISpatialReferenceDialog2 spatialReferenceDialog=new ESRI.ArcGIS.CatalogUI.SpatialReferenceDialogClass();
  ESRI.ArcGIS.Geometry.ISpatialReference spatialReference=spatialReferenceDialog.DoModalCreate(true, false, false, hWnd);
  if ((!(map.SpatialReferenceLocked)))
  {
    map.SpatialReference=spatialReference; 
  }
}
[Visual Basic .NET]
'''<summary>Use the SpatialReferenceDialog to change the coordinate system or spatial reference of the map.</summary>
'''
'''<param name="hWnd">The application window handle.</param>
'''<param name="map">An IMap interface.</param>
''' 
'''<remarks></remarks>
Public Sub ChangeMapSpatialReference(ByVal hWnd As System.Int32, ByVal map As ESRI.ArcGIS.Carto.IMap)

  If map Is Nothing Then

    Return

  End If

  Dim spatialReferenceDialog As ESRI.ArcGIS.CatalogUI.ISpatialReferenceDialog2=New ESRI.ArcGIS.CatalogUI.SpatialReferenceDialogClass
  Dim spatialReference As ESRI.ArcGIS.Geometry.ISpatialReference=spatialReferenceDialog.DoModalCreate(True, False, False, hWnd)

  If (Not (map.SpatialReferenceLocked)) Then

    map.SpatialReference=spatialReference

  End If

End Sub

Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.Carto
  • ESRI.ArcGIS.CatalogUI
  • ESRI.ArcGIS.Framework
  • ESRI.ArcGIS.Geometry