====== Source Code ServicesEditionSample GeodeticToStatePlane CS 091224.zip ====== ====Program.cs==== using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace GeodeticToStatePlane { static class Program { /// /// The main entry point for the application. /// [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 GeodeticToStatePlane { public partial class TestForm : Form { private MapEngine mapEngine = new MapEngine(); private MapEngine mapEngine2 = new MapEngine(); private Bitmap bitmap = null; private Bitmap bitmap2 = null; public TestForm() { InitializeComponent(); } private void TestForm_Load(object sender, EventArgs e) { // Sets the map in Decimal Degrees (Geodetic) mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-125.77,50.32,-67.71,23.23), Map.Width, Map.Height); mapEngine.BackgroundFillBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean); ShapeFileFeatureLayer CountriesLayer = new ShapeFileFeatureLayer(@"..\..\Data\countries02.shp"); CountriesLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1; CountriesLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; //Layer of the State Plane zones. ShapeFileFeatureLayer SPZLayer = new ShapeFileFeatureLayer(@"..\..\Data\stateplanezones.shp"); SPZLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.County2; SPZLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; ShapeFileFeatureLayer SPZlabelLayer = new ShapeFileFeatureLayer(@"..\..\Data\stateplanezones.shp"); SPZlabelLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = TextStyles.County2("SPC83"); SPZlabelLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; mapEngine.StaticLayers.Add("CountriesLayer", CountriesLayer); mapEngine.StaticLayers.Add("StatePlaneZonesLayer", SPZLayer); mapEngine.StaticLayers.Add("StatePlaneZonesLabelLayer", SPZlabelLayer); //Layer of street. (will be saved in State Plane) ShapeFileFeatureLayer streetLayer = new ShapeFileFeatureLayer(@"..\..\Data\Austinstreets.shp"); streetLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.Red, 2, false); streetLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; //Red circle to indicate location of the street layer on the map. InMemoryFeatureLayer circle = new InMemoryFeatureLayer(); circle.InternalFeatures.Add(new Feature(new Vertex(-97.7366, 30.2935))); circle.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.PointType = PointType.Symbol; circle.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimpleCircleStyle(GeoColor.StandardColors.Transparent, 12, GeoColor.StandardColors.Red, 1); circle.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; mapEngine.DynamicLayers.Add(circle); mapEngine.StaticLayers.Add("AustinStreets", streetLayer); ScaleBarAdornmentLayer scaleBar = new ScaleBarAdornmentLayer(); scaleBar.UnitFamily = UnitSystem.Metric; scaleBar.Location = AdornmentLocation.LowerLeft; mapEngine.AdornmentLayers.Add(scaleBar); DrawImage(); //Sets the map in meters (State Plane Central Texas zone 4203) mapEngine2.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(948121,3074033,951141,3071280), Map.Width, Map.Height); mapEngine2.BackgroundFillBrush = new GeoSolidBrush(GeoColor.StandardColors.LightGray); ShapeFileFeatureLayer TravisLayer = new ShapeFileFeatureLayer(@"..\..\Data\travis_sp.shp"); TravisLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.County2; TravisLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; mapEngine2.StaticLayers.Add("TravisLayer", TravisLayer); ScaleBarAdornmentLayer scaleBar2 = new ScaleBarAdornmentLayer(); scaleBar2.UnitFamily = UnitSystem.Metric; scaleBar2.Location = AdornmentLocation.LowerLeft; mapEngine2.AdornmentLayers.Add(scaleBar2); DrawImage2(); } //This function looks at what State Plane zone the street layer belongs to (using spatial query)and creates a new layer projected to //that State Plane zone. private void ProjectLayerToStatePlane() { ShapeFileFeatureLayer layerToProject = (ShapeFileFeatureLayer)mapEngine.StaticLayers["AustinStreets"]; ShapeFileFeatureLayer statePlaneLayer = (ShapeFileFeatureLayer)mapEngine.StaticLayers["StatePlaneZonesLayer"]; layerToProject.Open(); statePlaneLayer.Open(); //Determines the zone the street layer belongs to based on the center point of the layer. PointShape centerPointShape = layerToProject.GetBoundingBox().GetCenterPoint(); Collection statePlaneZones = statePlaneLayer.QueryTools.GetFeaturesContaining(centerPointShape, ReturningColumnsType.AllColumns); if (statePlaneZones.Count > 0) { //Gets the State Plane zone. int EPSG = System.Convert.ToInt32(statePlaneZones[0].ColumnValues["MIN_EPSG83"]); //Projection class to go from Geodetic projection to State Plane. Proj4Projection GeoToStatePlane_Projection = new Proj4Projection(); GeoToStatePlane_Projection.InternalProjectionParametersString = Proj4Projection.GetEsriParametersString(4326); //WGS84 (Geodetic) GeoToStatePlane_Projection.ExternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(EPSG); //State Plane //Creates a new shapefile in WGS84 from the existing shapefile in Albers projection. string outputLayer = layerToProject.ShapePathFileName.Substring(0, layerToProject.ShapePathFileName.Length - 4) + "_sp.shp"; ShapeFileFeatureLayer.SaveToProjection(layerToProject.ShapePathFileName, outputLayer, GeoToStatePlane_Projection, OverwriteMode.Overwrite); ShapeFileFeatureLayer streetLayer_sp = new ShapeFileFeatureLayer(outputLayer); streetLayer_sp.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.StandardColors.Red, 2, false); streetLayer_sp.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; mapEngine2.StaticLayers.Add("TravisLayer_SP", streetLayer_sp); DrawImage2(); } layerToProject.Close(); layerToProject.Close(); } private void btnProject_Click(object sender, EventArgs e) { ProjectLayerToStatePlane(); } 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 DrawImage2() { if (bitmap2 != null) { bitmap2.Dispose(); } bitmap2 = new Bitmap(Map2.Width, Map2.Height); mapEngine2.OpenAllLayers(); mapEngine2.DrawStaticLayers(bitmap2, GeographyUnit.Meter); mapEngine2.DrawDynamicLayers(bitmap2, GeographyUnit.Meter); mapEngine2.DrawAdornmentLayers(bitmap2, GeographyUnit.Meter); mapEngine2.CloseAllLayers(); Map2.Image = bitmap2; } 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); } private void Map2_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(mapEngine2.CurrentExtent, new ScreenPointF(e.X, e.Y), Map2.Width, Map2.Height); //Displays world coordinates. statusStrip1.Items["toolStripStatusLabelWorld"].Text = "(world) X:" + Math.Round(pointShape.X, 2) + " Y:" + Math.Round(pointShape.Y, 2); } } }