Ejemplo n.º 1
0
        private static void WritePolygonRecord(string path, List <Shape> shapes)
        {
            using (FileStream fs = new FileStream(path, FileMode.Append))
            {
                FileWriter fw = new FileWriter(fs);

                Dictionary <int, int> index = new ShxFile(path.Replace(Path.GetExtension(path), "") + ".shx").ReadContent();
                int number = 0;
                foreach (var item in index)
                {
                    fw.WriteReverseInt(item.Key, ++number);
                    fw.WriteReverseInt(item.Key + 4, item.Value);

                    fw.WriteInt(item.Key + 8, 3);

                    BoundingBox box = BoundingBox.GetBoundingBox(shapes[number - 1]);
                    fw.WriteDouble(item.Key + 12, box.XMin);
                    fw.WriteDouble(item.Key + 20, box.XMax);
                    fw.WriteDouble(item.Key + 28, box.YMin);
                    fw.WriteDouble(item.Key + 36, box.YMax);

                    fw.WriteInt(item.Key + 44, 1);
                    fw.WriteInt(item.Key + 48, shapes[number - 1].Vertexes.Count);

                    fw.WriteInt(item.Key + 52, 0);

                    for (int i = 0; i < shapes[number - 1].Vertexes.Count; i++)
                    {
                        fw.WriteDouble(item.Key + 56 + i * 16, shapes[number - 1].Vertexes[i].X);
                        fw.WriteDouble(item.Key + 64 + i * 16, shapes[number - 1].Vertexes[i].Y);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        protected static void WritePointRecord(string path, List <Shape> shapes)
        {
            using (FileStream fs = new FileStream(path, FileMode.Append))
            {
                FileWriter fw = new FileWriter(fs);

                for (int i = 0; i < shapes.Count; i++)
                {
                    fw.WriteReverseInt(100 + i * 8, (100 + i * 28) / 2);
                    fw.WriteReverseInt(104 + i * 8, 10);
                }
            }
        }
Ejemplo n.º 3
0
        protected static void WritePolyLineRecord(string path, List <Shape> shapes)
        {
            using (FileStream fs = new FileStream(path, FileMode.Append))
            {
                FileWriter fw = new FileWriter(fs);

                int offset = 0;
                for (int i = 0; i < shapes.Count; i++)
                {
                    fw.WriteReverseInt(100 + i * 8, (100 + offset) / 2);
                    offset += 44 + 4 + 16 * shapes[i].Vertexes.Count + 8;
                    fw.WriteReverseInt(104 + i * 8, (44 + 4 + 16 * shapes[i].Vertexes.Count) / 2);
                }
            }
        }
Ejemplo n.º 4
0
        private static void WritePointRecord(string path, List <Shape> shapes)
        {
            using (FileStream fs = new FileStream(path, FileMode.Append))
            {
                FileWriter fw = new FileWriter(fs);

                for (int i = 0; i < shapes.Count; i++)
                {
                    fw.WriteReverseInt(100 + i * 28, i + 1);
                    fw.WriteReverseInt(104 + i * 28, 10);

                    fw.WriteInt(108 + i * 28, 1);
                    fw.WriteDouble(112 + i * 28, shapes[i].Vertexes[0].X);
                    fw.WriteDouble(120 + i * 28, shapes[i].Vertexes[0].Y);
                }
            }
        }
Ejemplo n.º 5
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 + 8 * shapes.Count) / 2;
                fw.WriteReverseInt(24, fileLength);

                //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);
            }
        }
Ejemplo n.º 6
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);
            }
        }