Пример #1
1
        /// <summary>
        /// Generates intervals based on type, numberOfClasses and values.
        /// </summary>
        /// <param name="values"></param>
        /// <param name="type"></param>
        /// <param name="numberOfClasses"></param>
        /// <returns></returns>
        public static IList<Interval> GetIntervalsForNumberOfClasses(IList<Single> values, QuantityThemeIntervalType type, int numberOfClasses)
        {
            int index = 0;
            var intervals = new List<Interval>();
            var lowValue = values.Min();
            var highValue = values.Max();
            if (type == QuantityThemeIntervalType.NaturalBreaks)
            {
                ArrayList.Adapter((IList)values).Sort(); // performance, works 20% faster than layerAttribute.AttributeValues.Sort();
            }

            for (int i = 0; i < numberOfClasses; i++)
            {
                float intervalMin;
                float intervalMax;

                if (type == QuantityThemeIntervalType.EqualIntervals)
                {

                    intervalMin = lowValue + i * ((highValue - lowValue) / numberOfClasses);
                    intervalMax = lowValue + (i + 1) * ((highValue - lowValue) / numberOfClasses);
                }
                else
                {
                    intervalMin = Convert.ToSingle(values[index]);
                    index = (int)Math.Ceiling((double)(i + 1) / numberOfClasses * (values.Count - 1));
                    intervalMax = Convert.ToSingle(values[index]);
                }

                var interval = new Interval(intervalMin, intervalMax);
                intervals.Add(interval);
            }

            return intervals;
        }
Пример #2
0
        /// <summary> 
        /// Insert an item into the tree this is the root of.
        /// </summary>
        /// <param name="itemInterval"></param>
        /// <param name="item"></param>
        public void Insert(Interval itemInterval, object item)
        {
            int index = GetSubnodeIndex(itemInterval, origin);
            // if index is -1, itemEnv must contain the origin.
            if (index == -1) 
            {
                Add(item);
                return;
            }
            /*
            * the item must be contained in one interval, so insert it into the
            * tree for that interval (which may not yet exist)
            */
            Node node = subnode[index];
            /*
            *  If the subnode doesn't exist or this item is not contained in it,
            *  have to expand the tree upward to contain the item.
            */

            if (node == null || ! node.Interval.Contains(itemInterval)) 
            {
                Node largerNode = Node.CreateExpanded(node, itemInterval);
                subnode[index] = largerNode;
            }
            /*
            * At this point we have a subnode which exists and must contain
            * contains the env for the item.  Insert the item into the tree.
            */
            InsertContained(subnode[index], itemInterval, item);        
        }
Пример #3
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="itemInterval"></param>
 /// <returns></returns>
 public static Node CreateNode(Interval itemInterval)
 {
     Key key = new Key(itemInterval);
 
     Node node = new Node(key.Interval, key.Level);
     return node;
 }
Пример #4
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="node"></param>
 /// <param name="addInterval"></param>
 /// <returns></returns>
 public static Node CreateExpanded(Node node, Interval addInterval)
 {
     Interval expandInt = new Interval(addInterval);
     if (node != null) expandInt.ExpandToInclude(node.interval);
     Node largerNode = CreateNode(expandInt);
     if (node != null) largerNode.Insert(node);
     return largerNode;
 }
Пример #5
0
        private QuantityThemeItem(QuantityThemeItem another)
        {
            Interval = new Interval(another.Interval);
            style = (IStyle) another.Style.Clone();

            // label should be set after interval because when the interval
            // property is set, it also sets a default value for the label property
            label = another.label.Clone() as string;
        }
Пример #6
0
 /// <summary> 
 /// Returns the index of the subnode that wholely contains the given interval.
 /// If none does, returns -1.
 /// </summary>
 /// <param name="interval"></param>
 /// <param name="centre"></param>
 public static int GetSubnodeIndex(Interval interval, double centre)
 {
     int subnodeIndex = -1;
     if (interval.Min >= centre) 
         subnodeIndex = 1;
     if (interval.Max <= centre) 
         subnodeIndex = 0;
     return subnodeIndex;
 }
