User Tools

Site Tools


source_code_desktopeditionsample_sphericalmercatorprojectionadjustment_cs_110514.zip

Source Code DesktopEditionSample SphericalMercatorProjectionAdjustment CS 110514.zip

Program.cs

 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Windows.Forms;  
 
 namespace SphericalMercatorProjectionAdjustment  
 {  
     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.Windows.Forms;  
 using ThinkGeo.MapSuite.Core;  
 using ThinkGeo.MapSuite.DesktopEdition;  
 
 
 namespace  SphericalMercatorProjectionAdjustment  
 {  
     public partial class TestForm : Form  
     {  
 
         public TestForm()  
         {  
             InitializeComponent();  
         }  
 
         private void TestForm_Load(object sender, EventArgs e)  
         {  
             winformsMap1.MapUnit = GeographyUnit.Meter;  
             winformsMap1.CurrentExtent = new RectangleShape(-183470, 7119187, -177290, 7115400);  
             winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 198, 255, 255));  
 
             //Displays the World Map Kit as a background.  
             GoogleMapsOverlay googleMapsOverlay = new GoogleMapsOverlay();  
             winformsMap1.Overlays.Add(googleMapsOverlay);  
 
             //Sets the projection to go from British National Grid to Spherical Mercator used by Google Map.  
             Proj4Projection proj4 = new Proj4Projection();  
             //British National Grid  
             //http://www.spatial-reference.org/ref/epsg/27700/  
             proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(27700);  
             //Spherical Mercator projection used by Google Map.  
             //GetGoogleMapParametersString returns "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +no_defs"  
             proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();  
 
             ShapeFileFeatureLayer shapefileFeatureLayer = new ShapeFileFeatureLayer( @"..\..\data\railways_leeds.shp");  
             shapefileFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.Railway1;  
             shapefileFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
 
             //Sets the projection. You can notice that the railways layer is offset about one hundred meters to the east.  
             shapefileFeatureLayer.FeatureSource.Projection = proj4;  
 
             LayerOverlay staticOverlay = new LayerOverlay();  
             staticOverlay.Layers.Add("Railways", shapefileFeatureLayer);  
             winformsMap1.Overlays.Add("StaticOverlay", staticOverlay);  
 
             winformsMap1.Refresh();  
         }  
 
         private void btnAdjust_Click(object sender, EventArgs e)  
         {  
             //The purpose of this function is to adjust the inaccuracy that occurs in many cases from using straight GetGoogleMapParameters function when going  
             //from ellipsoid datum to spherical datum.  
             Proj4Projection proj4 = new Proj4Projection();  
             proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(27700);  
             //From the original Spherical Mercator projection string, we add the parameter +nadgrids=@null so that no grid shift occurs when going from airy ellipsoid based datum  
             //to Spherical datum used by Spherical Mercator projection.  
             proj4.ExternalProjectionParametersString = "+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs";  
 
             ShapeFileFeatureLayer shapefileFeatureLayer = (ShapeFileFeatureLayer)winformsMap1.FindFeatureLayer("Railways");  
             shapefileFeatureLayer.FeatureSource.Projection = proj4;  
 
             proj4.Open();  
             winformsMap1.Refresh(winformsMap1.Overlays["StaticOverlay"]);  
 
             btnAdjust.Enabled = false;  
         }  
 
         private void winformsMap1_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(winformsMap1.CurrentExtent, new ScreenPointF(e.X, e.Y), winformsMap1.Width, winformsMap1.Height);  
 
             //Displays world coordinates.  
             statusStrip1.Items["toolStripStatusLabelWorld"].Text = "(world) X:" + Math.Round(pointShape.X, 4) + " Y:" + Math.Round(pointShape.Y, 4);  
         }  
 
         private void btnClose_Click(object sender, EventArgs e)  
         {  
             this.Close();  
         }  
 
     }  
 }  
 
source_code_desktopeditionsample_sphericalmercatorprojectionadjustment_cs_110514.zip.txt · Last modified: 2015/09/08 06:07 by admin