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 MultipleShapeFileFeatureSource { 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 MultipleShapeFileFeatureSource { 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 extent and the background color mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-75.7,47.87,-63.7,41.02), Map.Width, Map.Height); mapEngine.BackgroundFillBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean); //Displays the World Map Kit as a background. ThinkGeo.MapSuite.Core.WorldMapKitLayer worldMapKitLayer = new ThinkGeo.MapSuite.Core.WorldMapKitLayer(); mapEngine.StaticLayers.Add(worldMapKitLayer); DrawImage(); } //Here we are creating a Layer for each shapefile building a separate spatial index for each. //The same ClassBreakStyle can be used for all the layers but you can see how a lot of code has to be repeated //to add the ClassBreakStyle to each layer. //You can see how in this case it makes more sense to use a multi index. private void DisplayWithRegularIndex() { mapEngine.StaticLayers.Clear(); //Displays the World Map Kit as a background. ThinkGeo.MapSuite.Core.WorldMapKitLayer worldMapKitLayer = new ThinkGeo.MapSuite.Core.WorldMapKitLayer(); mapEngine.StaticLayers.Add(worldMapKitLayer); // ClassBreakStyle classBreakStyle = new ClassBreakStyle("POP1990"); GeoPen geoPen = new GeoPen(GeoColor.StandardColors.Black, 1); classBreakStyle.ClassBreaks.Add(new ClassBreak(double.MinValue, new AreaStyle(geoPen, new GeoSolidBrush(GeoColor.FromArgb(200, 185, 255, 185))))); classBreakStyle.ClassBreaks.Add(new ClassBreak(5000, new AreaStyle(geoPen, new GeoSolidBrush(GeoColor.FromArgb(200, 81, 255, 81))))); classBreakStyle.ClassBreaks.Add(new ClassBreak(15000, new AreaStyle(geoPen, new GeoSolidBrush(GeoColor.FromArgb(200, 0, 204, 0))))); classBreakStyle.ClassBreaks.Add(new ClassBreak(100000, new AreaStyle(geoPen, new GeoSolidBrush(GeoColor.FromArgb(200, 0, 98, 0))))); classBreakStyle.ClassBreaks.Add(new ClassBreak(500000, new AreaStyle(geoPen, new GeoSolidBrush(GeoColor.FromArgb(200, 0, 39, 0))))); ShapeFileFeatureLayer Layer1 = new ShapeFileFeatureLayer(@"..\..\Data\mi_counties.shp"); ShapeFileFeatureLayer.BuildIndexFile(@"..\..\Data\mi_counties.shp", BuildIndexMode.DoNotRebuild); Layer1.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; Layer1.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(classBreakStyle); mapEngine.StaticLayers.Add("Maine Counties", Layer1); ShapeFileFeatureLayer Layer2 = new ShapeFileFeatureLayer(@"..\..\Data\nh_counties.shp"); ShapeFileFeatureLayer.BuildIndexFile(@"..\..\Data\nh_counties.shp", BuildIndexMode.DoNotRebuild); Layer2.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; Layer2.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(classBreakStyle); mapEngine.StaticLayers.Add("New Hampshire Counties", Layer2); ShapeFileFeatureLayer Layer3 = new ShapeFileFeatureLayer(@"..\..\Data\vm_counties.shp"); ShapeFileFeatureLayer.BuildIndexFile(@"..\..\Data\vm_counties.shp", BuildIndexMode.DoNotRebuild); Layer3.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; Layer3.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(classBreakStyle); mapEngine.StaticLayers.Add("Vermont Counties", Layer3); ShapeFileFeatureLayer Layer4 = new ShapeFileFeatureLayer(@"..\..\Data\ma_counties.shp"); ShapeFileFeatureLayer.BuildIndexFile(@"..\..\Data\ma_counties.shp", BuildIndexMode.DoNotRebuild); Layer4.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; Layer4.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(classBreakStyle); mapEngine.StaticLayers.Add("Massachusetts Counties", Layer4); ShapeFileFeatureLayer Layer5 = new ShapeFileFeatureLayer(@"..\..\Data\ri_counties.shp"); ShapeFileFeatureLayer.BuildIndexFile(@"..\..\Data\ri_counties.shp", BuildIndexMode.DoNotRebuild); Layer5.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; Layer5.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(classBreakStyle); mapEngine.StaticLayers.Add("Rhode Island Counties", Layer5); ShapeFileFeatureLayer Layer6 = new ShapeFileFeatureLayer(@"..\..\Data\ct_counties.shp"); ShapeFileFeatureLayer.BuildIndexFile(@"..\..\Data\ct_counties.shp", BuildIndexMode.DoNotRebuild); Layer6.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; Layer6.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(classBreakStyle); mapEngine.StaticLayers.Add("Connecticut Counties", Layer6); DrawImage(); } //Here we create a Multi Layer from several shapefiles with the same structure in the same folder having the same naming pattern. private void DisplayWithMultipleIndex() { mapEngine.StaticLayers.Clear(); //Displays the World Map Kit as a background. ThinkGeo.MapSuite.Core.WorldMapKitLayer worldMapKitLayer = new ThinkGeo.MapSuite.Core.WorldMapKitLayer(); mapEngine.StaticLayers.Add(worldMapKitLayer); //This represent the same structure shapefiles in the folder: ct_counties.shp, mi_counties.shp etc. string countyShapeFilePatten = @"..\..\Data\??" + "_counties.shp"; //Multi spatial index. string countyIndexFilePatten = @"..\..\Data\" + "northeast_counties.midx"; //Builds the multi index and the MultipleShapeFileFeatureLayer. MultipleShapeFileFeatureLayer.BuildIndex(countyShapeFilePatten, countyIndexFilePatten, BuildIndexMode.DoNotRebuild); MultipleShapeFileFeatureLayer multiLayer = new MultipleShapeFileFeatureLayer(countyShapeFilePatten, countyIndexFilePatten); ClassBreakStyle classBreakStyle = new ClassBreakStyle("POP1990"); GeoPen geoPen = new GeoPen(GeoColor.StandardColors.Black, 1); classBreakStyle.ClassBreaks.Add(new ClassBreak(double.MinValue, new AreaStyle(geoPen, new GeoSolidBrush(GeoColor.FromArgb(200, 185, 255, 185))))); classBreakStyle.ClassBreaks.Add(new ClassBreak(5000, new AreaStyle(geoPen, new GeoSolidBrush(GeoColor.FromArgb(200, 81, 255, 81))))); classBreakStyle.ClassBreaks.Add(new ClassBreak(15000, new AreaStyle(geoPen, new GeoSolidBrush(GeoColor.FromArgb(200, 0, 204, 0))))); classBreakStyle.ClassBreaks.Add(new ClassBreak(100000, new AreaStyle(geoPen, new GeoSolidBrush(GeoColor.FromArgb(200, 0, 98, 0))))); classBreakStyle.ClassBreaks.Add(new ClassBreak(500000, new AreaStyle(geoPen, new GeoSolidBrush(GeoColor.FromArgb(200, 0, 39, 0))))); multiLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; multiLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(classBreakStyle); mapEngine.StaticLayers.Add("North East Counties", multiLayer); DrawImage(); } //Here we create a multi layer based on an array of shapefiles. This is usefull, if you don't want to use all the shapefiles in the folder //or if their naming does not always follow the same pattern. private void DisplaySelectedWithMultipleIndex() { mapEngine.StaticLayers.Clear(); //Displays the World Map Kit as a background. ThinkGeo.MapSuite.Core.WorldMapKitLayer worldMapKitLayer = new ThinkGeo.MapSuite.Core.WorldMapKitLayer(); mapEngine.StaticLayers.Add(worldMapKitLayer); string[] shapeFiles = new string[] { @"..\..\Data\ct_counties.shp", @"..\..\Data\ri_counties.shp", @"..\..\Data\ma_counties.shp", @"..\..\Data\vm_counties.shp" }; string[] indexFiles = new string[] { @"..\..\Data\ct_counties.midx", @"..\..\Data\ri_counties.midx", @"..\..\Data\ma_counties.midx", @"..\..\Data\vm_counties.midx" }; MultipleShapeFileFeatureLayer.BuildIndex(shapeFiles, indexFiles, BuildIndexMode.DoNotRebuild); MultipleShapeFileFeatureLayer multiLayer = new MultipleShapeFileFeatureLayer(shapeFiles, indexFiles); ClassBreakStyle classBreakStyle = new ClassBreakStyle("POP1990"); GeoPen geoPen = new GeoPen(GeoColor.StandardColors.Black, 1); classBreakStyle.ClassBreaks.Add(new ClassBreak(double.MinValue, new AreaStyle(geoPen, new GeoSolidBrush(GeoColor.FromArgb(200, 185, 255, 185))))); classBreakStyle.ClassBreaks.Add(new ClassBreak(5000, new AreaStyle(geoPen, new GeoSolidBrush(GeoColor.FromArgb(200, 81, 255, 81))))); classBreakStyle.ClassBreaks.Add(new ClassBreak(15000, new AreaStyle(geoPen, new GeoSolidBrush(GeoColor.FromArgb(200, 0, 204, 0))))); classBreakStyle.ClassBreaks.Add(new ClassBreak(100000, new AreaStyle(geoPen, new GeoSolidBrush(GeoColor.FromArgb(200, 0, 98, 0))))); classBreakStyle.ClassBreaks.Add(new ClassBreak(500000, new AreaStyle(geoPen, new GeoSolidBrush(GeoColor.FromArgb(200, 0, 39, 0))))); multiLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; multiLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(classBreakStyle); mapEngine.StaticLayers.Add("North East Counties", multiLayer); DrawImage(); } private void btnRegular_Click(object sender, EventArgs e) { DisplayWithRegularIndex(); } private void btnMultiple_Click(object sender, EventArgs e) { DisplayWithMultipleIndex(); } private void button1_Click(object sender, EventArgs e) { DisplaySelectedWithMultipleIndex(); } 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); } } }