User Tools

Site Tools


source_code_serviceseditionsample_projectioninfeet_cs_090918.zip

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
source_code_serviceseditionsample_projectioninfeet_cs_090918.zip [2015/08/20 03:08]
127.0.0.1 external edit
source_code_serviceseditionsample_projectioninfeet_cs_090918.zip [2015/09/08 06:07] (current)
admin
Line 1: Line 1:
-====== ​Source_Code_ServicesEditionSample_ProjectionInFeet_CS_090918.zip ======+====== ​Source Code ServicesEditionSample ProjectionInFeet CS 090918.zip ====== 
  
-<​noinclude>​{{article rating}}</​noinclude>​ 
 ====LambertInFeetProjection.cs==== ====LambertInFeetProjection.cs====
-^ Code ^ + 
-<source lang="csharp" line="​1"​>using System;  ​\\ using System.Collections.Generic;  ​\\ using System.Linq;  ​\\ using System.Text;  ​\\ using ThinkGeo.MapSuite.Core;  ​\\  \\ namespace ProjectionInFeet  ​\\ {  ​\\     class LambertInFeetProjection : Projection  ​\\     {  ​\\         Proj4Projection proj4Projection = new Proj4Projection();  ​\\           public LambertInFeetProjection()  ​\\             {  ​\\                 ​<​nowiki>​//</​nowiki>​Lambert projection as internal projection.  ​\\                 proj4Projection.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);  ​\\                 ​<​nowiki>​//</​nowiki>​Geodetic (Longitude/​Latitude) as external projection.  ​\\                 proj4Projection.ExternalProjectionParametersString = Proj4Projection.GetEsriParametersString(102004);  ​\\             }  ​\\  \\             protected override Vertex[[]] ConvertToExternalProjectionCore(double[[]] x, double[[]] y)  ​\\             {  ​\\                 proj4Projection.Open();  ​\\                 Vertex[[]] vertices = new Vertex[[x.Length]];  ​\\                     for (int i = 0; i < vertices.Length;​ i++)  ​\\                     {  ​\\                         ​<​nowiki>​//</​nowiki>​converts Longitude/​Latitude to Meters for Lambert.  ​\\                         vertices[[i]] = proj4Projection.ConvertToExternalProjection(x[[i]], y[[i]]);  ​\\                         ​<​nowiki>​//</​nowiki>​Then we need to convert meters to feet.  ​\\                         vertices[[i]].X = Conversion.ConvertMeasureUnits(vertices[[i]].X, DistanceUnit.Meter,​ DistanceUnit.Feet);  ​\\                         vertices[[i]].Y = Conversion.ConvertMeasureUnits(vertices[[i]].Y, DistanceUnit.Meter,​ DistanceUnit.Feet);  ​\\                     }  ​\\  \\                ​proj4Projection.Close();  ​\\                ​return vertices;  ​\\             }  ​\\  \\             protected override Vertex[[]] ConvertToInternalProjectionCore(double[[]] x, double[[]] y)  ​\\             {  ​\\                 proj4Projection.Open();  ​\\                 Vertex[[]] vertices = new Vertex[[x.Length]];  ​\\  \\                 for (int i = 0; i < vertices.Length;​ i++)  ​\\                 {  ​\\                     ​<​nowiki>​//</​nowiki>​First, we need to convert feet to meters.  ​\\                     x[[i]] = Conversion.ConvertMeasureUnits(x[[i]], DistanceUnit.Feet,​ DistanceUnit.Meter);  ​\\                     y[[i]] = Conversion.ConvertMeasureUnits(y[[i]], DistanceUnit.Feet,​ DistanceUnit.Meter);  ​\\                     ​<​nowiki>​//</​nowiki>​Then, we can convert from meters to geodetic (Longitude/​Latitude).  ​\\                     vertices[[i]] = proj4Projection.ConvertToInternalProjection(x[[i]], y[[i]]);  ​\\                 }  ​\\  \\                 proj4Projection.Close();  ​\\                 return vertices;  ​\\             }  ​\\       }  ​\\ }  ​\\ </source  |+<code csharp> using System;  ​ 
 + using System.Collections.Generic;  ​ 
 + using System.Linq;  ​ 
 + using System.Text;  ​ 
 + using ThinkGeo.MapSuite.Core;  ​ 
 +   
 + namespace ProjectionInFeet  ​ 
 + {  ​ 
 +     class LambertInFeetProjection : Projection  ​ 
 +     {  ​ 
 +         Proj4Projection proj4Projection = new Proj4Projection();  ​ 
 +           public LambertInFeetProjection()  ​ 
 +             {  ​ 
 +                 //Lambert projection as internal projection.  ​ 
 +                 proj4Projection.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);  ​ 
 +                 //Geodetic (Longitude/​Latitude) as external projection.  ​ 
 +                 proj4Projection.ExternalProjectionParametersString = Proj4Projection.GetEsriParametersString(102004);  ​ 
 +             }  ​ 
 +   
 +             protected override Vertex[] ConvertToExternalProjectionCore(double[] x, double[] y)  ​ 
 +             {  ​ 
 +                 proj4Projection.Open();  ​ 
 +                 Vertex[] vertices = new Vertex[x.Length];  ​ 
 +                     for (int i = 0; i < vertices.Length;​ i++)  ​ 
 +                     {  ​ 
 +                         //converts Longitude/​Latitude to Meters for Lambert.  ​ 
 +                         vertices[i] = proj4Projection.ConvertToExternalProjection(x[i],​ y[i]);  ​ 
 +                         //Then we need to convert meters to feet.  ​ 
 +                         vertices[i].X = Conversion.ConvertMeasureUnits(vertices[i].X,​ DistanceUnit.Meter,​ DistanceUnit.Feet);  ​ 
 +                         vertices[i].Y = Conversion.ConvertMeasureUnits(vertices[i].Y,​ DistanceUnit.Meter,​ DistanceUnit.Feet);  ​ 
 +                     }  ​ 
 +   
 +                ​proj4Projection.Close();  ​ 
 +                ​return vertices;  ​ 
 +             }  ​ 
 +   
 +             protected override Vertex[] ConvertToInternalProjectionCore(double[] x, double[] y)  ​ 
 +             {  ​ 
 +                 proj4Projection.Open();  ​ 
 +                 Vertex[] vertices = new Vertex[x.Length];  ​ 
 +   
 +                 for (int i = 0; i < vertices.Length;​ i++)  ​ 
 +                 {  ​ 
 +                     //First, we need to convert feet to meters.  ​ 
 +                     x[i] = Conversion.ConvertMeasureUnits(x[i],​ DistanceUnit.Feet,​ DistanceUnit.Meter);  ​ 
 +                     y[i] = Conversion.ConvertMeasureUnits(y[i],​ DistanceUnit.Feet,​ DistanceUnit.Meter);  ​ 
 +                     //Then, we can convert from meters to geodetic (Longitude/​Latitude).  ​ 
 +                     vertices[i] = proj4Projection.ConvertToInternalProjection(x[i],​ y[i]);  ​ 
 +                 }  ​ 
 +   
 +                 proj4Projection.Close();  ​ 
 +                 return vertices;  ​ 
 +             }  ​ 
 +       }  ​ 
 + }  ​ 
 + </code>
  
  
  
 ====Program.cs==== ====Program.cs====
-^ Code ^ 
-| <source lang="​csharp"​ line="​1">​using System; ​ \\ using System.Collections.Generic; ​ \\ using System.Linq; ​ \\ using System.Windows.Forms; ​ \\  \\ namespace ProjectionInFeet ​ \\ {  \\     ​static class Program ​ \\     ​{ ​ \\         <​nowiki>//</​nowiki>/​ <​summary> ​ \\         <​nowiki>//</​nowiki>/​ The main entry point for the application. ​ \\         <​nowiki>//</​nowiki>/​ </​summary> ​ \\         ​[[STAThread]] ​ \\         ​static void Main() ​ \\         ​{ ​ \\             ​Application.EnableVisualStyles(); ​ \\             ​Application.SetCompatibleTextRenderingDefault(false); ​ \\             ​Application.Run(new TestForm()); ​ \\         ​} ​ \\     ​} ​ \\ }  \\ </​source> ​  | 
  
 +<code csharp> using System;  ​
 + using System.Collections.Generic;  ​
 + using System.Linq;  ​
 + using System.Windows.Forms;  ​
 +  ​
 + ​namespace ProjectionInFeet  ​
 + ​{  ​
 +     ​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());  ​
 +         ​}  ​
 +     ​}  ​
 + ​}  ​
 + </​code>​
  
  
-====TestForm.cs==== 
-^ Code ^ 
-| <source lang="​csharp"​ line="​1">​using System; ​ \\ using System.Drawing; ​ \\ using System.Windows.Forms; ​ \\ using ThinkGeo.MapSuite.Core; ​ \\  \\ namespace ProjectionInFeet ​ \\ {  \\     ​public partial class TestForm : Form  \\     ​{ ​ \\         ​private MapEngine mapEngine = new MapEngine(); ​ \\         ​private Bitmap bitmap = null;  \\         ​ShapeFileFeatureLayer worldLayer = null;  \\  \\         ​public TestForm() ​ \\         ​{ ​ \\             ​InitializeComponent(); ​ \\         ​} ​ \\  \\         ​private void TestForm_Load(object sender, EventArgs e)  \\         ​{ ​ \\             <​nowiki>//</​nowiki>​ Set the full extent and the background color  \\             ​mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-7948051,​5116233,​7630384,​-5296296),​ Map.Width, Map.Height); ​ \\             ​mapEngine.BackgroundFillBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean); ​ \\  \\             <​nowiki>//</​nowiki>​ Add the static layers to the MapEngine ​ \\             ​worldLayer = new ShapeFileFeatureLayer(@"​..\..\Data\USStates_lambert.shp",​ ShapeFileReadWriteMode.ReadOnly); ​ \\             ​worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.County1; ​ \\             ​worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; ​ \\             ​mapEngine.StaticLayers.Add("​StatesLayer",​ worldLayer); ​ \\  \\  \\            <​nowiki>//</​nowiki>​Add the dynamic layer to the MapEngine ​ \\             ​InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer(); ​ \\  \\             <​nowiki>//</​nowiki>​The feature has its coordinate in Longitude/​Latitude. ​ \\             ​Feature newFeature1 = new Feature(new PointShape(-95.83,​ 39.15)); ​ \\  \\             ​inMemoryFeatureLayer.InternalFeatures.Add("​myFeature",​ newFeature1); ​ \\  \\             ​inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimpleCircleStyle(GeoColor.SimpleColors.Red,​ 10);  \\             ​inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; ​ \\  \\             <​nowiki>//</​nowiki>​Applies the projection to the InMemoryFeatureLayer. ​ \\             <​nowiki>//</​nowiki>​LambertInFeetProjection has the internal projection as Lambert (feet) and  \\             <​nowiki>//</​nowiki>​external projection as geodetic (Longitude/​Latitude). ​ \\             ​LambertInFeetProjection lambertProj = new LambertInFeetProjection(); ​ \\             ​inMemoryFeatureLayer.FeatureSource.Projection = lambertProj; ​ \\  \\             ​mapEngine.DynamicLayers.Add(inMemoryFeatureLayer); ​ \\  \\  \\             ​DrawImage(); ​ \\         ​} ​ \\  \\  \\         ​private void DrawImage() ​ \\         ​{ ​ \\             if (bitmap != null) { bitmap.Dispose();​ }  \\             ​bitmap = new Bitmap(Map.Width,​ Map.Height); ​ \\             ​mapEngine.OpenAllLayers(); ​ \\             ​mapEngine.DrawStaticLayers(bitmap,​ GeographyUnit.Feet); ​ \\             ​mapEngine.DrawDynamicLayers(bitmap,​ GeographyUnit.Feet); ​ \\             ​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(); ​ \\         ​} ​ \\     ​} ​ \\ }  \\ </​source> ​  | 
  
 +====TestForm.cs====
  
 +<code csharp> using System;  ​
 + using System.Drawing;  ​
 + using System.Windows.Forms;  ​
 + using ThinkGeo.MapSuite.Core;  ​
 +  ​
 + ​namespace ProjectionInFeet  ​
 + ​{  ​
 +     ​public partial class TestForm : Form  ​
 +     ​{  ​
 +         ​private MapEngine mapEngine = new MapEngine();  ​
 +         ​private Bitmap bitmap = null;  ​
 +         ​ShapeFileFeatureLayer worldLayer = null;  ​
 +  ​
 +         ​public TestForm()  ​
 +         ​{  ​
 +             ​InitializeComponent();  ​
 +         ​}  ​
 +  ​
 +         ​private void TestForm_Load(object sender, EventArgs e)  ​
 +         ​{  ​
 +             // Set the full extent and the background color  ​
 +             ​mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-7948051,​5116233,​7630384,​-5296296),​ Map.Width, Map.Height);  ​
 +             ​mapEngine.BackgroundFillBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);  ​
 +  ​
 +             // Add the static layers to the MapEngine  ​
 +             ​worldLayer = new ShapeFileFeatureLayer(@"​..\..\Data\USStates_lambert.shp",​ ShapeFileReadWriteMode.ReadOnly);  ​
 +             ​worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.County1;  ​
 +             ​worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  ​
 +             ​mapEngine.StaticLayers.Add("​StatesLayer",​ worldLayer);  ​
 +  ​
 +  ​
 +            //Add the dynamic layer to the MapEngine  ​
 +             ​InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer();  ​
 +  ​
 +             //The feature has its coordinate in Longitude/​Latitude.  ​
 +             ​Feature newFeature1 = new Feature(new PointShape(-95.83,​ 39.15));  ​
 +  ​
 +             ​inMemoryFeatureLayer.InternalFeatures.Add("​myFeature",​ newFeature1);  ​
 +  ​
 +             ​inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimpleCircleStyle(GeoColor.SimpleColors.Red,​ 10);  ​
 +             ​inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  ​
 +  ​
 +             //​Applies the projection to the InMemoryFeatureLayer.  ​
 +             //​LambertInFeetProjection has the internal projection as Lambert (feet) and  ​
 +             //​external projection as geodetic (Longitude/​Latitude).  ​
 +             ​LambertInFeetProjection lambertProj = new LambertInFeetProjection();  ​
 +             ​inMemoryFeatureLayer.FeatureSource.Projection = lambertProj;  ​
 +  ​
 +             ​mapEngine.DynamicLayers.Add(inMemoryFeatureLayer);  ​
 +  ​
 +  ​
 +             ​DrawImage();  ​
 +         ​}  ​
 +  ​
 +  ​
 +         ​private void DrawImage()  ​
 +         ​{  ​
 +             if (bitmap != null) { bitmap.Dispose();​ }  ​
 +             ​bitmap = new Bitmap(Map.Width,​ Map.Height);  ​
 +             ​mapEngine.OpenAllLayers();  ​
 +             ​mapEngine.DrawStaticLayers(bitmap,​ GeographyUnit.Feet);  ​
 +             ​mapEngine.DrawDynamicLayers(bitmap,​ GeographyUnit.Feet);  ​
 +             ​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();  ​
 +         ​}  ​
 +     ​}  ​
 + ​}  ​
 + </​code>​
source_code_serviceseditionsample_projectioninfeet_cs_090918.zip.1440040126.txt.gz · Last modified: 2015/09/08 06:07 (external edit)