Пример #7
0
 /// <summary>
 /// Return a square envelope containing the argument envelope,
 /// whose extent is a power of two and which is based at a power of 2.
 /// </summary>
 /// <param name="itemInterval"></param>
 public  void ComputeKey(Interval itemInterval)
 {
     level = ComputeLevel(itemInterval);
     interval = new Interval();
     ComputeInterval(level, itemInterval);
     // MD - would be nice to have a non-iterative form of this algorithm
     while (!interval.Contains(itemInterval))
     {
         level += 1;
         ComputeInterval(level, itemInterval);
     }
 }
Пример #8
0
 /// <summary>
 /// Returns the subnode containing the envelope.
 /// Creates the node if
 /// it does not already exist.
 /// </summary>
 /// <param name="searchInterval"></param>
 public  Node GetNode(Interval searchInterval)
 {
     int subnodeIndex = GetSubnodeIndex(searchInterval, centre);
     // if index is -1 searchEnv is not contained in a subnode
     if (subnodeIndex != -1) 
     {
         // create the node if it does not exist
         Node node = GetSubnode(subnodeIndex);
         // recursively search the found/created node
         return node.GetNode(searchInterval);
     }
     else return this;            
 }
Пример #9
0
 /// <summary> 
 /// Insert an item which is known to be contained in the tree rooted at
 /// the given Node.  Lower levels of the tree will be created
 /// if necessary to hold the item.
 /// </summary>
 /// <param name="tree"></param>
 /// <param name="itemInterval"></param>
 /// <param name="item"></param>
 private void InsertContained(Node tree, Interval itemInterval, object item)
 {
     Assert.IsTrue(tree.Interval.Contains(itemInterval));
     /*
     * Do NOT create a new node for zero-area intervals - this would lead
     * to infinite recursion. Instead, use a heuristic of simply returning
     * the smallest existing node containing the query
     */
     bool isZeroArea = IntervalSize.IsZeroWidth(itemInterval.Min, itemInterval.Max);
     NodeBase node;
     if (isZeroArea)
         node = tree.Find(itemInterval);
     else node = tree.GetNode(itemInterval);
     node.Add(item);
 }
Пример #10
0
 /// <summary>
 /// Ensure that the Interval for the inserted item has non-zero extents.
 /// Use the current minExtent to pad it, if necessary.
 /// </summary>
 public static Interval EnsureExtent(Interval itemInterval, double minExtent)
 {
     double min = itemInterval.Min;
     double max = itemInterval.Max;
     // has a non-zero extent
     if (min != max) 
         return itemInterval;
     // pad extent
     if (min == max)
     {
         min = min - minExtent / 2.0;
         max = min + minExtent / 2.0;
     }
     return new Interval(min, max);
 }
Пример #11
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="interval"></param>
 /// <param name="resultItems"></param>
 /// <returns></returns>
 public  IList AddAllItemsFromOverlapping(Interval interval, IList resultItems)
 {
     if (!IsSearchMatch(interval))
         return items;
     // resultItems.addAll(items);
     foreach (object o in items)
         resultItems.Add(o);
     for (int i = 0; i < 2; i++)
         if (subnode[i] != null)
             subnode[i].AddAllItemsFromOverlapping(interval, resultItems);                            
     return items;
 }
Пример #12
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="interval"></param>
 /// <returns></returns>
 protected abstract bool IsSearchMatch(Interval interval);
Пример #13
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="interval"></param>
 /// <param name="foundItems"></param>
 public void Query(Interval interval, IList foundItems)
 {
     root.AddAllItemsFromOverlapping(interval, foundItems);
 }
Пример #14
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="interval"></param>
 private void CollectStats(Interval interval)
 {
     double del = interval.Width;
     if (del < minExtent && del > 0.0)
         minExtent = del;
 }
Пример #15
0
 public QuantityThemeItem(Interval interval, IStyle style)
 {
     Interval = interval;
     this.style = (IStyle) style.Clone();
 }
Пример #16
0
 /// <summary>
 /// min and max may be the same value.
 /// </summary>
 /// <param name="interval"></param>
 public IList Query(Interval interval)
 {
     /*
      * the items that are matched are all items in intervals
      * which overlap the query interval
      */
     IList foundItems = new ArrayList();
     Query(interval, foundItems);
     return foundItems;
 }
