Exemplo n.º 1
0
        /// <summary>
        /// Read a shapefile Polygon record.                                            POLYGON !!!!!!! Z= 5
        /// </summary>
        /// <param name="stream">Input stream.</param>
        /// <param name="record">Shapefile record to be updated.</param>
        private static void ReadPolygon(Stream stream, ShapeFileRecord record)
        {
            // Bounding Box.
            record.XMin = ShapeFile.ReadDouble64_LE(stream);
            record.YMin = ShapeFile.ReadDouble64_LE(stream);
            //record.ZMin = ShapeFile.ReadDouble64_LE(stream);
            record.XMax = ShapeFile.ReadDouble64_LE(stream);
            record.YMax = ShapeFile.ReadDouble64_LE(stream);
            //record.ZMax = ShapeFile.ReadDouble64_LE(stream);

            // Num Parts and Points.
            int numParts  = ShapeFile.ReadInt32_LE(stream);
            int numPoints = ShapeFile.ReadInt32_LE(stream);

            // Parts.

            for (int i = 0; i < numParts; i++)
            {
                record.Parts.Add(ShapeFile.ReadInt32_LE(stream));
            }

            // Points.
            float a             = 0;
            float b             = 0;
            float c             = 0;
            int   nombrePoint   = 0;
            int   nombrePointDu = 0;

            for (int i = 0; i < numPoints; i++)
            {
                Vector3 p = new Vector3();
                p.x            = (float)ShapeFile.ReadDouble64_LE(stream);
                p.y            = (float)ShapeFile.ReadDouble64_LE(stream);
                p.z            = (float)1;
                nombrePointDu += 1;

                if (p.x != a || p.y != b || p.z != c)
                {
                    record.Points.Add(p);

                    nombrePoint += 1;
                }
                a = p.x;
                b = p.y;
                c = p.z;

                //    if (p.X > XMi - (XMa - XMi) && p.X < XMa +   (XMa - XMi) && p.Y < YMa+YMa-YMi  && p.Y > YMi-YMa +YMi )
                //    {

                //    }
            }
            //Debug.Log("nombre de points non dupliqué"+nombrePoint);
            //Debug.Log("nombre de points total" + nombrePointDu);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Read the file header of the shapefile.
        /// </summary>
        /// <param name="stream">Input stream.</param>
        public void ReadShapeFileHeader(Stream stream)
        {
            // File Code.
            this.fileHeader.FileCode = ShapeFile.ReadInt32_BE(stream);
            if (this.fileHeader.FileCode != ShapeFile.expectedFileCode)
            {
                string msg = String.Format(System.Globalization.CultureInfo.InvariantCulture, "Invalid FileCode encountered. Expecting {0}.", ShapeFile.expectedFileCode);
                throw new ArgumentException(msg);
            }

            // 5 unused values.
            ShapeFile.ReadInt32_BE(stream);
            ShapeFile.ReadInt32_BE(stream);
            ShapeFile.ReadInt32_BE(stream);
            ShapeFile.ReadInt32_BE(stream);
            ShapeFile.ReadInt32_BE(stream);

            // File Length.
            this.fileHeader.FileLength = ShapeFile.ReadInt32_BE(stream);

            // Version.
            this.fileHeader.Version = ShapeFile.ReadInt32_LE(stream);

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

            // Bounding Box.
            this.fileHeader.XMin = ShapeFile.ReadDouble64_LE(stream);
            this.fileHeader.YMin = ShapeFile.ReadDouble64_LE(stream);
            this.fileHeader.XMax = ShapeFile.ReadDouble64_LE(stream);
            this.fileHeader.YMax = ShapeFile.ReadDouble64_LE(stream);

            // Adjust the bounding box in case it is too small.
            if (Math.Abs(this.fileHeader.XMax - this.fileHeader.XMin) < 1)
            {
                this.fileHeader.XMin -= 5;
                this.fileHeader.XMax += 5;
            }
            if (Math.Abs(this.fileHeader.YMax - this.fileHeader.YMin) < 1)
            {
                this.fileHeader.YMin -= 5;
                this.fileHeader.YMax += 5;
            }

            // Skip the rest of the file header.
            stream.Seek(100, SeekOrigin.Begin);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Read a shapefile Point record.                                      POINT !!!! Z = 3
        /// </summary>
        /// <param name="stream">Input stream.</param>
        /// <param name="record">Shapefile record to be updated.</param>
        private static void ReadPoint(Stream stream, ShapeFileRecord record)
        {
            // Points - add a single point.
            //,double XMax,double XMin,double YMax,double YMin
            Vector3 p = new Vector3();

            p.x = (float)ShapeFile.ReadDouble64_LE(stream);
            p.y = (float)ShapeFile.ReadDouble64_LE(stream);
            p.z = 3;

            record.Points.Add(p);

            // Bounding Box.
            record.XMin = p.x;
            record.YMin = p.y;
            //record.ZMin = p.z;
            record.XMax = record.XMin;
            record.YMax = record.YMin;
            // record.ZMax = record.ZMin;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Read a shapefile MultiPoint record.                                    MULTIPOINT !!!!! Z= 4
        /// </summary>
        /// <param name="stream">Input stream.</param>
        /// <param name="record">Shapefile record to be updated.</param>
        private static void ReadMultipoint(Stream stream, ShapeFileRecord record)
        {
            // Bounding Box.
            record.XMin = ShapeFile.ReadDouble64_LE(stream);
            record.YMin = ShapeFile.ReadDouble64_LE(stream);
            //record.ZMin = ShapeFile.ReadDouble64_LE(stream);
            record.XMax = ShapeFile.ReadDouble64_LE(stream);
            record.YMax = ShapeFile.ReadDouble64_LE(stream);
            //record.ZMax = ShapeFile.ReadDouble64_LE(stream);


            // Num Points.
            int numPoints = ShapeFile.ReadInt32_LE(stream);

            // Points.
            for (int i = 0; i < numPoints; i++)
            {
                Vector3 p = new Vector3();
                p.x = (float)ShapeFile.ReadDouble64_LE(stream);
                p.y = (float)ShapeFile.ReadDouble64_LE(stream);
                p.z = 4;
                record.Points.Add(p);
            }
        }