====== Source Code ServicesEditionSample DynamicSegmentation CS 090807.zip ====== ====Program.cs==== using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace DynamicSegmentation { 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.IO; using System.Drawing; using System.Windows.Forms; using ThinkGeo.MapSuite.Core; using System.Collections.ObjectModel; namespace DynamicSegmentation { public partial class TestForm : Form { private MapEngine mapEngine = new MapEngine(); private Bitmap bitmap = null; InMemoryFeatureLayer segmentInMemoryFeatureLayer = 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(0, 10, 10, 0), Map.Width, Map.Height); mapEngine.BackgroundFillBrush = new GeoSolidBrush(GeoColor.StandardColors.White); // Reads WKT from files and creates MultiLineShape from WKT (Well Known Text). StreamReader SR = File.OpenText(@"..\..\Data\MultiLineShape_WKT.txt"); string S; S = SR.ReadLine(); MultilineShape multiLineShape = new MultilineShape(S); //Add the dynamic layer with the full line as MultiLineShape to the MapEngine. InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer(); Feature feature = new Feature(multiLineShape); inMemoryFeatureLayer.InternalFeatures.Add("fullLine", feature); inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.Interstate3; inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; mapEngine.DynamicLayers.Add(inMemoryFeatureLayer); //Shows the total length of the full line. lblTotalLength.Text = "The total length of the line is " + Math.Round(multiLineShape.GetLength(GeographyUnit.Meter,DistanceUnit.Meter),2) + " meters"; //Add the dynamic layer for the line segment that will be used for the result of the dynamic segmentation. segmentInMemoryFeatureLayer = new InMemoryFeatureLayer(); mapEngine.DynamicLayers.Add("segmentLayer",segmentInMemoryFeatureLayer); //Add the dynamic layer for the start vertex of the full line. PointShape startPointShape = new PointShape(multiLineShape.Lines[0].Vertices[0]); InMemoryFeatureLayer vertexInMemoryFeatureLayer = new InMemoryFeatureLayer(); Feature startFeature = new Feature(startPointShape); vertexInMemoryFeatureLayer.InternalFeatures.Add("vertexFeatures", startFeature); vertexInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.CreateSimpleTriangleStyle(GeoColor.SimpleColors.Red, 10); vertexInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; mapEngine.DynamicLayers.Add(vertexInMemoryFeatureLayer); DrawImage(); } private void btnFind_Click(object sender, EventArgs e) { //Get the line segment from start distance and length and display the result in dynamic layer. double startDistance = Convert.ToDouble(txtBoxDistanceFromStart.Text); double Distance = Convert.ToDouble(txtBoxSegmentLength.Text); InMemoryFeatureLayer inMemoryFeatureLayer = (InMemoryFeatureLayer)mapEngine.DynamicLayers[0]; MultilineShape multiLineShape = (MultilineShape)inMemoryFeatureLayer.InternalFeatures[0].GetShape(); //Call GetLineOnLine passing the starting vertex, the start distance, the distance length, the map unit and the returning unit. MultilineShape segmentMultiLineShape = (MultilineShape)multiLineShape.GetLineOnALine(StartingPoint.FirstPoint, startDistance, Distance, GeographyUnit.Meter, DistanceUnit.Meter); //Make sure to clear any previous result. segmentInMemoryFeatureLayer.InternalFeatures.Clear(); //Get the feature for GetLineOnLine method to put in the InMemoryFeatureLayer for displaying in yellow. Feature segmentFeature = new Feature(segmentMultiLineShape); segmentInMemoryFeatureLayer.InternalFeatures.Add("segmentFeature", segmentFeature); segmentInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.SimpleColors.Yellow, 4, true); segmentInMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; DrawImage(); } private void DrawImage() { if (bitmap != null) { bitmap.Dispose(); } bitmap = new Bitmap(Map.Width, Map.Height); mapEngine.OpenAllLayers(); mapEngine.DrawDynamicLayers(bitmap, GeographyUnit.Meter); 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(); } } }