public static bool SaveLayers(Map map, string directory, Chart pieChart, Panel panel, ref CustomerInterpolation interpolation, ref List<InterpolatedFields> saveFields) { var projectFile = new Project(); var layers = new List<ProjectLayer>(); var baseMap = new BaseMapLayer(); UncheckAllLayers(map); foreach (var item in map.GetLayers()) { // Map Layer if (item is MapImageLayer && item.DataSet is InRamImageData) { } else { //Point Features Layer if (item is MapPointLayer && item.DataSet is PointShapefile) { var layer = item as IMapFeatureLayer; var fileName = Path.GetFileName(layer.DataSet.Filename); var path = Path.Combine(directory, fileName); layer.DataSet.SaveAs(Path.Combine(directory, fileName), true); layers.Add(new ProjectLayer() { Path = path }); item.Checked = true; PluginExtension.MyAppManager.Map.Refresh(); } else if (item is MapPolygonLayer && item.DataSet is IFeatureSet) { var layer = item as IMapPolygonLayer; var fileName = Path.GetFileName(layer.DataSet.Filename); var path = Path.Combine(directory, fileName); var imagePath = Path.Combine(directory, Path.GetFileNameWithoutExtension(layer.DataSet.Filename) + ".png"); var colorPlatImg = Path.Combine(directory, Path.GetFileNameWithoutExtension(layer.DataSet.Filename) + "_ColorPlate.png"); var pieChartImage = Path.Combine(directory, Path.GetFileNameWithoutExtension(layer.DataSet.Filename) + "_PIEChart.png"); item.Checked = true; PluginExtension.MyAppManager.Map.Refresh(); if (KrigingTemp.Fields.Where(c => c.OutputShapeFile == fileName).Count() > 0) { var tempField = KrigingTemp.Fields.Where(c => c.OutputShapeFile == fileName).First(); SaveGridFile(tempField.OutputShapeFile, directory); var intField = new InterpolatedFields(); intField.ZData = tempField.OutputZ; intField.Field = tempField.Field; intField.ShapeFile = path; intField.Image = imagePath; intField.PieChartData = Newtonsoft.Json.JsonConvert.SerializeObject(tempField.PieChartData); intField.ProductValue = tempField.ProductResult; if (new ConfigSaveKriging().LoadPieChart(pieChart, panel, tempField.PieChartData, pieChartImage)) { intField.PieChartImage = pieChartImage; } var ls = new List<ColorCategory>(); foreach (var s in layer.Symbology.Categories.ToList()) { ls.Add(new ColorCategory() { Color = s.GetColor(), Expression = s.FilterExpression, LegendText = s.LegendText, Max = s.Maximum, Min = s.Minimum, }); } var colorPlate = CreateColorPlate(ls); if (colorPlate != null) { colorPlate.Save(colorPlatImg, System.Drawing.Imaging.ImageFormat.Png); intField.ColorPlateImage = colorPlatImg; } intField.ColorsCategories = Newtonsoft.Json.JsonConvert.SerializeObject(ls); var array = Array.ConvertAll(tempField.OutputZ.Split(','), Double.Parse); intField.Max = Convert.ToDouble(array.Max(), System.Globalization.CultureInfo.InvariantCulture.NumberFormat); intField.Min = Convert.ToDouble(array.Min(), System.Globalization.CultureInfo.InvariantCulture.NumberFormat); intField.Mean = Convert.ToDouble(Math.Round(array.Average(), 2), System.Globalization.CultureInfo.InvariantCulture.NumberFormat); saveFields.Add(intField); getSnapshot(imagePath); } else { layers.Add(new ProjectLayer() { Path = path }); } layer.DataSet.SaveAs(path, true); } } } projectFile.BaseMap = baseMap; projectFile.Layers = layers; interpolation.ProjectFiles = Newtonsoft.Json.JsonConvert.SerializeObject(projectFile); return true; }
private async void btnSaveInterpolation_Click(object sender, EventArgs e) { try { var tab = (Control)PluginExtension.MyAppManager.Map; System.Drawing.Point location = tab.PointToScreen(System.Drawing.Point.Empty); this.Location = new Point(78, 78); var interpolation = new CustomerInterpolation() { CustomerFarmId = Convert.ToInt32(cbFarms.SelectedValue), Name = txtName.Text, }; var interpolatedFields = new List<InterpolatedFields>(); var dirPath = CreateClientDirectory(); ConfigSaveKriging.SaveLayers((Map)PluginExtension.MyAppManager.Map, dirPath, pieChart, panel1, ref interpolation, ref interpolatedFields); var result = _interpolationRepository.SaveInterpolation(interpolation, interpolatedFields); if (result > 0) { KrigingTemp.Fields = new List<KrigingInputField>(); MessageBox.Show("Kriging data saved successfully."); } await Task.Delay(100); } catch (Exception) { throw; } }