User Tools

Site Tools


source_code_serviceseditionsample_isolines_cs_winforms_111115.zip

Source Code ServicesEditionSample Isolines CS WinForms 111115.zip

Banner.cs

 using System;  
 using System.Diagnostics;  
 using System.IO;  
 using System.Management;  
 using System.Windows.Forms;  
 
 public partial class Banner : UserControl  
 {  
     public Banner()  
     {  
         InitializeComponent();  
         SetupBannerAd();  
     }  
 
     public void SetupBannerAd()  
     {  
         if (Process.GetCurrentProcess().ProcessName != "devenv")  
         {  
             adRotator.Url = new Uri(new DirectoryInfo(@"..\..\Resources\bannerad_offline.html").FullName);  
             if (IsNetworkAlive())  
             {  
                 adsRotatorTimer.Start();  
             }  
         }  
     }  
 
     private static bool IsNetworkAlive()  
     {  
         ObjectQuery objectQuery = new ObjectQuery("select * from Win32_NetworkAdapter where NetConnectionStatus=2");  
         ManagementObjectSearcher searcher = null;  
         try  
         {  
             searcher = new ManagementObjectSearcher(objectQuery);  
 
             return (searcher.Get().Count > 0);  
         }  
         finally  
         {  
             if (searcher != null)  
             {  
                 searcher.Dispose();  
             }  
         }  
     }  
 
     private void adsRotatorTimer_Tick(object sender, EventArgs e)  
     {  
         adRotator.Navigate("http://gis.thinkgeo.com/Default.aspx?tabid=640&random=" + Guid.NewGuid().ToString());  
     }  
 }  
 

Footer.cs

 using System;  
 using System.Diagnostics;  
 using System.Windows.Forms;  
 using DisplayIsoLines.Properties;  
 
 public partial class Footer : UserControl  
 {  
     public Footer()  
     {  
         InitializeComponent();  
     }  
 
     private void btnProductInformation_Click(object sender, EventArgs e)  
     {  
         Process.Start("http://gis.thinkgeo.com/Default.aspx?tabid=674");  
     }  
 
     private void btnProductInformation_Activate(object sender, EventArgs e)  
     {  
         btnProductInformation.Image = Resources.btn_active_map_suite_products;  
     }  
 
     private void btnProductInformation_Deactivate(object sender, EventArgs e)  
     {  
         btnProductInformation.Image = Resources.btn_inactive_map_suite_products;  
     }  
 
     private void btnSupportCenter_Click(object sender, EventArgs e)  
     {  
         Process.Start("http://gis.thinkgeo.com/supportcenter");  
     }  
 
     private void btnSupportCenter_Activate(object sender, EventArgs e)  
     {  
         btnSupportCenter.Image = Resources.btn_active_support_center;  
     }  
 
     private void btnSupportCenter_Deactivate(object sender, EventArgs e)  
     {  
         btnSupportCenter.Image = Resources.btn_inactive_support_center;  
     }  
 
     private void btnDiscussForum_Click(object sender, EventArgs e)  
     {  
         Process.Start("http://gis.thinkgeo.com/Support/DiscussionForums/tabid/143/afv/topicsview/aff/21/Default.aspx");  
     }  
 
     private void btnDiscussForum_Activate(object sender, EventArgs e)  
     {  
         btnDiscussForum.Image = Resources.btn_active_discussion_forums;  
     }  
 
     private void btnDiscussForum_Deactivate(object sender, EventArgs e)  
     {  
         btnDiscussForum.Image = Resources.btn_inactive_discussion_forums;  
     }  
 
     private void btnWiki_Click(object sender, EventArgs e)  
     {  
         Process.Start("http://wiki.thinkgeo.com/wiki/Map_Suite_Desktop_Edition");  
     }  
 
     private void btnWiki_Activate(object sender, EventArgs e)  
     {  
         btnWiki.Image = Resources.btn_active_thinkgeo_wiki;  
     }  
 
     private void btnWiki_Deactivate(object sender, EventArgs e)  
     {  
         btnWiki.Image = Resources.btn_inactive_thinkgeo_wiki;  
     }  
 
     private void btnContactUs_Click(object sender, EventArgs e)  
     {  
         Process.Start("http://gis.thinkgeo.com/Default.aspx?tabid=147");  
     }  
 
     private void btnContactUs_Activate(object sender, EventArgs e)  
     {  
         btnContactUs.Image = Resources.btn_active_contact_us;  
     }  
 
     private void btnContactUs_Deactivate(object sender, EventArgs e)  
     {  
         btnContactUs.Image = Resources.btn_inactive_contact_us;  
     }  
 }  
 

