Beispiel #1
0
        protected static void WriteHeader(string path, BoundingBox boundingBox, List <Shape> shapes)
        {
            using (FileStream fs = new FileStream(path, FileMode.Create))
            {
                FileWriter fw = new FileWriter(fs);

                //Write header
                //Write file code
                fw.WriteReverseInt(0, 9994);

                //Write unused fields
                for (int i = 0; i < 4; i++)
                {
                    fw.WriteReverseInt(i * 4 + 4, 0);
                }

                //Write file length
                int fileLength = 100;
                switch (shapes[0].Type)
                {
                case ShapeType.NullType:
                    break;

                case ShapeType.Point:
                    fileLength += shapes.Count * 28;
                    break;

                case ShapeType.PolyLine:
                    for (int i = 0; i < shapes.Count; i++)
                    {
                        fileLength += 44 + 4 + 16 * shapes[i].Vertexes.Count + 8;
                    }
                    break;

                case ShapeType.Polygon:
                    break;

                default:
                    break;
                }
                fw.WriteReverseInt(24, fileLength / 2);

                //Write version
                fw.WriteInt(28, 1000);

                //Write shape type
                if (shapes == null)
                {
                    fw.WriteInt(32, 0);
                }
                else
                {
                    fw.WriteInt(32, (int)shapes[0].Type);
                }

                //Write bounding box
                fw.WriteDouble(36, boundingBox.XMin);
                fw.WriteDouble(44, boundingBox.YMin);
                fw.WriteDouble(52, boundingBox.XMax);
                fw.WriteDouble(60, boundingBox.YMax);
                fw.WriteDouble(68, 0);
                fw.WriteDouble(76, 0);
                fw.WriteDouble(84, 0);
                fw.WriteDouble(92, 0);
            }
        }