ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Core.Geometry Namespace / SpatialReferenceBuilder Class / CreateSpatialReference Method / CreateSpatialReference(String) Method
The well-known text that represents the spatial reference.
Example

In This Topic
    CreateSpatialReference(String) Method
    In This Topic
    Convenience method to create a new instance of the SpatialReference class.
    Syntax
    public static SpatialReference CreateSpatialReference( 
       string wkt
    )
    Public Overloads Shared Function CreateSpatialReference( _
       ByVal wkt As String _
    ) As SpatialReference

    Parameters

    wkt
    The well-known text that represents the spatial reference.

    Return Value

    Example
    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();
      }
    });
    
    Construct a SpatialReference with a custom PCS - from a string
    // Use a builder convenience method or use a builder constructor.
    
    // Custom PCS, Predefined GCS
    string customWkt = "PROJCS[\"WebMercatorMile\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137.0,298.257223563]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Mercator_Auxiliary_Sphere\"],PARAMETER[\"False_Easting\",0.0],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",0.0],PARAMETER[\"Standard_Parallel_1\",0.0],PARAMETER[\"Auxiliary_Sphere_Type\",0.0],UNIT[\"Mile\",1609.344000614692]]";
    
    // Builder convenience methods don't need to run on the MCT.
    SpatialReference spatialReference = SpatialReferenceBuilder.CreateSpatialReference(customWkt);
    // SpatialReferenceBuilder properties
    //   spatialReference.Wkt == customWkt
    //   spatialReference.Wkid == 0
    //   spatialReference.VcsWkid == 0
    //   spatialReference.GcsWkid == 4326
    
    SpatialReference gcs = spatialReference.Gcs;
    // gcs.Wkid == 4326
    // gcs.IsGeographic == true
    // spatialReference.GcsWkt == gcs.Wkt
    
    // SpatialReferenceBuilder constructors need to run on the MCT.
    ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
    {
      using (SpatialReferenceBuilder sb = new SpatialReferenceBuilder(customWkt))
      {
        // do something with the builder
    
        spatialReference = sb.ToSpatialReference();
      }
    });
    
    Determine Transformations
    // methods need to run on the MCT
    ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
    {
      //
      // find the first transformation used between spatial references 4267 and 4326
      //
      SpatialReference sr4267 = 
           SpatialReferenceBuilder.CreateSpatialReference(4267);
      SpatialReference sr4326 = SpatialReferences.WGS84;
    
      List<ProjectionTransformation> transformations = 
             ProjectionTransformation.FindTransformations(sr4267, sr4326);
      // transformations.Count = 1
      ProjectionTransformation projTrans = transformations[0];
      CompositeGeographicTransformation compositeGT = 
           projTrans.Transformation as CompositeGeographicTransformation;
      GeographicTransformation gt = compositeGT[0];
      // gt.Wkid = 15851
      // gt.Name = "NAD_1927_To_WGS_1984_79_CONUS"
      // gt.IsForward = true
    
    
      //
      // find the first five transformation used between spatial references 4267 and 4326
      //
      transformations = ProjectionTransformation.FindTransformations(
                                         sr4267, sr4326, numResults: 5);
      // transformations.Count = 5
      projTrans = transformations[0];
      compositeGT = projTrans.Transformation as CompositeGeographicTransformation;
      // compositeGT.Count = 1
      // compositeGT[0].Wkid = 15851
      // compositeGT[0].Name = "NAD_1927_To_WGS_1984_79_CONUS"
      // compositeGT[0].IsForward = true
    
      projTrans = transformations[1];
      compositeGT = projTrans.Transformation as CompositeGeographicTransformation;
      // compositeGT.Count = 1
      // compositeGT[0].Wkid = 1173
      // compositeGT[0].Name = "NAD_1927_To_WGS_1984_4"
      // compositeGT[0].IsForward = true
    
      projTrans = transformations[2];
      compositeGT = projTrans.Transformation as CompositeGeographicTransformation;
      // compositeGT.Count = 1
      // compositeGT[0].Wkid = 1172
      // compositeGT[0].Name = "NAD_1927_To_WGS_1984_3"
      // compositeGT[0].IsForward = true
    
      projTrans = transformations[3];
      compositeGT = projTrans.Transformation as CompositeGeographicTransformation;
      // compositeGT.Count = 2
      // compositeGT[0].Wkid = 1241
      // compositeGT[0].Name = "NAD_1927_To_NAD_1983_NADCON"
      // compositeGT[0].IsForward = true
    
      // compositeGT[1].Wkid = 108190
      // compositeGT[1].Name = "WGS_1984_(ITRF00)_To_NAD_1983"
      // compositeGT[1].IsForward = false
    
      projTrans = transformations[4];
      compositeGT = projTrans.Transformation as CompositeGeographicTransformation;
      // compositeGT.Count = 2
      // compositeGT[0].Wkid = 1241
      // compositeGT[0].Name = "NAD_1927_To_NAD_1983_NADCON"
      // compositeGT[0].IsForward = true
    
      // compositeGT[1].Wkid = 1515
      // compositeGT[1].Name = "NAD_1983_To_WGS_1984_5"
      // compositeGT[1].IsForward = true
    
    
      //
      // find the first transformation used between spatial
      // references 4267 and 4326 within Alaska
      //
    
      // Alaska
      Envelope envelope = EnvelopeBuilderEx.CreateEnvelope(-161, 61, -145, 69);
      transformations = ProjectionTransformation.FindTransformations(
                                                  sr4267, sr4326, envelope);
      // transformations.Count = 1
      projTrans = transformations[0];
      compositeGT = projTrans.Transformation as CompositeGeographicTransformation;
      // compositeGT.Count = 2
      // compositeGT[0].Wkid = 1243
      // compositeGT[0].Name = "NAD_1927_To_NAD_1983_Alaska"
      // compositeGT[0].IsForward = true
    
      // compositeGT[1].Wkid = 108190
      // compositeGT[1].Name = "WGS_1984_(ITRF00)_To_NAD_1983"
      // compositeGT[1].IsForward = false
    
    
      //
      // find the first geographic transformation used between two spatial references with VCS  (use vertical = false)
      //
      SpatialReference inSR = 
                      SpatialReferenceBuilder.CreateSpatialReference(4269, 115702);
      SpatialReference outSR = 
                      SpatialReferenceBuilder.CreateSpatialReference(4326, 3855);
    
      // Even though each spatial reference has a VCS,
      // vertical = false should return geographic transformations.
      transformations = ProjectionTransformation.FindTransformations(inSR, outSR);
      // transformations.Count = 1
      projTrans = transformations[0];
      compositeGT = projTrans.Transformation as CompositeGeographicTransformation;
      // compositeGT.Count = 1
      // compositeGT[0].Wkid = 108190
      // compositeGT[0].Name = ""WGS_1984_(ITRF00)_To_NAD_1983"
      // compositeGT[0].IsForward = false
    
      //
      // find the first vertical transformation used between two spatial references with VCS  (use vertical = true)
      //
    
      transformations = 
                ProjectionTransformation.FindTransformations(
                                        inSR, outSR, vertical: true);
      // transformations.Count = 1
      projTrans = transformations[0];
    
      CompositeHVDatumTransformation compositeHV = 
              projTrans.Transformation as CompositeHVDatumTransformation;
      // compositeHV.Count = 2
      // compositeHV[0].Wkid = 1188
      // compositeHV[0].Name = "NAD_1983_To_WGS_1984_1"
      // compositeHV[0].IsForward = true
    
      // compositeHV[1].Wkid = 110019
      // compositeHV[1].Name = "WGS_1984_To_WGS_1984_EGM2008_2.5x2.5_Height"
      // compositeHV[1].IsForward = true
    });
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also