Beispiel #1
0
 /// <summary>
 /// Creates a new instance of DrawingScheme
 /// </summary>
 protected Scheme()
 {
     base.LegendSymbolMode = SymbolMode.None;
     LegendType = LegendType.Scheme;
     _statistics = new Statistics();
 }
Beispiel #2
0
        /// <summary>
        /// Before attempting to create categories using a color ramp, this must be calculated
        /// to updated the cache of values that govern statistics and break placement.
        /// </summary>
        /// <param name="table">The data Table to use.</param>
        public void GetValues(DataTable table)
        {
            Values = new List <double>();
            string normField = EditorSettings.NormField;
            string fieldName = EditorSettings.FieldName;

            if (!string.IsNullOrEmpty(EditorSettings.ExcludeExpression))
            {
                DataRow[] rows = table.Select("NOT (" + EditorSettings.ExcludeExpression + ")");
                foreach (DataRow row in rows)
                {
                    if (rows.Length < EditorSettings.MaxSampleCount)
                    {
                        double val;
                        if (!double.TryParse(row[fieldName].ToString(), out val))
                        {
                            continue;
                        }
                        if (double.IsNaN(val))
                        {
                            continue;
                        }

                        if (normField != null)
                        {
                            double norm;
                            if (!double.TryParse(row[normField].ToString(), out norm) || double.IsNaN(val))
                            {
                                continue;
                            }
                            Values.Add(val / norm);
                            continue;
                        }
                        Values.Add(val);
                    }
                    else
                    {
                        Dictionary <int, double> randomValues = new Dictionary <int, double>();
                        int    count = EditorSettings.MaxSampleCount;
                        int    max   = rows.Length;
                        Random rnd   = new Random();
                        for (int i = 0; i < count; i++)
                        {
                            double val;
                            double norm = 1;
                            int    index;
                            bool   failed = false;
                            do
                            {
                                index = rnd.Next(max);
                                if (!double.TryParse(rows[index][fieldName].ToString(), out val))
                                {
                                    failed = true;
                                }
                                if (normField == null)
                                {
                                    continue;
                                }
                                if (!double.TryParse(rows[index][normField].ToString(), out norm))
                                {
                                    failed = true;
                                }
                            } while (randomValues.ContainsKey(index) || double.IsNaN(val) || failed);
                            if (normField != null)
                            {
                                Values.Add(val / norm);
                            }
                            else
                            {
                                Values.Add(val);
                            }

                            randomValues.Add(index, val);
                        }
                    }
                }
                Values.Sort();
                Statistics.Calculate(Values);
                return;
            }

            if (table.Rows.Count < EditorSettings.MaxSampleCount)
            {
                // Simply grab all the values
                foreach (DataRow row in table.Rows)
                {
                    double val;
                    if (!double.TryParse(row[fieldName].ToString(), out val))
                    {
                        continue;
                    }
                    if (double.IsNaN(val))
                    {
                        continue;
                    }
                    if (normField == null)
                    {
                        Values.Add(val);
                        continue;
                    }
                    double norm;
                    if (!double.TryParse(row[normField].ToString(), out norm) || double.IsNaN(val))
                    {
                        continue;
                    }
                    Values.Add(val / norm);
                }
            }
            else
            {
                // Grab random samples
                Dictionary <int, double> randomValues = new Dictionary <int, double>();
                int    count = EditorSettings.MaxSampleCount;
                int    max   = table.Rows.Count;
                Random rnd   = new Random();
                for (int i = 0; i < count; i++)
                {
                    double val;
                    double norm = 1;
                    int    index;
                    bool   failed = false;
                    do
                    {
                        index = rnd.Next(max);
                        if (!double.TryParse(table.Rows[index][fieldName].ToString(), out val))
                        {
                            failed = true;
                        }
                        if (normField == null)
                        {
                            continue;
                        }
                        if (!double.TryParse(table.Rows[index][normField].ToString(), out norm))
                        {
                            failed = true;
                        }
                    } while (randomValues.ContainsKey(index) || double.IsNaN(val) || failed);
                    if (normField != null)
                    {
                        Values.Add(val / norm);
                    }
                    else
                    {
                        Values.Add(val);
                    }

                    randomValues.Add(index, val);
                }
            }
            Values.Sort();
        }
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Scheme"/> class.
 /// </summary>
 protected Scheme()
 {
     LegendSymbolMode = SymbolMode.None;
     LegendType       = LegendType.Scheme;
     Statistics       = new Statistics();
 }
