Represents a record of shape file.
コード例 #1
0
        /// <summary>
        /// Читает запись представляющую коллекцию точек.
        /// </summary>
        /// <param name="file">Входной поток</param>
        /// <param name="record">Запись Shape-файла в которую будет помещена прочитанная информация</param>
        /// <param name="bounds">Ограничивающий прямоугольник, с которым должен пересекаться ограничивающий прямоугольник записи</param>
        public override bool Read(Stream file, BoundingRectangle bounds, ShapeFileRecord record)
        {
            try
            {
                record.MinX = file.ReadDouble();// ShapeFile.ReadDouble64_LE(stream);
                record.MinY = file.ReadDouble();// ShapeFile.ReadDouble64_LE(stream);
                record.MaxX = file.ReadDouble();// ShapeFile.ReadDouble64_LE(stream);
                record.MaxY = file.ReadDouble();// ShapeFile.ReadDouble64_LE(stream);

                int numPoints = file.ReadInt32();// ShapeFile.ReadInt32_LE(stream);

                if (!ShapeHandler.IsRecordInView(bounds, record))
                {
                    file.Seek((long)numPoints * 16, SeekOrigin.Current);
                    return false;
                }

                for (int i = 0; i < numPoints; i++)
                {
                    ICoordinate p =
                        PlanimetryEnvironment.NewCoordinate(
                        file.ReadDouble(),//ShapeFile.ReadDouble64_LE(stream),
                        file.ReadDouble());//ShapeFile.ReadDouble64_LE(stream));

                    record.Points.Add(p);
                }

                return true;
            }
            catch { throw; }
        }
コード例 #2
0
ファイル: ShapeHandler.cs プロジェクト: gkrsu/maparound.core
 /// <summary>Проверка записи на нахождение границ фигуры в указанной области</summary>
 /// <param name="bounds">Границы области</param>
 /// <param name="record">Запись shape-файла</param>
 /// <returns></returns>
 protected static bool IsRecordInView(BoundingRectangle bounds, ShapeFileRecord record)
 {
     if (bounds != null && !bounds.IsEmpty())
     {
         if (!bounds.Intersects(
             new BoundingRectangle(PlanimetryEnvironment.NewCoordinate(record.MinX, record.MinY),
                                   PlanimetryEnvironment.NewCoordinate(record.MaxX, record.MaxY))))
             return false;
     }
     return true;
 }
コード例 #3
0
ファイル: PointHandler.cs プロジェクト: gkrsu/maparound.core
        /// <summary>
        /// Читает запись представляющую точку.
        /// </summary>
        /// <param name="file">Входной поток</param>
        /// <param name="record">Запись Shape-файла в которую будет помещена прочитанная информация</param>
        /// <param name="bounds">Ограничивающий прямоугольник, с которым должен пересекаться ограничивающий прямоугольник записи</param>
        public override bool Read(/*BigEndianBinaryReader*/Stream file, BoundingRectangle bounds, ShapeFileRecord record)
        {

            ICoordinate p = PlanimetryEnvironment.NewCoordinate(0, 0);
            p.X = file.ReadDouble();// ShapeFile.ReadDouble64_LE(stream);
            p.Y = file.ReadDouble();// ShapeFile.ReadDouble64_LE(stream);

            if (bounds != null && !bounds.IsEmpty() && !bounds.ContainsPoint(p))
                return false;

            record.Points.Add(p);

            record.MinX = p.X;
            record.MinY = p.Y;
            record.MaxX = record.MinX;
            record.MaxY = record.MinY;

            return true;
        }
