コード例 #1
0
        /// <summary>
        /// Reads the header of a Shapefile
        /// </summary>
        /// <param name="reader">The Shapefile stream</param>
        /// <returns>The shapefile header</returns>
        private void ReadFileHeader(BinaryReader reader, out ShapefileShapeType shapeType, out BoundingBox bounds)
        {
            // Read File Code.
            int FileCode = NumberReader.ReadIntBE(reader);

            //Verify that the file has the correct file code (9994)
            if (FileCode != 9994)
            {
                throw new FormatException("Invalid FileCode encountered. Expecting a file code of 9994.");
            }

            //Skip unused section
            reader.BaseStream.Seek(20, SeekOrigin.Current);

            // Read the File Length.
            long fileLength = NumberReader.ReadIntBE(reader);

            // Skip the Version number of the shapefile.
            reader.BaseStream.Seek(4, SeekOrigin.Current);

            // Get the shape type of the shapefile. Note that shapefiles can only contain one type of shape per file
            shapeType = (ShapefileShapeType)NumberReader.ReadIntLE(reader);

            // Get the bounding box of the Bounding Box.
            bounds = ReadBoundingBox(reader);
        }
コード例 #2
0
 /// <summary>
 /// Reads the header of the shapefile
 /// </summary>
 /// <param name="reader">A Shapefile as a BinaryReader</param>
 /// <param name="shapeType">The type of shapes contained in the Shapefile.</param>
 /// <param name="bounds">Bounding box of the shapes in the Shapefile.</param>
 public void ReadHeader(BinaryReader reader, out ShapefileShapeType shapeType, out BoundingBox bounds)
 {
     using (reader)
     {
         // Read the File Header.
         ReadFileHeader(reader, out shapeType, out bounds);
     }
 }
コード例 #3
0
 /// <summary>
 /// Reads the header of the shapefile
 /// </summary>
 /// <param name="stream">A Shapefile as a Stream</param>
 /// <param name="shapeType">The type of shapes contained in the Shapefile.</param>
 /// <param name="bounds">Bounding box of the shapes in the Shapefile.</param>
 public void ReadHeader(Stream stream, out ShapefileShapeType shapeType, out BoundingBox bounds)
 {
     using (BinaryReader reader = new BinaryReader(stream))
     {
         // Read the File Header.
         ReadFileHeader(reader, out shapeType, out bounds);
     }
 }
コード例 #4
0
        /// <summary>
        /// Reads all shapes in the Shapefile
        /// </summary>
        /// <param name="reader">The Shapefile stream</param>
        /// <param name="shapeType">The type of shape to read</param>
        /// <returns>A list of Geometry objects</returns>
        private async Task <List <Geometry> > ReadShapeRecords(BinaryReader reader, ShapefileShapeType shapeType)
        {
            List <Geometry> items = null;

            // Skip the end of the file header.
            reader.BaseStream.Seek(100, SeekOrigin.Begin);

            // Read the shapes depending on the ShapeType.
            switch (shapeType)
            {
            case ShapefileShapeType.NullShape:     // Do nothing.
                break;

            case ShapefileShapeType.Point:
            case ShapefileShapeType.PointZ:
            case ShapefileShapeType.PointM:
            case ShapefileShapeType.PointZM:
                items = ReadPointData(reader);
                break;

            case ShapefileShapeType.LineString:
            case ShapefileShapeType.LineStringZ:
            case ShapefileShapeType.LineStringM:
            case ShapefileShapeType.LineStringZM:
                items = await ReadLineStringData(reader);

                break;

            case ShapefileShapeType.Polygon:
            case ShapefileShapeType.PolygonZ:
            case ShapefileShapeType.PolygonM:
            case ShapefileShapeType.PolygonZM:
                items = ReadPolygonData(reader);
                break;

            case ShapefileShapeType.MultiPoint:
            case ShapefileShapeType.MultiPointZ:
            case ShapefileShapeType.MultiPointM:
            case ShapefileShapeType.MultiPointZM:
                items = ReadMultiPointData(reader);
                break;

            default:        //throw an error indicating that an unsupported shape type is in the file
                throw new Exception("ShapeType " + shapeType.ToString() + " is not supported.");
            }

            return(items);
        }