示例#1
0
        /// <summary>
        /// Parses data from the binnary array.
        /// </summary>
        /// <param name="wkb">The binary array with WKB serialized geometry.</param>
        /// <returns>Parsed geometry.</returns>
        /// <exception cref="WkbFormatException">Throws exception if wkb array does not contrains valid WKB geometry.</exception>
        public static Geometry Parse(byte[] wkb)
        {
            if (wkb == null)
            {
                throw new ArgumentNullException("wkb");
            }

            using (MemoryStream ms = new MemoryStream(wkb)) {
                using (BinaryReader reader = new BinaryReader(ms)) {
                    if (reader.PeekChar() == -1)
                    {
                        return(null);
                    }

                    try {
                        BinaryEncoding encoding = (BinaryEncoding)reader.ReadByte();
                        if (encoding == BinaryEncoding.BigEndian)
                        {
                            throw new NotSupportedException("Big endian encoding is not supprted in the current version of WkbReader.");
                        }

                        Geometry parsed = WkbReader.ReadGeometry(reader);

                        return(parsed);
                    }
                    catch (EndOfStreamException) {
                        throw new WkbFormatException("End of stream reached before end of valid WKB geometry end.");
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Reads GeometryCollection from the reader.
        /// </summary>
        /// <param name="reader">The reader used to read data from input stream.</param>
        /// <param name="is3D">bool value indicating whether GeometryCollection beeing read has Z-dimension.</param>
        /// <param name="isMeasured">bool value indicating whether GeometryCollection beeing read has M-value.</param>
        /// <returns>GeometryCollection read from the input.</returns>
        private static GeometryCollection <Geometry> ReadGeometryCollection(BinaryReader reader, bool is3D, bool isMeasured)
        {
            int pointsCount = (int)reader.ReadUInt32();

            GeometryCollection <Geometry> result = new GeometryCollection <Geometry>();

            for (int i = 0; i < pointsCount; i++)
            {
                result.Geometries.Add(WkbReader.ReadGeometry(reader));
            }

            return(result);
        }
示例#3
0
        /// <summary>
        /// Read geometry in WKB format from the input.
        /// </summary>
        /// <returns>Parsed geometry or null if no other geometry is available.</returns>
        public Geometry Read()
        {
            if (_inputReader.PeekChar() == -1)
            {
                return(null);
            }

            try {
                BinaryEncoding encoding = (BinaryEncoding)_inputReader.ReadByte();
                if (encoding == BinaryEncoding.BigEndian)
                {
                    throw new NotSupportedException("Big endian encoding is not supprted in the current version of WkbReader.");
                }

                return(WkbReader.ReadGeometry(_inputReader));
            }
            catch (EndOfStreamException) {
                throw new WkbFormatException("End of stream reached before end of valid WKB geometry end.");
            }
        }