コード例 #4
0
        /// <summary>
        /// Reads a record from the specified stream.
        /// </summary>
        /// <param name="stream">A System.IO.Stream instance to read</param>
        /// <param name="recordOffset">An offset of record</param>
        /// <param name="bounds">An object representing a bounds of the reading area</param>
        public ShapeFileRecord ReadRecord(Stream stream, int?recordOffset, BoundingRectangle bounds)
        {
            #region old

            //if (recordOffset != null)
            //    stream.Seek(recordOffset.Value, 0);

            //ShapeFileRecord record = new ShapeFileRecord();
            //record.Offset = stream.Position;

            //// заголовок записи
            //record.RecordNumber = ShapeFile.ReadInt32_BE(stream);
            //record.ContentLength = ShapeFile.ReadInt32_BE(stream);

            //// тип геометрической фигуры
            //record.ShapeType = ShapeFile.ReadInt32_LE(stream);

            //bool wasRead = false;
            //switch (record.ShapeType)
            //{
            //    case (int)ShapeType.NullShape:
            //        break;
            //    case (int)ShapeType.Point:
            //        wasRead = ShapeFile.ReadPoint(stream, bounds, record);
            //        break;
            //    case (int)ShapeType.PolyLine:
            //        wasRead = ShapeFile.ReadPolygon(stream, bounds, record);
            //        break;
            //    case (int)ShapeType.Polygon:
            //        wasRead = ShapeFile.ReadPolygon(stream, bounds, record);
            //        break;
            //    case (int)ShapeType.Multipoint:
            //        wasRead = ShapeFile.ReadMultipoint(stream, bounds, record);
            //        break;
            //    default:
            //        {
            //            string msg = String.Format(System.Globalization.CultureInfo.InvariantCulture, "ShapeType {0} is not supported.", (int)record.ShapeType);
            //            throw new InvalidDataException(msg);
            //        }
            //}

            //if (wasRead)
            //{
            //    this._records.Add(record);
            //    return record;
            //}
            //else return null;

            #endregion

            #region New

            if (recordOffset != null)
            {
                stream.Seek(recordOffset.Value, 0);
            }

            ShapeFileRecord record = new ShapeFileRecord();
            record.Offset = stream.Position;

            // заголовок записи
            //BigEndianBinaryReader reader = new BigEndianBinaryReader(stream);
            //record.RecordNumber = reader.ReadInt32BE();// ShapeFile.ReadInt32_BE(stream);
            //record.ContentLength = reader.ReadInt32BE();// ShapeFile.ReadInt32_BE(stream);
            record.RecordNumber  = stream.ReadInt32BE();   // ShapeFile.ReadInt32_BE(stream);
            record.ContentLength = stream.ReadInt32BE();   // ShapeFile.ReadInt32_BE(stream);


            // тип геометрической фигуры
            record.ShapeType = stream.ReadInt32();    //.ReadInt32BE();// ShapeFile.ReadInt32_LE(stream);


            ShapeHandler handler = ShapeFile.GetShapeHandler((ShapeType)record.ShapeType);

            if (handler.Read(stream, bounds, record))
            {
                this._records.Add(record);
                return(record);
            }
            else
            {
                return(null);
            }

            #endregion
        }
コード例 #5
0
ファイル: ShapeHandler.cs プロジェクト: gkrsu/maparound.core
 /// <summary>
 /// Читать потока данные по геометрическому объекту и заполнять запись shape-файла 
 /// </summary>
 /// <param name="file">Входной поток для чтения</param>
 /// <param name="bounds">Ограничивающий прямоугольник, с которым должен пересекаться ограничивающий прямоугольник записи</param>
 /// <param name="Record">Запись Shape-файла в которую будет помещена прочитанная информация</param>
 /// <returns>Успешность операции</returns>
 public abstract bool Read(Stream file, BoundingRectangle bounds, ShapeFileRecord Record);