Пример #17
0
        private static QuantityTheme GetQuantityTheme(theme theme)
        {
            var themeQuantity = (themeQuantity) theme.Item;

            var quanTheme = new QuantityTheme(themeQuantity.columnName, GetDefaultStyle(theme))
                                {
                                    NoDataValues = ConvertNoDataValues(themeQuantity.noDataValues, themeQuantity.noDataValueType)
                                };
                        
            foreach (themeItem quanThemeItem in themeQuantity.quantityThemeItems)
            {
                var themeStyle = GetStyle(quanThemeItem);
                var interval = new Interval(quanThemeItem.intervalMinValue,
                                            quanThemeItem.intervalMaxValue);

                var themeItem = new QuantityThemeItem(interval, themeStyle) {Label = quanThemeItem.label};
                quanTheme.ThemeItems.Add(themeItem);
            }
            
            return quanTheme;
        }
Пример #18
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="interval"></param>
 /// <returns></returns>
 public static int ComputeLevel(Interval interval)
 {
     double dx = interval.Width;            
     int level = DoubleBits.GetExponent(dx) + 1;
     return level;
 }
Пример #19
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="interval"></param>
 /// <returns></returns>
 public  bool Contains(Interval interval)
 {
     return Contains(interval.Min, interval.Max);
 }
Пример #20
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="interval"></param>
 public  void ExpandToInclude(Interval interval)
 {
     if (interval.Max > Max) 
         Max = interval.Max;
     if (interval.Min < Min) 
         Min = interval.Min;
 }
Пример #21
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        private Node CreateSubnode(int index)
        {   
            // create a new subnode in the appropriate interval
            double min = 0.0;
            double max = 0.0;

            switch (index) 
            {
                case 0:
                    min = interval.Min;
                    max = centre;
                    break;
                case 1:
                    min = centre;
                    max = interval.Max;
                    break;
                default:
			        break;
            }
            Interval subInt = new Interval(min, max);
            Node node = new Node(subInt, level - 1);
            return node;
        }
Пример #22
0
 /// <summary>
 /// The root node matches all searches.
 /// </summary>
 /// <param name="interval"></param>
 protected override bool IsSearchMatch(Interval interval)
 {
     return true;
 }
Пример #23
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="interval"></param>
 /// <returns></returns>
 public bool Overlaps(Interval interval)
 {
     return Overlaps(interval.Min, interval.Max);
 }
Пример #24
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="interval"></param>
 /// <param name="level"></param>
 public Node(Interval interval, int level)
 {
     this.interval = interval;
     this.level = level;
     centre = (interval.Min + interval.Max) / 2;
 }
Пример #25
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="interval"></param>
 public Interval(Interval interval)
 {
     Init(interval.Min, interval.Max);
 }
Пример #26
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="itemInterval"></param>
 /// <returns></returns>
 protected override bool IsSearchMatch(Interval itemInterval)
 {
     return itemInterval.Overlaps(interval);
 }
Пример #27
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="interval"></param>
 public Key(Interval interval)
 {
     ComputeKey(interval);
 }
Пример #28
0
 /// <summary>
 /// Returns the smallest existing
 /// node containing the envelope.
 /// </summary>
 /// <param name="searchInterval"></param>
 public  NodeBase Find(Interval searchInterval)
 {
     int subnodeIndex = GetSubnodeIndex(searchInterval, centre);
     if (subnodeIndex == -1)
         return this;
     if (subnode[subnodeIndex] != null) 
     {
         // query lies in subnode, so search it
         Node node = subnode[subnodeIndex];
         return node.Find(searchInterval);
     }
     // no existing subnode, so return this one anyway
     return this;
 }
Пример #29
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="level"></param>
 /// <param name="itemInterval"></param>
 private void ComputeInterval(int level, Interval itemInterval)
 {
     double size = DoubleBits.PowerOf2(level);            
     pt = Math.Floor(itemInterval.Min / size) * size;
     interval.Init(pt, pt + size);
 }
Пример #30
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="itemInterval"></param>
 /// <param name="item"></param>
 public void Insert(Interval itemInterval, object item)
 {
     CollectStats(itemInterval);
     Interval insertInterval = EnsureExtent(itemInterval, minExtent);            
     root.Insert(insertInterval, item);            
 }