====== Source Code ServicesEditionSample BuildCustomShapefileIndexes CS 100120.zip ====== ====Program.cs==== using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace BuildCustomIndexes { 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 BuildCustomIndexes { public partial class TestForm : Form { private MapEngine mapEngine = new MapEngine(); private Bitmap bitmap = null; public TestForm() { InitializeComponent(); } private void TestForm_Load(object sender, EventArgs e) { // Set the current extent and the background color. mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-97.7064075692848, 30.3432859644701, -97.6936334963502, 30.3358631923594), Map.Width, Map.Height); mapEngine.BackgroundFillBrush = new GeoSolidBrush(GeoColor.StandardColors.LightGray); // Build the first index that selects local roads by their CFCC column using the regex matching expression. ShapeFileFeatureLayer.BuildIndexFile(@"..\..\Data\Austinstreets.shp", @"..\..\Data\LocalRoad.idx", "CFCC", "A[4-9][0-9]", BuildIndexMode.DoNotRebuild); // Build another index that selects highways by their CFCC column using the regex matching expression. ShapeFileFeatureLayer.BuildIndexFile(@"..\..\Data\Austinstreets.shp", @"..\..\Data\Highway.idx", "CFCC", "A[1-3][0-9]", BuildIndexMode.DoNotRebuild); // Here we load the streets shapefile but we specify the local roads index. // Even though the roads shapefile has highways in them by specifying the local roads index it will // make it seem like the highways are gone. ShapeFileFeatureLayer localRoadLayer = new ShapeFileFeatureLayer(@"..\..\Data\Austinstreets.shp", @"..\..\Data\LocalRoad.idx"); localRoadLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.LocalRoad1; localRoadLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; mapEngine.StaticLayers.Add("LocalRoadLayer", localRoadLayer); // Here we load the same streets shapefile but we specify the highways index. ShapeFileFeatureLayer highwayLayer = new ShapeFileFeatureLayer(@"..\..\Data\Austinstreets.shp", @"..\..\Data\Highway.idx"); highwayLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.Highway1; highwayLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; mapEngine.StaticLayers.Add("HighwayLayer", highwayLayer); // Draw the map image on the screen. DrawImage(); } 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.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(); } 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); } } }