コード例 #6
0
ファイル: ShapeFile.cs プロジェクト: gkrsu/maparound.core
        /// <summary>
        /// Reads a record from the specified stream.
        /// </summary>
        /// <param name="stream">A System.IO.Stream instance to read</param>
        /// <param name="recordOffset">An offset of record</param>
        /// <param name="bounds">An object representing a bounds of the reading area</param>
        public ShapeFileRecord ReadRecord(Stream stream, int? recordOffset, BoundingRectangle bounds)
        {
                #region old

                //if (recordOffset != null)
                //    stream.Seek(recordOffset.Value, 0);

                //ShapeFileRecord record = new ShapeFileRecord();
                //record.Offset = stream.Position;

                //// заголовок записи
                //record.RecordNumber = ShapeFile.ReadInt32_BE(stream);
                //record.ContentLength = ShapeFile.ReadInt32_BE(stream);

                //// тип геометрической фигуры
                //record.ShapeType = ShapeFile.ReadInt32_LE(stream);

                //bool wasRead = false;
                //switch (record.ShapeType)
                //{
                //    case (int)ShapeType.NullShape:
                //        break;
                //    case (int)ShapeType.Point:
                //        wasRead = ShapeFile.ReadPoint(stream, bounds, record);
                //        break;
                //    case (int)ShapeType.PolyLine:
                //        wasRead = ShapeFile.ReadPolygon(stream, bounds, record);
                //        break;
                //    case (int)ShapeType.Polygon:
                //        wasRead = ShapeFile.ReadPolygon(stream, bounds, record);
                //        break;
                //    case (int)ShapeType.Multipoint:
                //        wasRead = ShapeFile.ReadMultipoint(stream, bounds, record);
                //        break;
                //    default:
                //        {
                //            string msg = String.Format(System.Globalization.CultureInfo.InvariantCulture, "ShapeType {0} is not supported.", (int)record.ShapeType);
                //            throw new InvalidDataException(msg);
                //        }
                //}

                //if (wasRead)
                //{
                //    this._records.Add(record);
                //    return record;
                //}
                //else return null;

                #endregion

                #region New

                if (recordOffset != null)
                    stream.Seek(recordOffset.Value, 0);

                ShapeFileRecord record = new ShapeFileRecord();
                record.Offset = stream.Position;

                // заголовок записи
                //BigEndianBinaryReader reader = new BigEndianBinaryReader(stream);
                //record.RecordNumber = reader.ReadInt32BE();// ShapeFile.ReadInt32_BE(stream);
                //record.ContentLength = reader.ReadInt32BE();// ShapeFile.ReadInt32_BE(stream);
                record.RecordNumber = stream.ReadInt32BE();// ShapeFile.ReadInt32_BE(stream);
                record.ContentLength = stream.ReadInt32BE();// ShapeFile.ReadInt32_BE(stream);


                // тип геометрической фигуры
                record.ShapeType = stream.ReadInt32();//.ReadInt32BE();// ShapeFile.ReadInt32_LE(stream);


                ShapeHandler handler = ShapeFile.GetShapeHandler((ShapeType)record.ShapeType);

                if (handler.Read(stream, bounds, record))
                {
                    this._records.Add(record);
                    return record;
                }
                else return null;

                #endregion
        }
コード例 #7
0
        private IGeometry geometryFromShapeRecord(ShapeFileRecord record)
        {
            switch (record.ShapeType)
            {
                // point
                case 1:
                    return new PointD(record.Points[0].X, record.Points[0].Y);
                // polyline
                case 3:
                    Polyline polyline = new Polyline();
                    for (int i = 0; i < record.Parts.Count; i++)
                    {
                        LinePath path = new LinePath();
                        int j;
                        for (j = record.Parts[i]; j < (i == record.Parts.Count - 1 ? record.Points.Count : record.Parts[i + 1]); j++)
                            path.Vertices.Add(PlanimetryEnvironment.NewCoordinate(record.Points[j].X, record.Points[j].Y));

                        polyline.Paths.Add(path);
                    }
                    return polyline;
                // ground
                case 5:
                    Polygon p = new Polygon();
                    for (int i = 0; i < record.Parts.Count; i++)
                    {
                        Contour contour = new Contour();
                        int j;
                        for (j = record.Parts[i]; j < (i == record.Parts.Count - 1 ? record.Points.Count : record.Parts[i + 1]); j++)
                            contour.Vertices.Add(PlanimetryEnvironment.NewCoordinate(record.Points[j].X, record.Points[j].Y));

                        contour.Vertices.RemoveAt(contour.Vertices.Count - 1);
                        p.Contours.Add(contour);
                    }
                    if (p.CoordinateCount > 0)
                        return p;
                    else
                        return null;
                // set of points
                case 8:
                    MultiPoint mp = new MultiPoint();
                    for (int i = 0; i < record.Points.Count; i++)
                        mp.Points.Add(PlanimetryEnvironment.NewCoordinate(record.Points[i].X, record.Points[i].Y));
                    return mp;
            }

            return null;
        }