private SbnFeature[] ReadBins(int nid, SbnBinIndex binIndex)
            {
                var numFeatures = binIndex.GetNumFeatures(nid);
                var res         = new SbnFeature[numFeatures];

                if (numFeatures == 0)
                {
                    return(res);
                }

                var firstBinIndex = binIndex.GetFirstBinIndex(nid);
                var numBins       = (int)Math.Ceiling(numFeatures / 100d);

                for (var i = 0; i < numBins; i++)
                {
                    using (var ms = new BinaryReader(new MemoryStream(_tree.GetBinData(firstBinIndex + i))))
                    {
                        var bin   = new SbnBin();
                        var binId = bin.Read(ms);
                        if (binId != firstBinIndex + i)
                        {
                            throw new SbnException("Corrupt sbn file");
                        }
                        bin.CopyTo(res, i * 100);
                    }
                }
                return(res);
            }
Beispiel #2
0
        internal void RemoveFeature(SbnFeature feature)
        {
            var index = FindFeature(feature);

            if (index >= 0)
            {
                RemoveAt(index);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Method to insert a feature to the tree
        /// </summary>
        /// <param name="feature"></param>
        internal void Insert(SbnFeature feature)
        {
            // Insert a feature into the tree
            Root.Insert(feature);
#if (NET40 || NET45)
            _featureIds.Add(feature.Fid);
#else
            _featureIds.Add(feature.Fid, 0);
#endif
        }
Beispiel #4
0
 private int FindFeature(SbnFeature feature)
 {
     for (var i = 0; i < NumFeatures; i++)
     {
         if (this[i].Equals(feature))
         {
             return(i);
         }
     }
     return(-1);
 }
Beispiel #5
0
        /// <summary>
        /// Method to remove the feature <paramref name="fid"/>
        /// </summary>
        /// <param name="fid">The id of the feature</param>
        /// <param name="envelope">The envelope in which to search for the feature</param>
#pragma warning disable 3001
        public void Remove(uint fid, Envelope envelope = null)
#pragma warning restore 3001
        {
            Monitor.Enter(_syncRoot);

            envelope = envelope ?? _header.Extent;
            var searchFeature = new SbnFeature(_header, fid, envelope);

            Root.Remove(searchFeature);

            Monitor.Exit(_syncRoot);
        }
Beispiel #6
0
 private void ReadBuffer(BinaryReader reader)
 {
     using (var msReader = new BinaryReader(new MemoryStream(reader.ReadBytes(NumFeatures * 8))))
     {
         for (var i = 0; i < NumFeatures; i++)
         {
             _features[i] = new SbnFeature(msReader);
         }
     }
     //reader.BaseStream.Read(_buffer, 0, NumFeatures*8);
     //for (var i = 0; i < NumFeatures; i++)
     //    Array.Reverse(_buffer, 4+8*i, 4);
 }
Beispiel #7
0
        internal void RemoveAt(int index)
        {
            if (index < NumFeatures - 1)
            {
                var max = NumFeatures - 1;
                for (var i = index; i < max; i++)
                {
                    _features[i] = _features[i + 1];
                }

                if (_next != null)
                {
                    _features[99] = _next[0];
                    _next.RemoveAt(0);
                }
                else
                {
                    _features[max] = new SbnFeature();
                    NumFeatures--;
                }
            }
            else
            {
                _features[index] = new SbnFeature();
                NumFeatures--;
            }

            //var offset = index * 8;
            //var size = 800 - 8 - offset;
            //if (size > 0)
            //{
            //    //Buffer.BlockCopy(_buffer, offset + 8, _buffer, offset, size);
            //    if (Next != null)
            //    {
            //        this[99] = Next[0];
            //        Next.RemoveFeature(Next[0]);
            //    }
            //    else
            //    {
            //        Buffer.BlockCopy(BitConverter.GetBytes((long)0), 0, _buffer, NumFeatures * 8, 8);
            //        NumFeatures--;
            //    }
            //}
        }
Beispiel #8
0
        /// <summary>
        /// Method to -inplace- rebuild the tree
        /// </summary>
        /// <param name="featureCount">The number of features for the tree</param>
        /// <param name="newFeature">The new feature to add</param>
        private void RebuildTree(int featureCount, SbnFeature newFeature)
        {
            var nodes = Nodes;

            _featureIds.Clear();

            BuildTree(featureCount);

            for (var i = 1; i < nodes.Length; i++)
            {
                foreach (var feature in nodes[i])
                {
                    Insert(feature);
                }
            }
            Insert(newFeature);

            CompactSeamFeatures();
        }
Beispiel #9
0
 internal void AddFeature(SbnFeature feature)
 {
     this[NumFeatures++] = feature;
 }