ArcGIS Pro 3.0 API Reference Guide
ArcGIS.Desktop.Core.UnitFormats Namespace / DisplayUnitFormat Class
Members Example

In This Topic
    DisplayUnitFormat Class
    In This Topic
    Provides unit formatting within a Pro project
    Object Model
    DisplayUnitFormat ClassCIMAngleFormat ClassUnit ClassCIMObject Class
    Syntax
    Remarks
    Supports property notification
    Example
    Get the Current Map Location Unit
    //var map = MapView.Active.Map;
    //Must be on the QueuedTask.Run()
    
    //Get the current location unit
    var loc_unit = map.GetLocationUnitFormat();
    var line = $"{loc_unit.DisplayName}, {loc_unit.UnitCode}";
    System.Diagnostics.Debug.WriteLine(line);
    
    Get the Available List of Map Location Units
    //var map = MapView.Active.Map;
    //Must be on the QueuedTask.Run()
    
    //Linear location unit formats are not included if the map sr
    //is geographic.
    var loc_units = map.GetAvailableLocationUnitFormats();
    
    Format a Location Using the Current Map Location Unit
    var mv = MapView.Active;
    var map = mv.Map;
    
    QueuedTask.Run(() =>
    {
      //Get the current view camera location
      var center_pt = new Coordinate2D(mv.Camera.X, mv.Camera.Y);
      //Get the current location unit
      var loc_unit = map.GetLocationUnitFormat();
    
      //Format the camera location
      var str = loc_unit.FormatLocation(center_pt, map.SpatialReference);
      System.Diagnostics.Debug.WriteLine($"Formatted location: {str}");
    });
    
    Set the Location Unit for the Current Map
    var mv = MapView.Active;
    var map = mv.Map;
    
    QueuedTask.Run(() =>
    {
      //Get the list of available location unit formats
      //for the current map
      var loc_units = map.GetAvailableLocationUnitFormats();
    
      //arbitrarily use the last unit in the list
      map.SetLocationUnitFormat(loc_units.Last());
    });
    
    Get the Current Map Elevation Unit
    //var map = MapView.Active.Map;
    //Must be on the QueuedTask.Run()
    
    //If the map is not a scene, the default Project distance
    //unit will be returned
    var elev_unit = map.GetElevationUnitFormat();
    var line = $"{elev_unit.DisplayName}, {elev_unit.UnitCode}";
    System.Diagnostics.Debug.WriteLine(line);
    
    Get the Available List of Map Elevation Units
    //var map = MapView.Active.Map;
    //Must be on the QueuedTask.Run()
    
    //If the map is not a scene, the list of current
    //Project distance units will be returned
    var elev_units = map.GetAvailableElevationUnitFormats();
    
    Format an Elevation Using the Current Map Elevation Unit
    var mv = MapView.Active;
    var map = mv.Map;
    
    QueuedTask.Run(() =>
    {
      //Get the current elevation unit. If the map is not
      //a scene the default Project distance unit is returned
      var elev_unit = map.GetElevationUnitFormat();
    
      //Format the view camera elevation
      var str = elev_unit.FormatValue(mv.Camera.Z);
    
      System.Diagnostics.Debug.WriteLine($"Formatted elevation: {str}");
    });
    
    Set the Elevation Unit for the Current Map
    var map = MapView.Active.Map;
    
    QueuedTask.Run(() =>
    {
      //Trying to set the elevation unit on a map other than
      //a scene will throw an InvalidOperationException
      if (map.IsScene)
      {
        //Get the list of available elevation unit formats
        //for the current map
        var loc_units = map.GetAvailableElevationUnitFormats();
        //arbitrarily use the last unit in the list
        map.SetElevationUnitFormat(loc_units.Last());
      }
    
    });
    
    Inheritance Hierarchy

    System.Object
       ArcGIS.Desktop.Framework.Contracts.PropertyChangedBase
          ArcGIS.Desktop.Core.UnitFormats.DisplayUnitFormat

    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 8.1

    See Also