Exemple #1
0
 public BBox(IBBox other)
 {
     MinX = other.MinX;
     MinY = other.MinY;
     MaxX = other.MaxX;
     MaxY = other.MaxY;
 }
 public static bool Intersects(IBBox <T> a, IBBox <T> b)
 {
     return(b.MinX <= a.MaxX &&
            b.MinY <= a.MaxY &&
            b.MaxX >= a.MinX &&
            b.MaxY >= a.MinY);
 }
        public bool Collides(IBBox <T> bbox)
        {
            var node = _data;

            if (!node.Intersects(bbox))
            {
                return(false);
            }

            var nodesToSearch = new Stack <Node>();

            while (node != null)
            {
                for (int i = 0, len = node.Children.Count; i < len; i++)
                {
                    Node     child     = node.Children[i];
                    BBox <T> childBBox = child;

                    if (childBBox.Intersects(bbox))
                    {
                        if (node.Leaf || BBox <T> .Contains(bbox, childBBox))
                        {
                            return(true);
                        }
                        nodesToSearch.Push(child);
                    }
                }
                node = nodesToSearch.Count > 0 ? nodesToSearch.Pop() : null;
            }

            return(false);
        }
 public virtual bool Contains(IBBox <T> a)
 {
     return(MinX <= a.MinX &&
            MinY <= a.MinY &&
            a.MaxX <= MaxX &&
            a.MaxY <= MaxY);
 }
        private void Insert(IBBox <T> item, int level, bool isNode)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            var bbox = item; //isNode ? item : new Node(item);

            var insertPath = new List <Node>();

            // find the best node for accommodating the item, saving all nodes along the path too
            var node = ChooseSubtree(bbox, _data, level, ref insertPath);

            // put the item into the node
            node.Children.Add(isNode ? (Node)item : new Node(item));
            node.Extend(bbox);

            // split on node overflow; propagate upwards if necessary
            while (level >= 0)
            {
                if (insertPath[level].Children.Count > _maxEntries)
                {
                    Split(ref insertPath, level);
                    level--;
                }
                else
                {
                    break;
                }
            }

            // adjust bboxes along the insertion path
            AdjustParentBBoxes(bbox, insertPath, level);
            Count++;
        }
 public virtual bool Intersects(IBBox <T> b)
 {
     return(b.MinX <= MaxX &&
            b.MinY <= MaxY &&
            b.MaxX >= MinX &&
            b.MaxY >= MinY);
 }
 public static void Extend <T>(this IBBox <T> a, float minX, float minY, float maxX, float maxY)
 {
     a.MinX = Math.Min(a.MinX, minX);
     a.MinY = Math.Min(a.MinY, minY);
     a.MaxX = Math.Max(a.MaxX, maxX);
     a.MaxY = Math.Max(a.MaxY, maxY);
 }
 public static void Extend <T>(this IBBox <T> a, IBBox <T> b)
 {
     a.MinX = Math.Min(a.MinX, b.MinX);
     a.MinY = Math.Min(a.MinY, b.MinY);
     a.MaxX = Math.Max(a.MaxX, b.MaxX);
     a.MaxY = Math.Max(a.MaxY, b.MaxY);
 }
 public static void Expand <T>(this IBBox <T> a, float amount)
 {
     a.MinX -= amount;
     a.MaxX += amount;
     a.MinY -= amount;
     a.MaxY += amount;
 }
Exemple #10
0
 public static bool Equals(this IBBox a, IBBox b)
 {
     return(b.MinX == a.MinX &&
            b.MinY == a.MinY &&
            b.MaxX == a.MaxX &&
            b.MaxY == a.MaxY);
 }
Exemple #11
0
 public static void Extend(this IBBox a, int minX, int minY, int maxX, int maxY)
 {
     a.MinX = Math.Min(a.MinX, minX);
     a.MinY = Math.Min(a.MinY, minY);
     a.MaxX = Math.Max(a.MaxX, maxX);
     a.MaxY = Math.Max(a.MaxY, maxY);
 }