Beispiel #4
0
        /// <summary>
        /// Gets the values from a file based data source rather than an in memory object.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="progressHandler"></param>
        public void GetValues(IAttributeSource source, ICancelProgressHandler progressHandler)
        {
            int pageSize = 100000;

            Values = new List <double>();
            string normField = EditorSettings.NormField;
            string fieldName = EditorSettings.FieldName;

            if (source.NumRows() < EditorSettings.MaxSampleCount)
            {
                int numPages = (int)Math.Ceiling((double)source.NumRows() / pageSize);
                for (int ipage = 0; ipage < numPages; ipage++)
                {
                    int       numRows = (ipage == numPages - 1) ? source.NumRows() % pageSize : pageSize;
                    DataTable table   = source.GetAttributes(ipage * pageSize, numRows);
                    if (!string.IsNullOrEmpty(EditorSettings.ExcludeExpression))
                    {
                        DataRow[] rows = table.Select("NOT (" + EditorSettings.ExcludeExpression + ")");
                        foreach (DataRow row in rows)
                        {
                            double val;
                            if (!double.TryParse(row[fieldName].ToString(), out val))
                            {
                                continue;
                            }
                            if (double.IsNaN(val))
                            {
                                continue;
                            }

                            if (normField != null)
                            {
                                double norm;
                                if (!double.TryParse(row[normField].ToString(), out norm) || double.IsNaN(val))
                                {
                                    continue;
                                }
                                Values.Add(val / norm);
                                continue;
                            }
                            Values.Add(val);
                        }
                    }
                    else
                    {
                        foreach (DataRow row in table.Rows)
                        {
                            double val;
                            if (!double.TryParse(row[fieldName].ToString(), out val))
                            {
                                continue;
                            }
                            if (double.IsNaN(val))
                            {
                                continue;
                            }

                            if (normField != null)
                            {
                                double norm;
                                if (!double.TryParse(row[normField].ToString(), out norm) || double.IsNaN(val))
                                {
                                    continue;
                                }
                                Values.Add(val / norm);
                                continue;
                            }
                            Values.Add(val);
                        }
                    }
                }
            }
            else
            {
                Dictionary <int, double> randomValues = new Dictionary <int, double>();
                pageSize = 10000;
                int count = EditorSettings.MaxSampleCount;

                Random         rnd          = new Random();
                AttributePager ap           = new AttributePager(source, pageSize);
                int            countPerPage = count / ap.NumPages();
                ProgressMeter  pm           = new ProgressMeter(progressHandler, "Sampling " + count + " random values", count);
                for (int iPage = 0; iPage < ap.NumPages(); iPage++)
                {
                    for (int i = 0; i < countPerPage; i++)
                    {
                        double val;
                        double norm = 1;
                        int    index;
                        bool   failed = false;
                        do
                        {
                            index = rnd.Next(ap.StartIndex, ap.StartIndex + pageSize);
                            DataRow dr = ap.Row(index);
                            if (!double.TryParse(dr[fieldName].ToString(), out val))
                            {
                                failed = true;
                            }
                            if (normField == null)
                            {
                                continue;
                            }
                            if (!double.TryParse(dr[normField].ToString(), out norm))
                            {
                                failed = true;
                            }
                        } while (randomValues.ContainsKey(index) || double.IsNaN(val) || failed);
                        if (normField != null)
                        {
                            Values.Add(val / norm);
                        }
                        else
                        {
                            Values.Add(val);
                        }
                        randomValues.Add(index, val);
                        pm.CurrentValue = i + iPage * countPerPage;
                    }
                    //Application.DoEvents();
                    if (progressHandler != null && progressHandler.Cancel)
                    {
                        break;
                    }
                }
            }
            Values.Sort();
            Statistics.Calculate(Values);
        }