ArcGIS Pro 3.1 API Reference Guide
ArcGIS.Core.Geometry Namespace / SpatialReferenceBuilder Class / ToSpatialReference Method
Example

In This Topic
    ToSpatialReference Method
    In This Topic
    Returns a SpatialReference instance representing the current state of the builder. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public SpatialReference ToSpatialReference()
    Public Function ToSpatialReference() As SpatialReference

    Return Value

    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Example
    Construct a SpatialReference - from a well-known ID
    // Use a builder convenience method or use a builder constructor.
    
    // SpatialReferenceBuilder convenience methods don't need to run on the MCT.
    SpatialReference sr3857 = SpatialReferenceBuilder.CreateSpatialReference(3857);
    
    // SpatialReferenceBuilder constructors need to run on the MCT.
    ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
    {
      using (SpatialReferenceBuilder srBuilder = new SpatialReferenceBuilder(3857))
      {
        // do something with the builder
    
        sr3857 = srBuilder.ToSpatialReference();
      }
    });
    
    Construct a SpatialReference - from a string
    // Use a builder convenience method or use a builder constructor.
    
    string wkt = "GEOGCS[\"MyGCS84\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Radian\",1.0]]";
    
    // SpatialReferenceBuilder convenience methods don't need to run on the MCT.
    SpatialReference sr = SpatialReferenceBuilder.CreateSpatialReference(wkt);
    
    // SpatialReferenceBuilder constructors need to run on the MCT.
    ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
    {
      using (SpatialReferenceBuilder builder = new SpatialReferenceBuilder(wkt))
      {
        // do something with the builder
    
        SpatialReference anotherSR = builder.ToSpatialReference();
      }
    });
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.0 or higher.
    See Also