Program.cs

 using System;  
 using System.Windows.Forms;  
 
 namespace SourceDisplayIsoLines  
 {  
     static class Program  
     {  
         /// <summary>  
         /// The main entry point for the application.  
         /// </summary>  
         [STAThread]  
         static void Main()  
         {  
             Application.EnableVisualStyles();  
             Application.SetCompatibleTextRenderingDefault(false);  
             Application.Run(new Sample());  
         }  
     }  
 }  
 

Sample.cs

 using System;  
 using System.Collections.Generic;  
 using System.Collections.ObjectModel;  
 using System.IO;  
 using System.Windows.Forms;  
 using ThinkGeo.MapSuite.Core;  
 using ThinkGeo.MapSuite.DesktopEdition;  
 
 public partial class Sample : Form  
 {  
     private string gridFilePath = @"..\..\Data\result.grid";  
     private string wellDepthPointDataFilePath = @"..\..\Data\GrayCountyIrrigationWellDepths.csv";  
     private Dictionary<PointShape, double> wellDepthPointData;  
 
     public Sample()  
     {  
         InitializeComponent();  
     }  
 
     private void Sample_Load(object sender, EventArgs e)  
     {  
         winformsMap1.CurrentExtent = new RectangleShape(-100.655827718567, 37.7441933095704, -100.613770681213, 37.7186586797486);  
 
         //Load the well depth points and depth data from a text file into the dictionary  
         //We cache this at the class level to prevent form loading it multiple times  
         wellDepthPointData = GetWellDepthPointDataFromCSV(wellDepthPointDataFilePath);  
 
         //This loads the background maps from ThinkGeo's World Map Kit Server.  
         WorldMapKitWmsDesktopOverlay worldMapKitOverlay = new WorldMapKitWmsDesktopOverlay();  
         winformsMap1.Overlays.Add("WorldMapKitOverlay", worldMapKitOverlay);  
 
         //Add the grid layer, the grid cells, and the well points to the map  
         LayerOverlay isoLineOverlay = new LayerOverlay();  
         winformsMap1.Overlays.Add("isoLineOverlay", isoLineOverlay);  
 
         isoLineOverlay.Layers.Add("IsoLineLayer", GetGridIsoLineLayer());  
         isoLineOverlay.Layers.Add("GridCellsLayer", GetGridFeatureLayer());  
         isoLineOverlay.Layers.Add("WellsLayer", GetWellDepthPointLayer());  
 
         winformsMap1.Refresh();  
     }  
 
     private static Dictionary<PointShape, double> GetWellDepthPointDataFromCSV(string csvFilePath)  
     {  
         StreamReader streamReader = null;  
         Dictionary<PointShape, double> wellDataPoints = new Dictionary<PointShape, double>();  
 
         try  
         {  
             streamReader = new StreamReader(csvFilePath);  
             string headline = streamReader.ReadLine();  
             while (!streamReader.EndOfStream)  
             {  
                 string line = streamReader.ReadLine();  
 
                 string[] parts = line.Split(',');  
                 wellDataPoints.Add(new PointShape(double.Parse(parts[0]), double.Parse(parts[1])), double.Parse(parts[2]));  
             }  
         }  
         finally  
         {  
             if (streamReader != null) { streamReader.Close(); }  
         }  
         return wellDataPoints;  
     }  
 
     private void CreateGridFile()  
     {  
         //Get the current extent since we use that to gerenate the grid.  Of course this is just for  
         //the demo and in the real world you can use any extent you like  
         RectangleShape currentDrawingExtent = ExtentHelper.GetDrawingExtent(winformsMap1.CurrentExtent, winformsMap1.Width, winformsMap1.Height);  
 
         //Calculate the cell size based on how many rows and columns you specified  
         double cellSize = Math.Min(currentDrawingExtent.Width / double.Parse(txtGridIsoLineCellColumnCount.Text), currentDrawingExtent.Height / Int32.Parse(txtGridIsoLineCellRowCount.Text));  
 
         //Greate the grid definition based on the extent, cell size etc.  
         GridDefinition gridDefinition = new GridDefinition(currentDrawingExtent, cellSize, -9999, wellDepthPointData);  
 
         FileStream gridFileStream = null;  
         try  
         {  
             gridFileStream = new FileStream(gridFilePath, FileMode.Create, FileAccess.ReadWrite);  
 
             //Generate the grid based on Inverse Distance Weighted interpolation model.  You can define your own model if needed.  
             GridFeatureSource.GenerateGrid(gridDefinition, new InverseDistanceWeightedGridInterpolationModel(2, double.MaxValue), gridFileStream);  
         }  
         finally  
         {  
             if (gridFileStream != null) { gridFileStream.Close(); }  
         }  
     }  
 
     private GridIsoLineLayer GetGridIsoLineLayer()  
     {  
         //Create a grid file based on the textboxes and the current extent  
         CreateGridFile();  
 
         //Load the grid we just created into the GridIsoLineLayer using the number of breaks defines  
         //on the screen  
         Collection<double> isoLineLevels = GridIsoLineLayer.GetIsoLineLevels(wellDepthPointData, Convert.ToInt32(txtGridIsoLineLevelCount.Text));  
         GridIsoLineLayer isoLineLayer = new GridIsoLineLayer(gridFilePath, isoLineLevels);  
 
         //Create a series of colors from blue to red that we will use for the breaks  
         Collection<GeoColor> colors = GeoColor.GetColorsInQualityFamily(GeoColor.StandardColors.Blue, GeoColor.StandardColors.Red, isoLineLevels.Count, ColorWheelDirection.Clockwise);  
 
         //Setup a class break style based on the isoline levels and the colors  
         ClassBreakStyle classBreakLineStyle = new ClassBreakStyle(isoLineLayer.DataValueColumnName);  
         LineStyle firstStyle = new LineStyle(new GeoPen(colors[0], 3));  
         classBreakLineStyle.ClassBreaks.Add(new ClassBreak(double.MinValue, firstStyle));  
         for (int i = 0; i < colors.Count - 1; i++)  
         {  
             LineStyle style = new LineStyle(new GeoPen(colors[i|+ 1], 3));  
             classBreakLineStyle.ClassBreaks.Add(new ClassBreak(isoLineLevels[i], style));  
         }  
         isoLineLayer.CustomStyles.Add(classBreakLineStyle);  
 
         //Create the text styles to label the lines  
         TextStyle textStyle = TextStyles.CreateSimpleTextStyle(isoLineLayer.DataValueColumnName, "Arial", 8, DrawingFontStyles.Bold, GeoColor.StandardColors.Black, 0, 0);  
         textStyle.OverlappingRule = LabelOverlappingRule.NoOverlapping;  
         textStyle.SplineType = SplineType.StandardSplining;  
         textStyle.DuplicateRule = LabelDuplicateRule.UnlimitedDuplicateLabels;  
         textStyle.TextLineSegmentRatio = 9999999;  
         textStyle.FittingLineInScreen = true;  
         textStyle.SuppressPartialLabels = true;  
         isoLineLayer.CustomStyles.Add(textStyle);  
 
         return isoLineLayer;  
     }  
 
     private GridFeatureLayer GetGridFeatureLayer()  
     {  
         GridIsoLineLayer gridIsoLineLayer = (GridIsoLineLayer)((LayerOverlay)winformsMap1.Overlays["isoLineOverlay"]).Layers["IsoLineLayer"];  
 
         gridIsoLineLayer.Open();  
 
         //Get the line breaks  
         Collection<double> isoLineBreaks = GridIsoLineLayer.GetIsoLineLevels(wellDepthPointData, Convert.ToInt32(txtGridIsoLineLevelCount.Text));  
 
         //Load a new GridFeatureLayer based on the current grid file  
         GridFeatureLayer gridFeatureLayer = new GridFeatureLayer(gridFilePath);  
 
         //Create a series of colors from blue to red that we will use for the breaks  
         Collection<GeoColor> colors = GeoColor.GetColorsInQualityFamily(GeoColor.StandardColors.Blue, GeoColor.StandardColors.Red, isoLineBreaks.Count, ColorWheelDirection.Clockwise);  
 
         //Create a class break style  
         ClassBreakStyle classBreakLineStyle = new ClassBreakStyle(gridFeatureLayer.DataValueColumnName);  
 
         //Setup a class break style based on the isoline levels and the colors  
         AreaStyle firstStyle = new AreaStyle(new GeoPen(GeoColor.FromArgb(50, colors[0]), 1), new GeoSolidBrush(GeoColor.FromArgb(50, colors[0])));  
         classBreakLineStyle.ClassBreaks.Add(new ClassBreak(double.MinValue, firstStyle));  
         for (int i = 1; i < colors.Count - 1; i++)  
         {  
             AreaStyle style = new AreaStyle(new GeoPen(GeoColor.FromArgb(50, colors[i]), 1), new GeoSolidBrush(GeoColor.FromArgb(50, colors[i])));  
             classBreakLineStyle.ClassBreaks.Add(new ClassBreak(isoLineBreaks[i], style));  
         }  
 
         gridFeatureLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(classBreakLineStyle);  
         gridFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
         return gridFeatureLayer;  
     }  
 
     private InMemoryFeatureLayer GetWellDepthPointLayer()  
     {  
         //Create an in memory layer to hold the well data from the text file  
         InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer();  
         inMemoryFeatureLayer.FeatureSource.Open();  
         //Make sure to specify the depth column  
         inMemoryFeatureLayer.Columns.Add(new FeatureSourceColumn("Depth", "String", 10));  
 
         //Loop through all the point data and add it to the in memory layer  
         foreach (KeyValuePair<PointShape, double> wellDepth in wellDepthPointData)  
         {  
             Feature feature = new Feature(wellDepth.Key);  
             feature.ColumnValues.Add("Depth", wellDepth.Value.ToString());  
             inMemoryFeatureLayer.InternalFeatures.Add(feature);  
         }  
         //Now that all of the data is added we can build an in memory index to make the lookups fast  
         inMemoryFeatureLayer.BuildIndex();  
 
         //Create the well point style  
         PointStyle pointStyle1 = PointStyles.CreateSimpleCircleStyle(GeoColor.StandardColors.White, 4, GeoColor.SimpleColors.Black, 2);  
         inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(pointStyle1);  
 
         //Create the text style with a halo  
         TextStyle textStyle = TextStyles.CreateSimpleTextStyle("Depth", "Arial", 10, DrawingFontStyles.Regular, GeoColor.SimpleColors.Black);  
         textStyle.HaloPen = new GeoPen(GeoColor.StandardColors.White, 3);  
         textStyle.PointPlacement = PointPlacement.UpperCenter;  
         textStyle.YOffsetInPixel = 5;  
 
         //Apply these styles at all levels and add then to the custom styles for the layer  
         inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;  
         inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(textStyle);  
 
         return inMemoryFeatureLayer;  
     }  
 
     #region Control Events  
 
     private void btnGenerateGridFile_Click(object sender, EventArgs e)  
     {  
         //Close the previous isoLineLayer and get ready to replace it with a new one  
         LayerOverlay layerOverlay = (LayerOverlay)winformsMap1.Overlays["isoLineOverlay"];  
         layerOverlay.Layers["IsoLineLayer"].Close();  
 
         ((LayerOverlay)winformsMap1.Overlays["isoLineOverlay"]).Layers["IsoLineLayer"] = GetGridIsoLineLayer();  
 
         cbxGridLine.Enabled = true;  
         winformsMap1.Refresh(layerOverlay);  
     }  
 
     private void btnGenerateWithFixedBreaks_Click(object sender, EventArgs e)  
     {  
         //Close the previous dynamicIsoLineLayer and get ready to replace it with a new one  
         LayerOverlay layerOverlay = (LayerOverlay)winformsMap1.Overlays["isoLineOverlay"];  
         layerOverlay.Layers["IsoLineLayer"].Close();  
 
         Collection<double> isoLineLevels = GridIsoLineLayer.GetIsoLineLevels(wellDepthPointData, Convert.ToInt32(txtGridIsoLineLevelCount.Text));  
 
         //Create the new dynamicIsoLineLayer using the well data and the number of isoline levels from  
         //the screen  
         DynamicIsoLineLayer dynamicIsoLineLayer = new DynamicIsoLineLayer(wellDepthPointData, isoLineLevels);  
         dynamicIsoLineLayer.CellHeightInPixel = winformsMap1.Height / int.Parse(txtDynamicIsoLineCellRowCount.Text);  
         dynamicIsoLineLayer.CellWidthInPixel = winformsMap1.Width / int.Parse(txtDynamicIsoLineCellColumnCount.Text);  
 
         //Create a series of colors from blue to red that we will use for the breaks  
         Collection<GeoColor> colors = GeoColor.GetColorsInQualityFamily(GeoColor.StandardColors.Blue, GeoColor.StandardColors.Red, isoLineLevels.Count, ColorWheelDirection.Clockwise);  
 
         //Setup a class break style based on the isoline levels and the colors  
         ClassBreakStyle classBreakLineStyle = new ClassBreakStyle(dynamicIsoLineLayer.DataValueColumnName);  
         LineStyle firstStyle = new LineStyle(new GeoPen(colors[0], 3));  
         classBreakLineStyle.ClassBreaks.Add(new ClassBreak(double.MinValue, firstStyle));  
         for (int i = 0; i < colors.Count - 1; i++)  
         {  
             LineStyle style = new LineStyle(new GeoPen(colors[i|+ 1], 3));  
             classBreakLineStyle.ClassBreaks.Add(new ClassBreak(isoLineLevels[i], style));  
         }  
         dynamicIsoLineLayer.CustomStyles.Add(classBreakLineStyle);  
 
         //Create the text styles to label the lines  
         TextStyle textStyle = TextStyles.CreateSimpleTextStyle(dynamicIsoLineLayer.DataValueColumnName, "Arial", 8, DrawingFontStyles.Bold, GeoColor.StandardColors.Black, 0, 0);  
         textStyle.OverlappingRule = LabelOverlappingRule.NoOverlapping;  
         textStyle.SplineType = SplineType.StandardSplining;  
         textStyle.DuplicateRule = LabelDuplicateRule.UnlimitedDuplicateLabels;  
         textStyle.TextLineSegmentRatio = 9999999;  
         textStyle.FittingLineInScreen = true;  
         textStyle.SuppressPartialLabels = true;  
         dynamicIsoLineLayer.CustomStyles.Add(textStyle);  
 
         //Set the layer to the new dynamicIsoLineLayer  
         ((LayerOverlay)winformsMap1.Overlays["isoLineOverlay"]).Layers["IsoLineLayer"] = dynamicIsoLineLayer;  
 
         //Turn the grid cell layer off and disable the checkbox  
         ((LayerOverlay)winformsMap1.Overlays["isoLineOverlay"]).Layers["GridCellsLayer"].IsVisible = false;  
         cbxGridLine.Enabled = false;  
         cbxGridLine.Checked = false;  
 
         winformsMap1.Refresh(layerOverlay);  
     }  
 
     private void cbxGridLine_CheckedChanged(object sender, EventArgs e)  
     {  
         //Change the visability of the GridLayer based on the checkbox  
         LayerOverlay layerOverlay = (LayerOverlay)winformsMap1.Overlays["isoLineOverlay"];  
         layerOverlay.Layers["GridCellsLayer"].IsVisible = cbxGridLine.Checked;  
         winformsMap1.Refresh(layerOverlay);  
     }  
 
     #endregion  
 }
source_code_serviceseditionsample_isolines_cs_winforms_111115.zip.txt · Last modified: 2015/09/09 03:35 by admin