Exemple #12
0
 public static void Expand(this IBBox a, int amount)
 {
     a.MinX -= amount;
     a.MaxX += amount;
     a.MinY -= amount;
     a.MaxY += amount;
 }
        /*
         * Note: Original python-implementation was defined in Layer.py
         *
         * def getResolution (self, (minx, miny, maxx, maxy)):
         * return max( (maxx - minx) / self.size[0],
         *  (maxy - miny) / self.size[1] )
         */
        #endregion
        public static double GetResolution(this IBBox self, Size size)
        {
            var resX = (self.MaxX - self.MinX) / size.Width;
            var resY = (self.MaxY - self.MinY) / size.Height;

            return(Math.Max(resX, resY));
        }
 public static bool Contains(IBBox <T> a, IBBox <T> b)
 {
     return(a.MinX <= b.MinX &&
            a.MinY <= b.MinY &&
            b.MaxX <= a.MaxX &&
            b.MaxY <= a.MaxY);
 }
 private static void FailIfInvalidBBox(IBBox bbox)
 {
     Assert.IsNotNull(bbox, "bbox should not be null");
     Assert.AreEqual(1596363.87, bbox.MaxX);
     Assert.AreEqual(7964447.65, bbox.MaxY);
     Assert.AreEqual(-570684.15, bbox.MinX);
     Assert.AreEqual(6424344.35, bbox.MinY);
 }
 private void AdjustParentBBoxes(IBBox <T> bbox, List <Node> path, int level)
 {
     // adjust bboxes along the given tree path
     for (var i = level; i >= 0; i--)
     {
         path[i].Extend(bbox);
     }
 }
 public void Insert(IBBox <T> item)
 {
     if (item == null)
     {
         throw new ArgumentNullException("item");
     }
     Insert(item, _data.Height - 1, false);
 }
Exemple #18
0
        public long IntersectionArea(IBBox b)
        {
            long minX = Math.Max(MinX, b.MinX);
            long minY = Math.Max(MinY, b.MinY);
            long maxX = Math.Min(MaxX, b.MaxX);
            long maxY = Math.Min(MaxY, b.MaxY);

            return(Math.Max(0, maxX - minX) *
                   Math.Max(0, maxY - minY));
        }
        public float IntersectionArea(IBBox <T> b)
        {
            float minX = Math.Max(MinX, b.MinX);
            float minY = Math.Max(MinY, b.MinY);
            float maxX = Math.Min(MaxX, b.MaxX);
            float maxY = Math.Min(MaxY, b.MaxY);

            return(Math.Max(0, maxX - minX) *
                   Math.Max(0, maxY - minY));
        }
        public static Resolutions GetResolutions(this IBBox self, int levels, Size size)
        {
            var width  = self.Width();
            var height = self.Height();
            var aspect = self.GetAspect();

            double maxResolution = (width >= height)
                ? width / (size.Width /*[0]*/ * aspect)
                : width / (size.Height /*[1]*/ * aspect);

            return(GeoCache.Core.Resolutions.Get(levels, maxResolution));
        }
        private Node ChooseSubtree(IBBox <T> bbox, Node node, int level, ref List <Node> path)
        {
            Node  child;
            Node  targetNode = null;
            float minArea, minEnlargement;

            while (true)
            {
                path.Add(node);

                if (node.Leaf || path.Count - 1 == level)
                {
                    break;
                }

                minArea = minEnlargement = long.MaxValue;

                for (int i = 0, len = node.Children.Count; i < len; i++)
                {
                    child = node.Children[i];
                    float area        = child.Area;
                    float enlargement = child.EnlargedArea(bbox) - area;

                    // choose entry with the least area enlargement
                    if (enlargement < minEnlargement)
                    {
                        minEnlargement = enlargement;
                        minArea        = area < minArea ? area : minArea;
                        targetNode     = child;
                    }
                    else if (enlargement == minEnlargement)
                    {
                        // otherwise choose one with the smallest area
                        if (area < minArea)
                        {
                            minArea    = area;
                            targetNode = child;
                        }
                    }
                }

                node = targetNode ?? node.Children[0];
            }

            return(node);
        }
