Пример #1
0
        /// <summary>
        /// Adds elevation.
        /// </summary>
        public void AddElevation(ElevationHandler.GetElevationDelegate getElevationFunc)
        {
            if (_elevation == null)
            {
                _elevation = _createElevation(_coordinates.Length / 2);
            }

            for (var i = 0; i < _index.Length; i++)
            {
                ShapesArray.ExtractPointerAndSize(_index[i], out var pointer, out var size);
                if (size > 0)
                {
                    for (var p = 0; p < size; p++)
                    {
                        var lat = _coordinates[pointer + (p * 2)];
                        var lon = _coordinates[pointer + (p * 2) + 1];

                        var e = getElevationFunc(lat, lon);
                        if (e.HasValue)
                        {
                            _elevation[pointer / 2 + p] = e.Value;
                        }
                        else
                        {
                            _elevation[pointer / 2 + p] = NO_ELEVATION;
                        }
                    }
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Gets the index and the size (if any).
 /// </summary>
 private void GetPointerAndSize(long id, out long pointer, out int size)
 {
     if (id >= _index.Length)
     {
         pointer = -1;
         size    = -1;
         return;
     }
     ShapesArray.ExtractPointerAndSize(_index[id], out pointer, out size);
 }
Пример #3
0
        /// <summary>
        /// Copies to the given stream.
        /// </summary>
        public override long CopyTo(Stream stream)
        {
            var initialPosition = stream.Position;

            stream.Write(BitConverter.GetBytes(_index.Length), 0, 8);
            stream.Seek(stream.Position + 8, System.IO.SeekOrigin.Begin); // leave room for the coordinates-size.

            // rewrite the coordinates array in the process removing all empty spaces after removing items.
            var  position            = stream.Position;
            var  coordinatesPosition = position + (_index.Length * 8);
            long newPointer          = 0;

            using (var indexStream = new BinaryWriter(new LimitedStream(stream, position)))
            {
                using (var coordinatesStream = new BinaryWriter(new LimitedStream(stream, coordinatesPosition)))
                {
                    long pointer;
                    int  size;
                    for (var i = 0; i < _index.Length; i++)
                    {
                        coordinatesStream.SeekBegin(newPointer * 4);
                        ShapesArray.ExtractPointerAndSize(_index[i], out pointer, out size);
                        if (size > 0)
                        {
                            for (var p = 0; p < size; p++)
                            {
                                coordinatesStream.Write(_coordinates[pointer + (p * 2)]);
                                coordinatesStream.Write(_coordinates[pointer + (p * 2) + 1]);
                            }

                            indexStream.SeekBegin(i * 8);
                            indexStream.Write(ShapesArray.BuildPointerAndSize(newPointer, size));
                            newPointer += size * 2;
                        }
                        else
                        {
                            indexStream.SeekBegin(i * 8);
                            indexStream.Write((ulong)0);
                        }
                    }
                }
            }

            // write coordinates size.
            stream.Seek(initialPosition + 8, System.IO.SeekOrigin.Begin);
            stream.Write(BitConverter.GetBytes(newPointer), 0, 8);

            // seek until after.
            var sizeInBytes = 16 + (_index.Length * 8) + (newPointer * 4);

            stream.Seek(initialPosition + sizeInBytes, System.IO.SeekOrigin.Begin);
            return(sizeInBytes);
        }
Пример #4
0
 /// <summary>
 /// Deserializes an shapes index from the given stream.
 /// </summary>
 public static ShapesArray CreateFrom(Stream stream, bool copy, bool hasElevation = false)
 {
     return(ShapesArray.CreateFrom(stream, copy, out var _, hasElevation));
 }
Пример #5
0
 /// <summary>
 /// Sets the index and size.
 /// </summary>
 private void SetPointerAndSize(long id, long pointer, int size)
 {
     _index[id] = ShapesArray.BuildPointerAndSize(pointer, size);
 }
Пример #6
0
 /// <summary>
 /// Adds a new shape.
 /// </summary>
 public static void Set(this ShapesArray index, long id, params Coordinate[] shape)
 {
     index[id] = new ShapeEnumerable(shape);
 }
Пример #7
0
        /// <summary>
        /// Deserializes an shapes index from the given stream.
        /// </summary>
        public static ShapesArray CreateFrom(Stream stream, bool copy)
        {
            long size;

            return(ShapesArray.CreateFrom(stream, copy, out size));
        }