ArcGIS Pro 3.8 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.
      await 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.
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
        using (SpatialReferenceBuilder sb = new SpatialReferenceBuilder(customWkt))
        {
          // do something with the builder
    
          spatialReference = sb.ToSpatialReference();
        }
      });
    }
    SpatialReference WKT2
    {
      SpatialReference sr = SpatialReferences.WebMercator;
    
      // Get Esri WKT
      string wkt = sr.Wkt;
      /*
        PROJCS["WGS_1984_Web_Mercator_Auxiliary_Sphere",
         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["Meter", 1.0]]
      */
    
      // Get OGC WKT2
      string wkt2 = sr.GetWkt2(WktFormatMode.None);
      /*
        PROJCRS["WGS_1984_Web_Mercator_Auxiliary_Sphere",
         BASEGEOGCRS["GCS_WGS_1984",
          DYNAMIC[FRAMEEPOCH[1990.5], MODEL["AM0-2"]],
          DATUM["D_WGS_1984",
           ELLIPSOID["WGS_1984", 6378137.0, 298.257223563, LENGTHUNIT["Meter", 1.0]]],
          PRIMEM["Greenwich", 0.0, ANGLEUNIT["Degree", 0.0174532925199433]],
          CS[ellipsoidal, 2],
          AXIS["Latitude (lat)", north, ORDER[1]],
          AXIS["Longitude (lon)", east, ORDER[2]],
          ANGLEUNIT["Degree", 0.0174532925199433]],
         CONVERSION["Mercator_Auxiliary_Sphere",
          METHOD["Mercator_Auxiliary_Sphere"],
          PARAMETER["False_Easting", 0.0, LENGTHUNIT["Meter", 1.0]],
          PARAMETER["False_Northing", 0.0, LENGTHUNIT["Meter", 1.0]],
          PARAMETER["Central_Meridian", 0.0, ANGLEUNIT["Degree", 0.0174532925199433]],
          PARAMETER["Standard_Parallel_1", 0.0, ANGLEUNIT["Degree", 0.0174532925199433]],
          PARAMETER["Auxiliary_Sphere_Type", 0.0]],
         CS[Cartesian, 2],
         AXIS["Easting (X)", east, ORDER[1]],
         AXIS["Northing (Y)", north, ORDER[2]],
         LENGTHUNIT["Meter", 1.0]]
      */
    
      // You can create a spatial reference with the Esri WKT string or the OCG WKT2 string
      sr = SpatialReferenceBuilder.CreateSpatialReference(wkt2);
    
      // Get OGC WKT2 including authority in top-level objects
      // In this case the authority is written as ID["EPSG",3857]
      wkt2 = sr.GetWkt2(WktFormatMode.AuthorityTop);
      /*
        PROJCRS["WGS_1984_Web_Mercator_Auxiliary_Sphere",
         BASEGEOGCRS["GCS_WGS_1984",
         DYNAMIC[FRAMEEPOCH[1990.5],MODEL["AM0-2"]],
         DATUM["D_WGS_1984",
          ELLIPSOID["WGS_1984",6378137.0,298.257223563,LENGTHUNIT["Meter",1.0]]],
         PRIMEM["Greenwich",0.0,ANGLEUNIT["Degree",0.017453292519943295]],
         CS[ellipsoidal,2],
         AXIS["Latitude (lat)",north,ORDER[1]],
         AXIS["Longitude(lon)",east,ORDER[2]],
         ANGLEUNIT["Degree",0.017453292519943295]],
         CONVERSION["Mercator_Auxiliary_Sphere",
          METHOD["Mercator_Auxiliary_Sphere"],
          PARAMETER["False_Easting",0.0,LENGTHUNIT["Meter",1.0]],
          PARAMETER["False_Northing",0.0,LENGTHUNIT["Meter",1.0]],
          PARAMETER["Central_Meridian",0.0,ANGLEUNIT["Degree",0.017453292519943295]],
          PARAMETER["Standard_Parallel_1",0.0,ANGLEUNIT["Degree",0.017453292519943295]],
          PARAMETER["Auxiliary_Sphere_Type",0.0]],
          CS[Cartesian,2],
          AXIS["Easting (X)",east,ORDER[1]],
          AXIS["Northing (Y)",north,ORDER[2]],
          LENGTHUNIT["Meter",1.0],
          ID["EPSG",3857]]
      */
    
      // Get OGC WKT2 including authority in all objects
      // Authority is written as ID["ESPG",<id>] or ID["Esri",<id>]
      wkt2 = sr.GetWkt2(WktFormatMode.AuthorityAll);
      /*
        PROJCRS["WGS_1984_Web_Mercator_Auxiliary_Sphere",
         BASEGEOGCRS["GCS_WGS_1984",
          DYNAMIC[FRAMEEPOCH[1990.5],MODEL["AM0-2"]],
          DATUM["D_WGS_1984",
           ELLIPSOID["WGS_1984",6378137.0,298.257223563,LENGTHUNIT["Meter",1.0,ID["EPSG",9001]],ID["EPSG",7030]],
           ID["EPSG",6326]],
          PRIMEM["Greenwich",0.0,ANGLEUNIT["Degree",0.017453292519943295,ID["EPSG",9102]],ID["EPSG",8901]],
          CS[ellipsoidal,2],
          AXIS["Latitude (lat)",north,ORDER[1]],
          AXIS["Longitude(lon)",east,ORDER[2]],
          ANGLEUNIT["Degree",0.017453292519943295,ID["EPSG",9102]],ID["EPSG",4326]],
          CONVERSION["Mercator_Auxiliary_Sphere",
           METHOD["Mercator_Auxiliary_Sphere",ID["Esri",43104]],
           PARAMETER["False_Easting",0.0,LENGTHUNIT["Meter",1.0,ID["EPSG",9001]],ID["Esri",100001]],
           PARAMETER["False_Northing",0.0,LENGTHUNIT["Meter",1.0,ID["EPSG",9001]],ID["Esri",100002]],
           PARAMETER["Central_Meridian",0.0,ANGLEUNIT["Degree",0.017453292519943295,ID["EPSG",9102]],ID["Esri",100010]],
           PARAMETER["Standard_Parallel_1",0.0,ANGLEUNIT["Degree",0.017453292519943295,ID["EPSG",9102]],ID["Esri",100025]],
           PARAMETER["Auxiliary_Sphere_Type",0.0,ID["Esri",100035]]],
          CS[Cartesian,2],
          AXIS["Easting(X)",east,ORDER[1]],
          AXIS["Northing (Y)",north,ORDER[2]],
          LENGTHUNIT["Meter",1.0,ID["EPSG",9001]],
          ID["EPSG",3857]]
      */
    }
    SpatialReference Datum and datum properties
    {
      // Get datum of a spatial reference
      SpatialReference srWgs84 = SpatialReferences.WGS84;
      Datum datum = srWgs84.Datum;
      // datum.Name = "D_WGS_1984"
      // datum.Wkid = 6326
      // datum.SpheroidName = "WGS_1984"
      // datum.SpheroidWkid = 7030
      // datum.SpheroidFlattening = 0.0033528106647474805
      // datum.SpheroidSemiMajorAxis = 6378137.0
      // datum.SpheroidSemiMinorAxis = 6356752.3142451793
    
      // Custom WKT
      string wyomingWkt = "PROJCS[\"Wyoming_State_Pl_NAD_1927\",GEOGCS[\"GCS_North_American_1927\",DATUM[\"D_North_American_1927_Perry\",SPHEROID[\"Clarke_1866_Chase\",6378210.0,250.0]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"false_easting\",500000.0],PARAMETER[\"false_northing\",0.0],PARAMETER[\"central_meridian\",-107.3333333],PARAMETER[\"scale_factor\",0.9999412],PARAMETER[\"latitude_of_origin\",40.66666667],UNIT[\"Foot_US\",0.3048006096012192]]";
      SpatialReference srFromWkt = SpatialReferenceBuilder.CreateSpatialReference(wyomingWkt);
      datum = srWgs84.Datum;
      // datum.Name = "D_North_American_1927_Perry"
      // datum.Wkid = 0
      // datum.SpheroidName = "Clarke_1866_Chase"
      // datum.SpheroidWkid = 0
      // datum.SpheroidFlattening = 0.004
      // datum.SpheroidSemiMajorAxis = 6378210.0
      // datum.SpheroidSemiMinorAxis = 6352697.16
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also