ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.Geometry Namespace / Unit Class / FactoryCode Property
Example

In This Topic
    FactoryCode Property
    In This Topic
    Gets the well-known ID of the unit. If the unit is a custom unit, then the factory code will be 0.
    Syntax
    Public ReadOnly Property FactoryCode As Integer
    public int FactoryCode {get;}
    Example
    AngularUnit - Create an AngularUnit with a factory code
    {
      try
      {
        // create a Grad unit
        var grad = AngularUnit.CreateAngularUnit(9105);
        string unitName = grad.Name;                        // Grad
        double conversionFactor = grad.ConversionFactor;    // 0.015708
        double radiansPerUnit = grad.RadiansPerUnit;
        int factoryCode = grad.FactoryCode;                 // 9105
    
        // convert 10 grads to degrees
        double val = grad.ConvertTo(10, AngularUnit.Degrees);
    
        // convert 10 radians to grads
        val = grad.ConvertFromRadians(10);
      }
      catch (ArgumentException)
      {
        // ArgumentException will be thrown by CreateAngularUnit in
        // the following scenarios:
        // - if the factory code used is a non-angular factory code
        //   (i.e. it corresponds to square meters which is an area unit code)
        // - if the factory code used is invalid
        //   (i.e. it is negative or doesn't correspond to any factory code)
      }
    
    }
    AngularUnit - Create a Custom AngularUnit
    {
      // custom unit - 3 radians per unit
      var myAngularUnit = AngularUnit.CreateAngularUnit("myCustomAngularUnit", 3);
      string Name = myAngularUnit.Name;                   // myCustomAngularUnit
      double Factor = myAngularUnit.ConversionFactor;     // 3
      int Code = myAngularUnit.FactoryCode;               // 0 because it is a custom angular unit
      double radiansUnit = myAngularUnit.RadiansPerUnit;  // 3
    
      // convert 10 degrees to my unit
      double converted = AngularUnit.Degrees.ConvertTo(10, myAngularUnit);
      // convert it back to degrees
      converted = myAngularUnit.ConvertTo(converted, AngularUnit.Degrees);
    
      // convert 1 radian into my angular units
      converted = myAngularUnit.ConvertFromRadians(1);
    
      // get the wkt
      string wkt = myAngularUnit.Wkt;
    
      // create an angular unit from this wkt
      var anotherAngularUnit = AngularUnit.CreateAngularUnit(wkt);
      // anotherAngularUnit.ConversionFactor = 3
      // anotherAngularUnit.FactoryCode = 0    
      // anotherAngularUnit.RadiansPerUnit = 3
    }
    LinearUnit - Create a LinearUnit with a factory code
    {
      try
      {
        // create a british 1936 foot
        var britFoot = LinearUnit.CreateLinearUnit(9095);
        string unitName = britFoot.Name;                        //  "Foot_British_1936"
        double conversionFactor = britFoot.ConversionFactor;    // 0.3048007491
        double metersPerUnit = britFoot.MetersPerUnit;
        int factoryCode = britFoot.FactoryCode;                 // 9095
    
        // convert 10 british 1936 feet to centimeters
        double val = britFoot.ConvertTo(10, LinearUnit.Centimeters);
    
        // convert 10 m to british 1936 feet
        val = britFoot.ConvertFromMeters(10);
      }
      catch (ArgumentException)
      {
        // ArgumentException will be thrown by CreateLinearUnit
        // in the following scenarios:
        // - if the factory code used is a non-linear factory code
        //   (i.e. it corresponds to square meters which is an area unit code)
        // - if the factory code used is invalid
        //   (i.e. it is negative or doesn't correspond to any factory code)
      }
    
    }
    LinearUnit - Create a Custom LinearUnit
    {
      // create a custom linear unit - there are 0.33 meters per myLinearUnit
      var myLinearUnit = LinearUnit.CreateLinearUnit("myCustomLinearUnit", 0.33);
      string name = myLinearUnit.Name;                          // myCustomLinearUnit
      double convFactor = myLinearUnit.ConversionFactor;        // 0.33
      int code = myLinearUnit.FactoryCode;                      // 0 for custom units
      double metersUnit = myLinearUnit.MetersPerUnit;           // 0.33
      string toString = myLinearUnit.ToString();                // same as Name - myCustomLinearUnit
    
      // convert 10 centimeters to myLinearUnit 
      double convertedVal = LinearUnit.Centimeters.ConvertTo(10, myLinearUnit);
    
      // get the wkt
      string lu_wkt = myLinearUnit.Wkt;
    
      // create an angular unit from this wkt
      var anotherLinearUnit = LinearUnit.CreateLinearUnit(lu_wkt);
      // anotherLinearUnit.ConversionFactor = 0.33
      // anotherLinearUnit.FactoryCode = 0    
      // anotherLinearUnit.MetersPerUnit = 0.33
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also