ArcGIS Pro 3.7 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;
        //Note: 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
    {
        //Linear location unit formats are not included if the map sr
        //is geographic.
        //Note: Must be on the QueuedTask.Run()
        var loc_units = map.GetAvailableLocationUnitFormats();
    }
    Format a Location Using the Current Map Location Unit
    {
        //Get the current view camera location
        var center_pt = new Coordinate2D(mapView.Camera.X, mapView.Camera.Y);
        //Get the current location unit
        //Note: Must be on the QueuedTask.Run()
        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
    {
        //Get the list of available location unit formats
        //for the current map
        //Note: Must be on the QueuedTask.Run()
        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 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
    {
        //If the map is not a scene, the list of current
        //Project distance units will be returned
        //Note: Must be on the QueuedTask.Run()
        var elev_units = map.GetAvailableElevationUnitFormats();
    }
    Format an Elevation Using the Current Map Elevation Unit
    {
        //Get the current elevation unit. If the map is not
        //a scene the default Project distance unit is returned
        //Note: Must be on the QueuedTask.Run()
        var elev_unit = map.GetElevationUnitFormat();
    
        //Format the view camera elevation
        var str = elev_unit.FormatValue(mapView.Camera.Z);
    
        System.Diagnostics.Debug.WriteLine($"Formatted elevation: {str}");
    }
    Set the Elevation Unit for the Current Map
    {
        //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
            //Note: Must be on the QueuedTask.Run()
            map.SetElevationUnitFormat(loc_units.Last());
        }
    }
    Inheritance Hierarchy

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

    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also