Example #1
0
        /// <summary>
        /// Read a shapefile record.
        /// </summary>
        /// <param name="stream">Input stream.</param>
        public ShapeFileRecord ReadShapeFileRecord(Stream stream)
        {
            ShapeFileRecord record = new ShapeFileRecord();

            // Record Header.
            record.RecordNumber  = ShapeFile.ReadInt32_BE(stream);
            record.ContentLength = ShapeFile.ReadInt32_BE(stream);

            // Shape Type.
            record.ShapeType = ShapeFile.ReadInt32_LE(stream);

            // Read the shape geometry, depending on its type.
            switch (record.ShapeType)
            {
            case (int)ShapeType.NullShape:
                // Do nothing.
                break;

            case (int)ShapeType.Point:
                ShapeFile.ReadPoint(stream, record);
                break;

            case (int)ShapeType.PolyLine:
                // PolyLine has exact same structure as Polygon in shapefile.
                ShapeFile.ReadPolygon(stream, record);
                break;

            case (int)ShapeType.Polygon:
                ShapeFile.ReadPolygon(stream, record);
                break;

            case (int)ShapeType.Multipoint:
                ShapeFile.ReadMultipoint(stream, record);
                break;

            default:
            {
                string msg = String.Format(System.Globalization.CultureInfo.InvariantCulture, "ShapeType {0} is not supported.", (int)record.ShapeType);
                throw new ApplicationException(msg);
            }
            }

            // Add the record to our internal list.
            this.records.Add(record);

            return(record);
        }