Exemple #22
0
        public static int CompareMinX(IBBox a, IBBox b)
        {
            int d = a.MinX - b.MinX;

            if (d < 0)
            {
                return(-1);
            }
            else if (d > 0)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
        public static int CompareMinY(IBBox <T> a, IBBox <T> b)
        {
            float d = a.MinY - b.MinY;

            if (d < 0)
            {
                return(-1);
            }
            else if (d > 0)
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
Exemple #24
0
        public Cell GetCell(IBBox bbox, bool exact)
        {
            if (!BBox.Contains(bbox.MinX, bbox.MinY))
            {
                string message = string.Format("Lower left corner ({0}, {1}) is outside layer bounds {2}."
                                               , bbox.MinX, bbox.MinY, BBox);
                const bool FORCE_STRICT = false;
                if (FORCE_STRICT || exact && ExtentType == ExtentType.Strict)
                {
                    throw new ArgumentOutOfRangeException("bbox",
                                                          message +
                                                          "\nTo remove this condition, set extent-type to loose in your configuration.");
                }
                Trace.WriteLine(message, "Layer.GetCell");
            }

            int    z   = GetLevel(bbox.GetResolution(Size), Size);
            double res = Resolutions[z];

            double x0 = (bbox.MinX - BBox.MinX) / (res * Size.Width);
            double y0 = (bbox.MinY - BBox.MinY) / (res * Size.Height);

            int x = Convert.ToInt32(Math.Round(x0));
            int y = Convert.ToInt32(Math.Round(y0));

            double tileX = ((x * res * Size.Width) + BBox.MinX);
            double tileY = ((y * res * Size.Height) + BBox.MinY);

            if (exact)
            {
                if (Math.Abs(bbox.MinX - tileX) / res > 1)
                {
                    throw new Exception(string.Format("Current x value {0} is too far from tile corner x {1}", bbox.MinX, tileX));
                }
                if (Math.Abs(bbox.MinY - tileY) / res > 1)
                {
                    throw new Exception(string.Format("Current y value {0} is too far from tile corner y {1}", bbox.MinX, tileX));
                }
            }
            //var quadKey = Microsoft.MapPoint.VirtualEarthTileSystem.TileXYToQuadKey(x, y, z);
            //if (string.IsNullOrEmpty(quadKey))
            //    quadKey = string.Format("<empty x={0}, y={1}, z={2}>", x, y, z);
            //System.Diagnostics.Trace.WriteLine("GetCell - TileXYToQuadKey:" + quadKey, "Layer.GetCell");

            return(new Cell(x, y, z));
        }
        public List <IBBox <T> > SearchParentsOrNull(IBBox <T> bbox)
        {
            var node = _data;
            //_cacheListResult.Clear();
            //var result = _cacheListResult;
            var result = new List <IBBox <T> >();

            if (!node.Contains(bbox))
            {
                return(null);
            }

            var nodesToSearch = new Stack <Node>();

            while (node != null)
            {
                for (int i = 0, len = node.Children.Count; i < len; i++)
                {
                    Node     child     = node.Children[i];
                    BBox <T> childBBox = child;

                    if (childBBox.Contains(bbox))
                    {
                        if (node.Leaf)
                        {
                            result.Add(child.ExternalObject);
                        }
                        else if (BBox <T> .Contains(bbox, childBBox))
                        {
                            AllCombine(child, ref result);
                        }
                        else
                        {
                            nodesToSearch.Push(child);
                        }
                    }
                }
                node = nodesToSearch.Count > 0 ? nodesToSearch.Pop() : null;
            }

            return(result.Count == 0 ? null : result.ToList());
        }
Exemple #26
0
        protected Layer(string name, string layers, IBBox bbox,
                        string srs, string description, double?maxResolution,
                        Size size, int levels, Resolutions resolutions,
                        string extension, string mimeType, ICache cache,
                        string watermarkImage, float?watermarkOpacity,
                        ExtentType extentType, object units, string tmsType)
        {
            Name        = name;
            Description = description;
            if (string.IsNullOrEmpty(layers))
            {
                Layers = name;
            }

            BBox        = bbox;
            Size        = size;
            Units       = units;
            Srs         = srs;
            Extension   = extension;
            ContentType = string.IsNullOrEmpty(mimeType) ? Format : mimeType;
            Cache       = cache;
            //Debug = debug;
            ExtentType = extentType;
            TmsType    = tmsType;
            _levels    = levels;
            if (resolutions != null)
            {
                Resolutions = resolutions;
            }
            else
            {
                MaxResolution = maxResolution;
            }
            WatermarkImage   = watermarkImage;
            WatermarkOpacity = watermarkOpacity;
        }
 public Node(IBBox <T> externalObject)
     : base(externalObject.MinX, externalObject.MinY, externalObject.MaxX, externalObject.MaxY)
 {
     ExternalObject = externalObject;
 }
 public float EnlargedArea(IBBox <T> b)
 {
     return((Math.Max(b.MaxX, MaxX) - Math.Min(b.MinX, MinX)) *
            (Math.Max(b.MaxY, MaxY) - Math.Min(b.MinY, MinY)));
 }
 public List <IBBox <T> > Search(IBBox <T> bbox)
 {
     return(SearchOrNull(bbox) ?? new List <IBBox <T> >());
 }
 public List <IBBox <T> > SearchParents(IBBox <T> bbox)
 {
     return(SearchParentsOrNull(bbox) ?? new List <IBBox <T> >());
 }