Exemple #1
0
        public static FeatureCollection FromFlatGeobuf(byte[] bytes)
        {
            var fc = new NetTopologySuite.Features.FeatureCollection();

            var bb = new ByteBuffer(bytes);

            var headerSize = (ulong)ByteBufferUtil.GetSizePrefix(bb);

            bb.Position = FlatBufferConstants.SizePrefixLength;
            var header = Header.GetRootAsHeader(bb);

            var count        = header.FeaturesCount;
            var featuresSize = header.FeaturesSize;
            var nodeSize     = header.IndexNodeSize;

            bb.Position += (int)headerSize;

            var index     = new PackedHilbertRTree(count, nodeSize);
            var indexData = bytes.Skip((int)(headerSize + featuresSize)).Take((int)index.Size).ToArray();

            index.Load(indexData);

            while (count-- > 0)
            {
                var featureLength = ByteBufferUtil.GetSizePrefix(bb);
                bb.Position += FlatBufferConstants.SizePrefixLength;
                var feature = FeatureConversions.FromByteBuffer(bb, header);
                fc.Add(feature);
                bb.Position += featureLength;
            }

            return(fc);
        }
        public void SingleItemRoundtripTest()
        {
            var tree = new PackedHilbertRTree(1);

            tree.Add(0, 0, 1, 1);
            tree.Finish();
            var data = tree.ToBytes();

            Assert.AreEqual(tree.Size, (ulong)data.LongLength);

            var tree2 = new PackedHilbertRTree(1, 16);

            tree2.Load(data);
            var list = tree2.Search(0, 0, 1, 1);

            Assert.AreEqual(1, list.Count);
        }