[ArcEngine] How can I convert a shape from geographic to projected?

991
2
Jump to solution
06-18-2012 09:04 AM
ManfredLauterbach
Occasional Contributor
Hi,
This question is derived from http://forums.arcgis.com/threads/56517-ArcEngine-Drawing-projected-geometry?p=194053.

When developing a new test third party application that uses ArcEngine, I create and draw a simple circle at a location into a default, newly instantiated graphic tracker.
The shape is displayed as a perfect circle.

If I were to draw this shape using a projection, in order to represent it as it would appear on the earth's surface - but on a flat projected surface of the earth's surface, then it would appear as an ellipse (especially at 60 degrees LAT North).

I've tried the following code to perform this conversion, but it does not work - does anyone know why?
          PointClass centroid = new PointClass() { X = 0, Y = 60};           PointClass permiterPoint = new PointClass() { X = 4, Y = 60 };           CircularArcClass circularArc = new CircularArcClass();           circularArc.PutCoords(centroid, permiterPoint, permiterPoint, esriArcOrientation.esriArcClockwise);            IPolygon polygon = new PolygonClass();           segmentCollection = polygon as ISegmentCollection;           segmentCollection.AddSegment(circularArc);            ESRI.ArcGIS.Geometry.ISpatialReference2 spatialRef;           ESRI.ArcGIS.Geometry.ISpatialReferenceFactory2 factory = (ISpatialReferenceFactory2)new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironment();           spatialRef = (ISpatialReference2)factory.CreateSpatialReference((int)ESRI.ArcGIS.Geometry.esriSRGeoCSType.esriSRGeoCS_WGS1984);            polygon.Project(spatialRef);            // ... Add shape to tracker
0 Kudos
1 Solution

Accepted Solutions
ManfredLauterbach
Occasional Contributor
There seems to be insufficient information from ESRI to establish how to do this, forcing me to use a non-ESRI workaround :

I have downloaded and used a WMM (world magnetic model) library to calculate the correct coordinates for the desired projection and simply provide the correct coordinates to contruct ESRI geometry.

View solution in original post

0 Kudos
2 Replies
ManfredLauterbach
Occasional Contributor
In this example : http://help.arcgis.com/EN/sdk/10.0/ArcObjects_NET/conceptualhelp/index.html#//000100000m6z000000
      //Create source spatial reference.
      Type factoryType = Type.GetTypeFromProgID("esriGeometry.SpatialReferenceEnvironment");
      System.Object obj = Activator.CreateInstance(factoryType);
      ISpatialReferenceFactory3 spatialReferenceFactory = obj as ISpatialReferenceFactory3;

      ISpatialReference spatialReference = spatialReferenceFactory.CreateGeographicCoordinateSystem((int) esriSRGeoCSType.esriSRGeoCS_WGS1984);
      spatialReference.SetFalseOriginAndUnits(-80.0000000232831, 39.9999999767169, 42949672.9);
      
      //Create an envelope and define its spatial reference.
      IEnvelope envelope = new EnvelopeClass();
      envelope.PutCoords(-68.6076204314651, 49.6186709634653, -68.5531907607304, 49.6530789785679);
      envelope.SpatialReference = spatialReference;
      
      //Destination spatial reference.
      ISpatialReference projectedCoordinateSystem = spatialReferenceFactory.CreateProjectedCoordinateSystem((int) esriSRProjCSType.esriSRProjCS_NAD1927UTM_19N);
      
      //Define the XYDomain equivalent to SetFalseOriginAndUnits.
      projectedCoordinateSystem.SetDomain(500000, 600000, 5300000, 5600000);
      String report = "Print envelope coordinates before projection:\n" +
          envelope.XMin + " , " + envelope.YMin + " , " + envelope.XMax + " , " + envelope.YMax + "\n\n\n";
      
      //Project envelope.
      IGeometry geometry = envelope as IGeometry2;
      geometry.Project(projectedCoordinateSystem as ISpatialReference);
      report = report + "Print envelope coordinates after projection:\n" +
          envelope.XMin + " , " + envelope.YMin + " , " + envelope.XMax + " , " + envelope.YMax;
      System.Windows.Forms.MessageBox.Show(report);


The input coordinates for the target envelope are : -68.6076204314651, 49.6186709634653, -68.5531907607304, 49.6530789785679
Running the code provides the following output coordinates : 528323.415273589, 5496089.14621679, 532275.069518614, 5499936.46383288

Displaying the input envelope on the map works - but how do I display the projected envelope in the same map?
(which additional conversion is necessary?)
0 Kudos
ManfredLauterbach
Occasional Contributor
There seems to be insufficient information from ESRI to establish how to do this, forcing me to use a non-ESRI workaround :

I have downloaded and used a WMM (world magnetic model) library to calculate the correct coordinates for the desired projection and simply provide the correct coordinates to contruct ESRI geometry.
0 Kudos