Ejemplo n.º 1
0
        public override byte[] ToWellKnownBinary()
        {
            /// 0103000000 01000000 03000000 BF9EAF592E1BDBBF 6F445AD726844A40 BF9EAF592E1BDBBF
            ///         00000001  - number of rings
            ///         00000003  - number of points in ring
            /// BF9EAF592E1BDBBF  - point 1
            /// 6F445AD726844A40  - point 2
            /// BF9EAF592E1BDBBF  - point 3

            int             numberOfRings  = Rings.Count();
            int             numberOfPoints = Rings.Sum(x => x.Points.Count());
            WellKnownBinary wkb            = WellKnownBinary.Allocate(GeometryType.Polygon, 9 + (numberOfRings * 4) + (numberOfPoints * 8));

            wkb.AddRange(BitConverter.GetBytes(numberOfRings));

            foreach (var ring in Rings)
            {
                wkb.AddRange(BitConverter.GetBytes(ring.Points.Count()));

                foreach (var point in ring.Points)
                {
                    wkb.AddRange(BitConverter.GetBytes(point.Longitude));
                    wkb.AddRange(BitConverter.GetBytes(point.Latitude));
                }
            }

            return(wkb.ToArray());
        }
Ejemplo n.º 2
0
        public override byte[] ToWellKnownBinary()
        {
            /// 0101000000 BF9EAF592E1BDBBF 6F445AD726844A40
            /// BF9EAF592E1BDBBF  - longitude
            /// 6F445AD726844A40  - latitude

            WellKnownBinary wkb = WellKnownBinary.Allocate(GeometryType.Point, 21);

            wkb.AddRange(BitConverter.GetBytes(Longitude));
            wkb.AddRange(BitConverter.GetBytes(Latitude));

            return(wkb.ToArray());
        }
Ejemplo n.º 3
0
        public override byte[] ToWellKnownBinary()
        {
            /// 0102000000 03000000 BF9EAF592E1BDBBF 6F445AD726844A40 BF9EAF592E1BDBBF
            ///         03000000  - number of points
            /// BF9EAF592E1BDBBF  - point 1
            /// 6F445AD726844A40  - point 2
            /// BF9EAF592E1BDBBF  - point 3

            int             numberOfPoints = Points.Count();
            WellKnownBinary wkb            = WellKnownBinary.Allocate(GeometryType.LineString, 9 + (numberOfPoints * 8));

            wkb.AddRange(BitConverter.GetBytes(numberOfPoints));

            foreach (var point in Points)
            {
                wkb.AddRange(BitConverter.GetBytes(point.Longitude));
                wkb.AddRange(BitConverter.GetBytes(point.Latitude));
            }

            return(wkb.ToArray());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a well-known binary buffer, pre-populated with the byte order and geometry type
        /// </summary>
        /// <param name="geometryType">Geometry type to write into the buffer</param>
        /// <param name="capacity">The number of bytes that the new instance can initially store</param>
        /// <returns>A WellKnownBinary instance, pre-populated with the byte order and geometry type</returns>
        public static WellKnownBinary Allocate(GeometryType geometryType, int capacity)
        {
            /// 01                - refers to the byte order; 0x01 is for little endian
            /// 01000000          - geometry type; 0x01 is a Point
            ///

            WellKnownBinary wkb = new WellKnownBinary(capacity);

            wkb.Add(BitConverter.IsLittleEndian ? LittleEndian : BigEndian);
            wkb.AddRange(BitConverter.GetBytes((int)geometryType));

            return(wkb);
        }