Converting east/north to Lat/Long using projected Spatial Reference

415
3
Jump to solution
11-04-2019 01:46 AM
EhabNada
New Contributor II

Hi,

I'm new in programming using arcobjects, trying to build a desktop arcmap 10.5 add-in using C#, one of the main issues i'm not able to solve is converting (easting/northing) to (latitude/longitude) using same "projected" SpatialReference, that means that the conversion should use the ellipsoid information stored in the same projected spatial reference assigned to the feature.

Thanks,

0 Kudos
1 Solution

Accepted Solutions
EhabNada
New Contributor II

Hi,

in case someone does need this, with a bit of help from Google, not sure if this is the best way to do it but i was able to do coordinate conversion both ways using one assigned projected geodesy, i'll summarize it:

Try

{

   ISpatialReference s1;      //this will be used for the feature dataset projected geodesy reference.

   ISpatialReference s2;      // the Geographic geodesy reference.

 

 

   IProjectedCoordinateSystem PrjSyst = (IProjectedCoordinateSystem)s1;
   string GeographicalCSName = PrjSyst.GeographicCoordinateSystem.Name;

 

   var srProjCSArray = Enum.GetValues(typeof(esriSRGeoCSType));
   var srEnvirnonment = new SpatialReferenceEnvironment();

   foreach (var item in srProjCSArray)
   {
      ISpatialReference sr = srEnvirnonment.CreateGeographicCoordinateSystem((int)item);
      if (sr.Name == GeographicalCSName)
      {
         s2= sr;

         //break;
      }
   }

   IPoint point;

   IGeometry geometry;
   geometry = point;

   // from projected to geographic
   geometry.SpatialReference = s1;
   geometry.Project(s2);
   point= (IPoint)geometry;

 

...........

}

.....

View solution in original post

3 Replies
MelitaKennedy
Esri Notable Contributor

If you have the spatial reference, get the ProjectedCoordinateSystem, then the GeographicCoordinateSystem from that. Use the GCS as the target/output coordinate system.

EhabNada
New Contributor II

Thanks! I'm not experienced in arcobjetcs library, so not sure how to do this but will give it a try, if you have a hint it will be appreciated though.

thanks again.

0 Kudos
EhabNada
New Contributor II

Hi,

in case someone does need this, with a bit of help from Google, not sure if this is the best way to do it but i was able to do coordinate conversion both ways using one assigned projected geodesy, i'll summarize it:

Try

{

   ISpatialReference s1;      //this will be used for the feature dataset projected geodesy reference.

   ISpatialReference s2;      // the Geographic geodesy reference.

 

 

   IProjectedCoordinateSystem PrjSyst = (IProjectedCoordinateSystem)s1;
   string GeographicalCSName = PrjSyst.GeographicCoordinateSystem.Name;

 

   var srProjCSArray = Enum.GetValues(typeof(esriSRGeoCSType));
   var srEnvirnonment = new SpatialReferenceEnvironment();

   foreach (var item in srProjCSArray)
   {
      ISpatialReference sr = srEnvirnonment.CreateGeographicCoordinateSystem((int)item);
      if (sr.Name == GeographicalCSName)
      {
         s2= sr;

         //break;
      }
   }

   IPoint point;

   IGeometry geometry;
   geometry = point;

   // from projected to geographic
   geometry.SpatialReference = s1;
   geometry.Project(s2);
   point= (IPoint)geometry;

 

...........

}

.....

View solution in original post