/// <summary> /// Does the internal processing to actually create the breaks. /// </summary> /// <param name="numBreaks">number of breaks</param> /// <param name="tuples">asc ordered input of values and their occurence counts</param> /// <returns>created breaks</returns> private static List <double> ClassifyByJenksFisher(int numBreaks, List <ValueCountTuple> tuples) { var breaksArray = new List <double>(numBreaks); if (numBreaks == 0) { return(breaksArray); } // avoid array <-> list conversations breaksArray.AddRange(Enumerable.Repeat(0.0d, numBreaks)); var classificator = new JenksFisher(tuples, numBreaks); if (numBreaks > 1) { // runs the actual calculation classificator.CalculateAll(); int lastClassBreakIndex = classificator.FindMaxBreakIndex(classificator._bufferSize - 1, 0, classificator._bufferSize); while (--numBreaks != 0) { // assign the break values to the result breaksArray[numBreaks] = tuples[lastClassBreakIndex + numBreaks].Value; if (numBreaks > 1) { classificator._classBreaksIndex -= classificator._bufferSize; lastClassBreakIndex = classificator._classBreaks[classificator._classBreaksIndex + lastClassBreakIndex]; } } } breaksArray[0] = tuples[0].Value; // break for the first class is the minimum of the dataset. return(breaksArray); }
private bool DoJenksFisherCategorization(int colorIndex, bool multiAOI = false) { if (txtCategoryCount.Text.Length > 0) { _sheetMapSummary.Clear(); _categoryItems.Clear(); _dataValues = ComputeDataValues(multiAOI); _dataValues.Sort(); var listBreaks = JenksFisher.CreateJenksFisherBreaksArray(_dataValues, int.Parse(txtCategoryCount.Text)); var n = 0; var lower = listBreaks.Min(); var upper = 0D; int row; System.Drawing.Color color; _categories.Clear(); ColorBlend blend = (ColorBlend)icbColorScheme.ColorSchemes.List[colorIndex]; _scheme = ColorSchemes.ColorBlend2ColorScheme(blend); //make categories from the breaks defined in Jenk's-Fisher's //add the category range and color to a datagridview CategoryItem ci; foreach (var item in listBreaks) { if (n > 0) { upper = item; color = AddCategory(lower, upper); ci = new CategoryItem(); ci.Upper = item; ci.Color = color; ci.Lower = lower; ci.ClassSize = GetClassSize(lower, upper).ToString(); lower = item; _categoryItems.Add(ci); } n++; } //add the last category to the datagridview color = AddCategory(upper, _dataValues.Max() + 1); ci = new CategoryItem(); ci.Color = color; ci.Lower = listBreaks.Max(); ci.Upper = _dataValues.Max(); ci.ClassSize = GetClassSize(listBreaks.Max(), 0, true).ToString(); _categoryItems.Add(ci); //add an empty null category AddNullCategory(); return(_categoryItems.Count > 0); } else { MessageBox.Show("Specify number of categories", "GPX Manager", MessageBoxButton.OK, MessageBoxImage.Information); } return(false); }
private List <double> GetBreaksFromFisherVesselInventoryData(string inventoryGuid, int numBreaks = 5) { List <double> source = new List <double>(); var dt = new DataTable(); string sql = $@"SELECT Sum(CountMunicipalMotorized) AS Motorized, Sum(CountMunicipalNonMotorized) AS NonMotorized, Sum(CountCommercial) AS Commercial FROM tblGearInventoryBarangay WHERE InventoryGuid={{{inventoryGuid}}} GROUP BY Municipality"; using (var conection = new OleDbConnection(global.ConnectionString)) { try { conection.Open(); var adapter = new OleDbDataAdapter(sql, conection); adapter.Fill(dt); for (int i = 0; i < dt.Rows.Count; i++) { DataRow dr = dt.Rows[i]; double v = (double)dr["Motorized"]; if (v > 0) { source.Add(v); } v = (double)dr["NonMotorized"]; if (v > 0) { source.Add(v); } v = (double)dr["Commercial"]; if (v > 0) { source.Add(v); } } } catch (Exception ex) { Logger.Log(ex.Message, "InventoryMapping.cs", "GetBreaksFromInventoryData"); } } BreakSourceMaximum = source.Max(); BreakSourceMinimum = source.Min(); return(JenksFisher.CreateJenksFisherBreaksArray(source, numBreaks)); }
private List <double> GetBreaksFromInventoryData(string inventoryGuid, int numBreaks = 5) { List <double> source = new List <double>(); var dt = new DataTable(); string sql = $@"SELECT Sum([tblGearInventoryBarangayData].[CountCommercial] +[tblGearInventoryBarangayData].[CountMunicipalMotorized] +[tblGearInventoryBarangayData].[CountMunicipalNonMotorized] +[tblGearInventoryBarangayData].[CountNoBoat]) AS TotalCount FROM tblGearInventoryBarangay INNER JOIN tblGearInventoryBarangayData ON tblGearInventoryBarangay.BarangayInventoryGuid = tblGearInventoryBarangayData.BarangayInventoryGUID WHERE tblGearInventoryBarangay.InventoryGuid={{{inventoryGuid}}} GROUP BY tblGearInventoryBarangay.Municipality, tblGearInventoryBarangayData.GearVariation ORDER BY Sum([tblGearInventoryBarangayData].[CountCommercial] +[tblGearInventoryBarangayData].[CountMunicipalMotorized] +[tblGearInventoryBarangayData].[CountMunicipalNonMotorized] +[tblGearInventoryBarangayData].[CountNoBoat]) DESC"; using (var conection = new OleDbConnection(global.ConnectionString)) { try { conection.Open(); var adapter = new OleDbDataAdapter(sql, conection); adapter.Fill(dt); if (dt.Rows.Count > 0) { BreakSourceMaximum = (double)dt.Rows[0]["TotalCount"]; } for (int i = 0; i < dt.Rows.Count; i++) { DataRow dr = dt.Rows[i]; source.Add((double)dr["TotalCount"]); } BreakSourceMinimum = (double)dt.Rows[dt.Rows.Count - 1]["TotalCount"]; } catch (Exception ex) { Logger.Log(ex.Message, "InventoryMapping.cs", "GetBreaksFromInventoryData"); } } return(JenksFisher.CreateJenksFisherBreaksArray(source, numBreaks)); }
public void Render(double[] vec) { if (vec == null) { return; } // var statinfo = StatHelper.Get(vec); var breaks = JenksFisher.CreateJenksFisherBreaksArray(vec, ColourRampCount + 1); if (breaks.Count <= 1) { return; } //MessageBox.Show(breaks.Count.ToString()); //Console.WriteLine(breaks.Count); Console.WriteLine(breaks); for (int i = 0; i < _GraphicsLayer.Graphics.Count; i++) { var color = _ClassColor[0]; for (int j = 0; j < ColourRampCount; j++) { if (vec[i] >= breaks[j] && vec[i] < breaks[j + 1]) { color = _ClassColor[j]; break; } } var symbol = _GraphicsLayer.Graphics[i].Symbol as SimpleFillSymbol; symbol.Fill = new System.Windows.Media.SolidColorBrush(color) { Opacity = Opacity }; symbol.BorderThickness = BorderThickness; } _GraphicsLayer.Refresh(); }