示例#1
0
        private void InsertBinarySearchTreeNodes(IDXIndexTreeNode parent, DataTable tab)
        {
            DataRow[] rows = tab.Select("PID=" + parent.NID);
            foreach (DataRow row in rows)
            {
                IDXIndexTreeNode node = new IDXIndexTreeNode();
                node.NID    = (int)row["NID"];
                node.pos    = (int)row["POS"];
                node.Bounds = new Envelope((double)row["minx"], (double)row["miny"], (double)row["maxx"], (double)row["maxy"]);
                InsertBinarySearchTreeNodes(node, tab);

                if (parent.SubNodes == null)
                {
                    parent.SubNodes = new List <IDXIndexTreeNode>();
                }
                parent.SubNodes.Add(node);
            }
        }
示例#2
0
        public IDXIndexTree(string filename)
        {
            FileInfo fi = new FileInfo(filename);

            if (!fi.Exists)
            {
                return;
            }

            _filename = filename;

            StreamReader sr = new StreamReader(filename);
            BinaryReader br = new BinaryReader(sr.BaseStream);

            if (br.ReadInt32() != -999)
            {
                sr.Close();
                return;
            }

            DataTable tab = new DataTable();

            tab.Columns.Add("NID", typeof(int));
            tab.Columns.Add("PID", typeof(int));
            tab.Columns.Add("minx", typeof(double));
            tab.Columns.Add("miny", typeof(double));
            tab.Columns.Add("maxx", typeof(double));
            tab.Columns.Add("maxy", typeof(double));
            tab.Columns.Add("POS", typeof(int));

            int NID;

            while ((NID = br.ReadInt32()) != null)
            {
                if (NID == -999)
                {
                    break;
                }

                DataRow row = tab.NewRow();
                row["NID"]  = NID;
                row["PID"]  = br.ReadInt32();
                row["minx"] = br.ReadDouble();
                row["miny"] = br.ReadDouble();
                row["maxx"] = br.ReadDouble();
                row["maxy"] = br.ReadDouble();
                row["POS"]  = br.BaseStream.Position;

                if ((int)row["NID"] == 0)  // Root;
                {
                    _root        = new IDXIndexTreeNode();
                    _root.NID    = (int)row["NID"];
                    _root.Bounds = new Envelope((double)row["minx"], (double)row["miny"], (double)row["maxx"], (double)row["maxy"]);
                    _root.pos    = (int)row["POS"];
                }
                tab.Rows.Add(row);

                int count = (int)br.ReadInt32();
                br.BaseStream.Position += count * sizeof(int);
            }

            if (_root != null)
            {
                InsertBinarySearchTreeNodes(_root, tab);
            }

            sr.Close();
        }