Source Code ServicesEditionSample DatumTransformation CS 100723.zip

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
 
namespace DatumTransformation
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new TestForm());
        }
    }
}

TestForm.cs

 using System;  
 using System.Collections.ObjectModel;  
 using System.Drawing;  
 using System.Windows.Forms;  
 using ThinkGeo.MapSuite.Core;  
 
 namespace DatumTransformation  
 {  
     public partial class TestForm : Form  
     {  
         private MapEngine mapEngine = new MapEngine();  
         private Bitmap bitmap = null;  
 
        public TestForm()  
         {  
             InitializeComponent();  
         }  
 
         private void TestForm_Load(object sender, EventArgs e)  
         {  
             // Set the extent and the background color  
             mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-9.1386,38.7187,-9.1217,38.7091), Map.Width, Map.Height);  
             mapEngine.BackgroundFillBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);  
 
             //Displays the World Map Kit as a background.  
             ThinkGeo.MapSuite.Core.WorldMapKitLayer worldMapKitLayer = new ThinkGeo.MapSuite.Core.WorldMapKitLayer();  
             mapEngine.StaticLayers.Add(worldMapKitLayer);  
 
             //InMemoryFeatureLayer for displaying the points.  
             InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer();  
             inMemoryFeatureLayer.Open();  
             inMemoryFeatureLayer.Columns.Add(new FeatureSourceColumn("Datum", "string", 20));  
             inMemoryFeatureLayer.Close();  
 
             inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimpleCircleStyle(GeoColor.StandardColors.DarkGreen,  
                                                                               10, GeoColor.StandardColors.Black, 2);  
             inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.CreateSimpleTextStyle("Datum", "Arial", 10, DrawingFontStyles.Bold,  
                                                                               GeoColor.StandardColors.Black,10,0);  
             inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
 
 
             //We are adding the points for ED50 and WGS84. You have to understand that they are actually the same points except that two different  
             //datums are used.  
 
             //The point is originatly in degrees with ED50 datum. We display it to show how offset it is compared to the same point in degrees with WGS84 datum  
             PointShape ED50pointShape = new PointShape(-9.1302509553484654, 38.714824991881208);  
             Feature ED50feature = new Feature(ED50pointShape);  
             ED50feature.ColumnValues.Add("Datum", "ED50");  
 
             inMemoryFeatureLayer.InternalFeatures.Add(ED50feature);  
 
 
             //We take the same point in ED50 datum and apply Datum trasformation to it so that it is using WGS84 as for the World Map Kit.  
             //So, the point in WGS84 is the corrected point from ED50 so that it matched World Map Kit.  
             //Notice that for datum transformation, the same API is used where you set the parameters for InternalProjectionParameters and externalProjectionParameters.  
 
             //To go from ED50 datum to WGS84 datum so that the point matches the projection of the map.  
             ManagedProj4Projection proj4 = new ManagedProj4Projection();  
 
             //Degrees ED50 for internal projection  
             //http://www.spatialreference.org/ref/epsg/62306405/  (for reference)  
             //http://en.wikipedia.org/wiki/ED50  (for further information)  
             proj4.InternalProjectionParametersString = "+proj=longlat +ellps=intl +towgs84=-157.89,-17.16,-78.41,2.118,2.697,-1.434,-1.1097046576093785 +no_defs";  
 
             //WGS84 projection (datum) for external projection  
             //http://www.spatialreference.org/ref/epsg/4326/  (for reference)  
             //http://en.wikipedia.org/wiki/WGS84 (for further information)  
             proj4.ExternalProjectionParametersString = ManagedProj4Projection.GetEpsgParametersString(4326);  
 
             proj4.Open();  
             Vertex WGS84vertex = proj4.ConvertToExternalProjection(ED50pointShape.X, ED50pointShape.Y);  
             proj4.Close();  
 
             Feature WGS84feature = new Feature(new PointShape(WGS84vertex.X, WGS84vertex.Y));  
             WGS84feature.ColumnValues.Add("Datum", "WSG84");  
 
             inMemoryFeatureLayer.InternalFeatures.Add(WGS84feature);  
 
 
             mapEngine.DynamicLayers.Add("Points", inMemoryFeatureLayer);  
 
             //Displays Scale Bar to how offset the same point is based on the datum.  
             //You can notice that the ED50 point is offset about 200 meters to the north east compared to WGS84.  
             //When doing a datum transformation, the difference is slight, usually a few meters. It can be thought as merely a correction.  
             //When changing projection to the data, though, the difference is huge. We change completely of coordinate system and the same  
             //point cannot be displayed on the same map.  
             ScaleBarAdornmentLayer scaleBarAdornmentLayer = new ScaleBarAdornmentLayer();  
             scaleBarAdornmentLayer.UnitFamily = UnitSystem.Metric;  
             scaleBarAdornmentLayer.Location = AdornmentLocation.LowerLeft;  
 
             mapEngine.AdornmentLayers.Add(scaleBarAdornmentLayer);  
 
             DrawImage();  
         }  
 
 
         private void DrawImage()  
         {  
             if (bitmap != null) { bitmap.Dispose(); }  
             bitmap = new Bitmap(Map.Width, Map.Height);  
             mapEngine.OpenAllLayers();  
             mapEngine.DrawStaticLayers(bitmap, GeographyUnit.DecimalDegree);  
             mapEngine.DrawDynamicLayers(bitmap, GeographyUnit.DecimalDegree);  
             mapEngine.DrawAdornmentLayers(bitmap, GeographyUnit.DecimalDegree);  
             mapEngine.CloseAllLayers();  
 
             Map.Image = bitmap;  
         }  
 
         private void ToolBar_ButtonClick(object sender, ToolBarButtonClickEventArgs e)  
         {  
             switch (e.Button.Tag.ToString())  
             {  
                 case "Zoom In":  
                     mapEngine.CurrentExtent.ScaleDown(50);  
                     break;  
                 case "Zoom Out":  
                     mapEngine.CurrentExtent.ScaleUp(50);  
                     break;  
                 case "Full Extent":  
                     mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-180.0, 83.0, 180.0, -90.0), Map.Width, Map.Height);  
                     break;  
                 case "Pan Left":  
                     mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Left, 20);  
                     break;  
                 case "Pan Right":  
                     mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Right, 20);  
                     break;  
                 case "Pan Up":  
                     mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Up, 20);  
                     break;  
                 case "Pan Down":  
                     mapEngine.CurrentExtent = ExtentHelper.Pan(mapEngine.CurrentExtent, PanDirection.Down, 20);  
                     break;  
                 default:  
                     break;  
             }  
             DrawImage();  
         }  
 
         private void btnClose_Click(object sender, EventArgs e)  
         {  
             this.Close();  
         }  
 
         private void Map_MouseMove(object sender, MouseEventArgs e)  
         {  
             //Displays the X and Y in screen coordinates.  
             statusStrip1.Items["toolStripStatusLabelScreen"].Text = "X:" + e.X + " Y:" + e.Y;  
 
             //Gets the PointShape in world coordinates from screen coordinates.  
             PointShape pointShape = ExtentHelper.ToWorldCoordinate(mapEngine.CurrentExtent, new ScreenPointF(e.X, e.Y), Map.Width, Map.Height);  
 
             //Displays world coordinates.  
             statusStrip1.Items["toolStripStatusLabelWorld"].Text = "(world) X:" + Math.Round(pointShape.X, 4) + " Y:" + Math.Round(pointShape.Y, 4);  
         }  
     }  
 }