User Tools

Site Tools


source_code_serviceseditionsample_projectiondistortion_cs_100916.zip

Source Code ServicesEditionSample ProjectionDistortion CS 100916.zip

Program.cs

 using System;  
 using System.Collections.Generic;  
 using System.Linq;  
 using System.Windows.Forms;  
 
 namespace ProjectionDistortion  
 {  
     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 ProjectionDistortion  
 {  
     public partial class TestForm : Form  
     {  
         private MapEngine mapEngine = new MapEngine();  
         private Bitmap bitmap = null;  
 
         private MapEngine mapEngine2 = new MapEngine();  
         private Bitmap bitmap2 = null;  
 
         private MapEngine mapEngine3 = new MapEngine();  
         private Bitmap bitmap3 = null;  
 
         private MapEngine mapEngine4 = new MapEngine();  
         private Bitmap bitmap4 = null;  
 
         public TestForm()  
         {  
             InitializeComponent();  
         }  
 
         private void TestForm_Load(object sender, EventArgs e)  
         {  
             //Sets the zoom levels and styles for countries layer.  
             ShapeFileFeatureLayer shapefileFeatureLayer = new ShapeFileFeatureLayer(@"../../data/Countries.shp");  
             shapefileFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;  
             shapefileFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
 
             //Gets a grid of multipointShapes fitting a specified rectangle  
             MultipointShape multiPointShape = GetGridFromRectangle(new RectangleShape(-125, 51, -67, 22),15);  
 
             InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer();  
             inMemoryFeatureLayer.InternalFeatures.Add(new Feature(multiPointShape));  
             inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimplePointStyle(PointSymbolType.Circle, GeoColor.SimpleColors.Red, 3);  
             inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
 
             //Sets the Geodetic Map  
             //For more info on Geodetic: http://en.wikipedia.org/wiki/Geodetic_system  
             LoadMapWithProjection(mapEngine, bitmap, Map, GeographyUnit.DecimalDegree, null, shapefileFeatureLayer, inMemoryFeatureLayer);  
 
             //Sets the Mollweide map  
             //For more info on Mollweide: http://en.wikipedia.org/wiki/Mollweide_projection  
             ManagedProj4Projection projMollweide = new ManagedProj4Projection();  
             projMollweide.InternalProjectionParametersString = ManagedProj4Projection.GetEpsgParametersString(4326);  
             projMollweide.ExternalProjectionParametersString = ManagedProj4Projection.GetEsriParametersString(54009);  
 
             LoadMapWithProjection(mapEngine2, bitmap2, Map2, GeographyUnit.Meter, projMollweide, shapefileFeatureLayer, inMemoryFeatureLayer);  
 
 
             //Sets the Spherical Mercator map (used for Google Map, Bing map, etc)  
             //For more info on Spherical Mercator: http://en.wikipedia.org/wiki/Mercator_projection  
 
             ManagedProj4Projection projSphericalMercator = new ManagedProj4Projection();  
             projSphericalMercator.InternalProjectionParametersString = ManagedProj4Projection.GetEpsgParametersString(4326);  
             projSphericalMercator.ExternalProjectionParametersString = ManagedProj4Projection.GetGoogleMapParametersString();  
 
             LoadMapWithProjection(mapEngine3, bitmap3, Map3, GeographyUnit.Meter, projSphericalMercator, shapefileFeatureLayer, inMemoryFeatureLayer);  
 
             //Sets the Lambert Azimuthal Equal Area map  
             //For more info on Lambert Azimuthal Equal Area: http://en.wikipedia.org/wiki/Lambert_azimuthal_equal-area_projection  
             ManagedProj4Projection projPlateCarre = new ManagedProj4Projection();  
             projPlateCarre.InternalProjectionParametersString = ManagedProj4Projection.GetEpsgParametersString(4326);  
             projPlateCarre.ExternalProjectionParametersString = ManagedProj4Projection.GetEpsgParametersString(2163);  
 
             LoadMapWithProjection(mapEngine4, bitmap4, Map4, GeographyUnit.Meter, projPlateCarre, shapefileFeatureLayer, inMemoryFeatureLayer);  
 
         }  
 
         private void LoadMapWithProjection(MapEngine mapEngine,Bitmap bitmap, PictureBox Map, GeographyUnit geographyUnit, ManagedProj4Projection proj, ShapeFileFeatureLayer shapefileFeatureLayer, InMemoryFeatureLayer inMemoryFeatureLayer)  
         {  
             shapefileFeatureLayer.FeatureSource.Projection = proj;  
 
             mapEngine.StaticLayers.Add(shapefileFeatureLayer);  
 
             inMemoryFeatureLayer.FeatureSource.Projection = proj;  
 
             mapEngine.DynamicLayers.Add(inMemoryFeatureLayer);  
 
             // Set the extent and the background color  
             shapefileFeatureLayer.Open();  
             mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(shapefileFeatureLayer.GetBoundingBox(), Map.Width, Map.Height);  
             shapefileFeatureLayer.Close();  
             mapEngine.BackgroundFillBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);  
 
             DrawImage(bitmap, Map, mapEngine, geographyUnit);  
         }  
 
         private MultipointShape GetGridFromRectangle(RectangleShape rectangleShape, int pointCountBySide)  
         {  
             MultipointShape multiPointShape = new MultipointShape();  
 
             //Determines the longest side.  
             double maxSide;  
             if (rectangleShape.Width > rectangleShape.Height) { maxSide = rectangleShape.Width; }  
             else  
             { maxSide = rectangleShape.Height; }  
 
             //Calculates the interval based on the point count and the longest side.  
             double interval = maxSide / pointCountBySide;  
 
             //Builds the grid from west to east in the outer loop and from north to south in the inner loop.  
             double x = rectangleShape.UpperLeftPoint.X;  
             while (x < rectangleShape.UpperRightPoint.X)  
             {  
                 double y = rectangleShape.UpperLeftPoint.Y;  
                 while (y > rectangleShape.LowerLeftPoint.Y)  
                 {  
                     multiPointShape.Points.Add(new PointShape(x, y));  
                     y = y - interval;  
                 }  
                 x = x + interval;  
             }  
 
             return multiPointShape;  
         }  
 
         private void DrawImage(Bitmap bitmap, PictureBox Map, MapEngine mapEngine, GeographyUnit geographyUnit)  
         {  
             if (bitmap != null) { bitmap.Dispose(); }  
             bitmap = new Bitmap(Map.Width, Map.Height);  
             mapEngine.OpenAllLayers();  
             mapEngine.DrawStaticLayers(bitmap, geographyUnit);  
             mapEngine.DrawDynamicLayers(bitmap, geographyUnit);  
             mapEngine.CloseAllLayers();  
 
             Map.Image = bitmap;  
         }  
 
         private void btnClose_Click(object sender, EventArgs e)  
         {  
             this.Close();  
         }  
     }  
 }  
 
source_code_serviceseditionsample_projectiondistortion_cs_100916.zip.txt · Last modified: 2015/09/08 06:06 by admin