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,
Solved! Go to Solution.
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;
...........
}
.....
If you have the spatial reference, get the ProjectedCoordinateSystem, then the GeographicCoordinateSystem from that. Use the GCS as the target/output coordinate system.
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.
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;
...........
}
.....