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; using ThinkGeo.MapSuite.Core; namespace ChemicalPlume { 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 ChemicalPlume { public partial class TestForm : Form { private MapEngine mapEngine = new MapEngine(); private Bitmap bitmap = null; ShapeFileFeatureLayer streetLayer = null; PointShape centerPointShape = null; PolygonShape polygonShape = null; float degreeAngle = 0; public TestForm() { InitializeComponent(); } private void TestForm_Load(object sender, EventArgs e) { // Set the extent and the background color mapEngine.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-116.3409,43.6440,-116.2987,43.6121), 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); // Adds the street layer for the spatial analysis from the World Map Kit to the MapEngine. //Notice that this layer is not displayed and is used only for spatial query. //For this project, we are using a subset of the street data available in our USA street data product. //http://gis.thinkgeo.com/Products/StandaloneMapDataIconLibraries/USAData/tabid/184/Default.aspx. streetLayer = new ShapeFileFeatureLayer(@"..\..\Data\streets.shp", ShapeFileReadWriteMode.ReadOnly); //streetLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.LocalRoad4; //streetLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; mapEngine.StaticLayers.Add("StreetLayer", streetLayer); //Add the dynamic layers to the MapEngine. //We are using an example from ERG (Emergency Response Guide)from the US department of Transportation. We take the example of a small spill of phosgene //chemical during the day (300 ft of radius of isolation zone and and area of 0.4 miles of width for the protection zone). //See the website for more info: http://www.phmsa.dot.gov/ InMemoryFeatureLayer IsolationLayer = new InMemoryFeatureLayer(); InMemoryFeatureLayer ProtectionLayer = new InMemoryFeatureLayer(); IsolationLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateHatchStyle(GeoHatchStyle.Percent20, GeoColor.StandardColors.Orange, GeoColor.FromArgb(100, GeoColor.StandardColors.Yellow)); IsolationLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; //Location of the source of the chemical release. centerPointShape = new PointShape(-116.3188,43.6286); //Builds the Isolation zone. Circle of 300 feet of radius from the source. double LongDiff1 = DecimalDegreesHelper.GetLongitudeDifferenceFromDistance(300, DistanceUnit.Feet, 30.2996); EllipseShape ellipseShape = new EllipseShape(centerPointShape, LongDiff1); Feature isolationFeature = new Feature(ellipseShape); IsolationLayer.InternalFeatures.Add("Isolation", isolationFeature); mapEngine.DynamicLayers.Add("IsolationLayer", IsolationLayer); //Builds the Protection zone. Area of 2500 feet of width. ProtectionLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateHatchStyle(GeoHatchStyle.Percent05, GeoColor.StandardColors.Orange, GeoColor.FromArgb(150, GeoColor.StandardColors.Orange)); ProtectionLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; double LongDiff2 = DecimalDegreesHelper.GetLongitudeDifferenceFromDistance(2500, DistanceUnit.Feet, 30.2996); polygonShape = new PolygonShape(); polygonShape.OuterRing.Vertices.Add(new Vertex(centerPointShape.X - (LongDiff2 / 2), centerPointShape.Y + LongDiff2)); polygonShape.OuterRing.Vertices.Add(new Vertex(centerPointShape.X + (LongDiff2 / 2), centerPointShape.Y + LongDiff2)); polygonShape.OuterRing.Vertices.Add(new Vertex(centerPointShape.X + (LongDiff2 / 2), centerPointShape.Y)); polygonShape.OuterRing.Vertices.Add(new Vertex(centerPointShape.X - (LongDiff2 / 2), centerPointShape.Y)); polygonShape.OuterRing.Vertices.Add(new Vertex(centerPointShape.X - (LongDiff2 / 2), centerPointShape.Y + LongDiff2)); Feature protectionFeature = new Feature(polygonShape); ProtectionLayer.InternalFeatures.Add("Protection", protectionFeature); mapEngine.DynamicLayers.Add("ProtectionLayer", ProtectionLayer); //Sets the InMemoryFeatureLayer for the affected streets by the chemical plume. InMemoryFeatureLayer affectedStreetsLayer = new InMemoryFeatureLayer(); affectedStreetsLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.CreateSimpleLineStyle(GeoColor.FromArgb(150,255,0,0), 6, false); affectedStreetsLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; mapEngine.DynamicLayers.Add("AffectedStreetsLayer", affectedStreetsLayer); //Gets the street features inside the chemical plume and them to the InMemoryFeatureLayer for display. Collection<Feature> features = GetAffectedFeatures(); ((InMemoryFeatureLayer)mapEngine.FindDynamicFeatureLayer("AffectedStreetsLayer")).InternalFeatures.Clear(); foreach (Feature feature in features) ((InMemoryFeatureLayer)mapEngine.FindDynamicFeatureLayer("AffectedStreetsLayer")).InternalFeatures.Add(feature); DrawImage(); } private Collection<Feature> GetAffectedFeatures() { //Gets the shapes from the Isolation and Protection zones and union them into one shape to do the spatial query in one step //on the street data. PolygonShape polygonShape = (PolygonShape)((InMemoryFeatureLayer)mapEngine.FindDynamicFeatureLayer("ProtectionLayer")).InternalFeatures["Protection"].GetShape(); PolygonShape ellipseShape = (PolygonShape)((InMemoryFeatureLayer)mapEngine.FindDynamicFeatureLayer("IsolationLayer")).InternalFeatures["Isolation"].GetShape(); MultipolygonShape unionShape = polygonShape.Union(ellipseShape); streetLayer.Open(); Collection<Feature> features = streetLayer.QueryTools.GetFeaturesIntersecting(unionShape, ReturningColumnsType.NoColumns); streetLayer.Close(); return features; } private void btnRotate_Click(object sender, EventArgs e) { //Rotates the Protection zone according to the wind direction. This changes the affected streets. PolygonShape polygonShape = (PolygonShape)((InMemoryFeatureLayer)mapEngine.FindDynamicFeatureLayer("ProtectionLayer")).InternalFeatures["Protection"].GetShape(); polygonShape.Rotate(centerPointShape, degreeAngle + 10); ((InMemoryFeatureLayer)mapEngine.FindDynamicFeatureLayer("ProtectionLayer")).InternalFeatures["Protection"] = new Feature(polygonShape); Collection<Feature> features = GetAffectedFeatures(); ((InMemoryFeatureLayer)mapEngine.FindDynamicFeatureLayer("AffectedStreetsLayer")).InternalFeatures.Clear(); foreach ( Feature feature in features) ((InMemoryFeatureLayer)mapEngine.FindDynamicFeatureLayer("AffectedStreetsLayer")).InternalFeatures.Add(feature); 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); } } }