ThinkGeo Cloud
ThinkGeo UI Controls
ThinkGeo Open Source
Help and Support
External Resources
ThinkGeo Cloud
ThinkGeo UI Controls
ThinkGeo Open Source
Help and Support
External Resources
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace SaveToProjection { 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()); } } }
using System; using System.Collections.ObjectModel; using System.Drawing; using System.Windows.Forms; using ThinkGeo.MapSuite.Core; namespace SaveToProjection { public partial class TestForm : Form { private MapEngine WGS84_mapEngine = new MapEngine(); private MapEngine albers_mapEngine = new MapEngine(); private Bitmap bitmap1 = null; private Bitmap bitmap2 = null; public TestForm() { InitializeComponent(); } private void btnSaveToProjection_Click(object sender, EventArgs e) { //Map in WGS84 (deciaml degrees). // Set the extent and the background color WGS84_mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-144.39,77.28,-53.58,5.39), WGS84_Map.Width, WGS84_Map.Height); WGS84_mapEngine.BackgroundFillBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean); //Uses the WorldMapKit as a bacground. WorldMapKitLayer worldMapKitLayer = new WorldMapKitLayer(); WGS84_mapEngine.StaticLayers.Add(worldMapKitLayer); //Projection class to go from regional Albers projection to WGS84. Proj4Projection AlbersToWGS84_Projection = new Proj4Projection(); AlbersToWGS84_Projection.InternalProjectionParametersString = Proj4Projection.GetEsriParametersString(102008); //North America Albers Equal Area Conic AlbersToWGS84_Projection.ExternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326); //WGS84 //Creates a new shapefile in WGS84 from the existing shapefile in Albers projection. ShapeFileFeatureLayer.SaveToProjection(@"..\..\Data\albers_northamerica.shp", @"..\..\Data\wgs84_northamerica.shp", AlbersToWGS84_Projection, OverwriteMode.Overwrite); ShapeFileFeatureLayer wgs84Layer = new ShapeFileFeatureLayer(@"..\..\Data\wgs84_northamerica.shp"); wgs84Layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(75, GeoColor.StandardColors.Green), GeoColor.StandardColors.Black,1); wgs84Layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; WGS84_mapEngine.StaticLayers.Add(wgs84Layer); DrawImage2(); } private void TestForm_Load(object sender, EventArgs e) { //Map in Albers projection // Set the extent and the background color albers_mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-5681302,5499813,4379940,-4183019), Albers_Map.Width, Albers_Map.Height); albers_mapEngine.BackgroundFillBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean); ShapeFileFeatureLayer albersLayer = new ShapeFileFeatureLayer(@"..\..\Data\albers_northamerica.shp"); albersLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(75, GeoColor.StandardColors.Green), GeoColor.StandardColors.Black, 1); albersLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; albers_mapEngine.StaticLayers.Add("NorthAmerica", albersLayer); DrawImage1(); } private void DrawImage1() { if (bitmap1 != null) { bitmap1.Dispose(); } bitmap1 = new Bitmap(Albers_Map.Width, Albers_Map.Height); albers_mapEngine.OpenAllLayers(); albers_mapEngine.DrawStaticLayers(bitmap1, GeographyUnit.Meter); albers_mapEngine.CloseAllLayers(); Albers_Map.Image = bitmap1; } private void DrawImage2() { if (bitmap2 != null) { bitmap2.Dispose(); } bitmap2 = new Bitmap(WGS84_Map.Width, WGS84_Map.Height); WGS84_mapEngine.OpenAllLayers(); WGS84_mapEngine.DrawStaticLayers(bitmap2, GeographyUnit.DecimalDegree); WGS84_mapEngine.DrawDynamicLayers(bitmap2, GeographyUnit.DecimalDegree); WGS84_mapEngine.CloseAllLayers(); WGS84_Map.Image = bitmap2; } private void Lambert_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(albers_mapEngine.CurrentExtent, new ScreenPointF(e.X, e.Y), Albers_Map.Width, Albers_Map.Height); //Displays world coordinates. statusStrip1.Items["toolStripStatusLabelWorld"].Text = "(world) X:" + Math.Round(pointShape.X, 4) + " Y:" + Math.Round(pointShape.Y, 4); } private void WGS84_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(WGS84_mapEngine.CurrentExtent, new ScreenPointF(e.X, e.Y), WGS84_Map.Width, WGS84_Map.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(); } } }