Can I create a spatialreference from an existing prj file?

89
2
Jump to solution
05-27-2022 12:18 PM
MarioLandry2
New Contributor III

When developing under ArcMap, we used to be able to create a spatialreference from a prj file just like in this example:

 pSpatialReference = pSRFact.CreateESRISpatialReferenceFromPRJFile(_sPrjFile);

But when I look at the documentation for ArcGIS Pro SDK, I only see that in order to create a spatial reference, the most common way of doing it is using a wkid number.

Can I do it using a prj file, or am I missing something here?

0 Kudos
1 Solution

Accepted Solutions
NarelleChedzey
Esri Contributor

Hi , 

 

We don't have anything to use the prj file directly, but I believe you should be able to use the following code as the prj file contains text in the wkt format.  I have wrapped the CreateSpatialReference call in a try/catch in case of error which would need to be handled. 

      try
      {
        string path = @"c:\60571.prj";
        var sText = System.IO.File.ReadAllText(path);
        SpatialReference sr  = SpatialReferenceBuilder.CreateSpatialReference(sText);
      }
      catch (Exception e)
      {
      }

 

Regards

Narelle

View solution in original post

0 Kudos
2 Replies
NarelleChedzey
Esri Contributor

Hi , 

 

We don't have anything to use the prj file directly, but I believe you should be able to use the following code as the prj file contains text in the wkt format.  I have wrapped the CreateSpatialReference call in a try/catch in case of error which would need to be handled. 

      try
      {
        string path = @"c:\60571.prj";
        var sText = System.IO.File.ReadAllText(path);
        SpatialReference sr  = SpatialReferenceBuilder.CreateSpatialReference(sText);
      }
      catch (Exception e)
      {
      }

 

Regards

Narelle

0 Kudos
MarioLandry2
New Contributor III

Thanks a lot Narelle.  It will work for me.

0 Kudos