Exemple #1
0
 public void createQuadTree()
 {
     if (Boundingbox == null)
         throw new Exception("Need boundingbox to create quadTree");
     QuadTree = new QuadTree(Boundingbox.MinX, Boundingbox.MaxX, Boundingbox.MinY, Boundingbox.MaxY);
     foreach (Feature f in Features.Values)
         QuadTree.add(f);
 }
Exemple #2
0
        public void split()
        {
            // creates child nodes
            hasChildren = true;
            children[0] = new QuadTree(boundary.MinX, boundary.MinX + boundary.Width / 2, boundary.MinY, boundary.MinY + boundary.Height / 2);
            children[1] = new QuadTree(boundary.MinX, boundary.MinX + boundary.Width / 2, boundary.MinY + boundary.Height / 2, boundary.MaxY);
            children[2] = new QuadTree(boundary.MinX + boundary.Width / 2, boundary.MaxX, boundary.MinY, boundary.MinY + boundary.Height / 2);
            children[3] = new QuadTree(boundary.MinX + boundary.Width / 2, boundary.MaxX, boundary.MinY + boundary.Height / 2, boundary.MaxY);

            // divide features between child nodes
            List<Feature> newfeatures = new List<Feature>();
            foreach (Feature f in features)
            {
                bool added = false;
                foreach (QuadTree qt in children) {
                    if (qt.gboundary.Contains(f.Geometry))
                    {
                        qt.add(f);
                        added = true;
                        break;
                    }
                }
                if (!added)
                   newfeatures.Add(f);
            }
            features = newfeatures;
        }