0

I am using a text box to enter the projection name(for example : WGS_1984_UTM_Zone_37N) and I want to get that spatial reference detail using arcobjects(vb.net/C#). How to accomplish this? Kindly clarify.

user2408848
  • 151
  • 7

1 Answers1

0

Providing TextBox to enter the projection name is a bad idea, as it will allow the user to enter any value, which may not be in the format you want. ie "WGS84_UTM_zone_37N" or "WGS 1984 UTM Zone 37N" etc. all are valid values but, you will have lot of trouble to identify which Spatial Reference user is looking for.

I would suggest you to provide a dropdown instead and use one of the Projection system contants like esriSRProjCSType and/or esriSRGeoCSType, and populated the dropdown.

If you still want it, you would have to create an instance of all the spatialreference till you find a match with the value entered in the textbox.

private ISpatialReference GetSpatialReference(string srName){
    var srProjCSArray = Enum.GetValues(typeof(esriSRProjCSType));
    var srEnvirnonment = new SpatialReferenceEnvironment();

    foreach (var item in srProjCSArray)
    {
         var sr = srEnvirnonment.CreateProjectedCoordinateSystem((int)item);
         if(sr.Name == srName)
             return sr;
    }
}

This method works only for Projected Coordinate system, you would have to do similarly for Geographic Coordinate system.

T Kambi
  • 1,389
  • 2
  • 9
  • 16