コード例 #1
0
        /// <summary>
        /// Reads the entire index file in order to get a breakdown of how shapes are broken up.
        /// </summary>
        /// <param name="fileName">A string fileName of the .shx file to read.</param>
        /// <returns>A List of ShapeHeaders that give offsets and lengths so that reading can be optimized</returns>
        protected List <ShapeHeader> ReadIndexFile(string fileName)
        {
            string shxFilename = fileName;
            string ext         = Path.GetExtension(fileName);

            if (ext != ".shx")
            {
                shxFilename = Path.ChangeExtension(fileName, ".shx");
            }

            if (shxFilename == null)
            {
                throw new NullReferenceException(fileName);
            }

            if (File.Exists(shxFilename) == false)
            {
                throw new FileNotFoundException(fileName);
            }

            // This will store the header elements that we read from the file.
            List <ShapeHeader> result = new List <ShapeHeader>();

            // Use a the length of the file to dimension the byte array
            BufferedBinaryReader bbReader = new BufferedBinaryReader(shxFilename);

            if (bbReader.FileLength == 100)
            {
                // the file is empty, so we are done
                bbReader.Close();
                return(result);
            }

            // Skip the header and begin reading from the first record
            bbReader.Seek(100, SeekOrigin.Begin);

            Header.ShxLength = (int)bbReader.FileLength / 2;
            long length = bbReader.FileLength - 100;

            long numRecords = length / 8; // Each record consists of 2 Big-endian integers for a total of 8 bytes.

            for (long i = 0; i < numRecords; i++)
            {
                ShapeHeader sh = new ShapeHeader
                {
                    Offset        = bbReader.ReadInt32(false),
                    ContentLength = bbReader.ReadInt32(false)
                };
                result.Add(sh);
            }

            bbReader.Close();
            return(result);
        }
コード例 #2
0
ファイル: Shapefile.cs プロジェクト: DIVEROVIEDO/DotSpatial
        /// <summary>
        /// Reads the entire index file in order to get a breakdown of how shapes are broken up.
        /// </summary>
        /// <param name="fileName">A string fileName of the .shx file to read.</param>
        /// <returns>A List of ShapeHeaders that give offsets and lengths so that reading can be optimized</returns>
        public List<ShapeHeader> ReadIndexFile(string fileName)
        {
            string shxFilename = fileName;
            string ext = Path.GetExtension(fileName);

            if (ext != ".shx")
            {
                shxFilename = Path.ChangeExtension(fileName, ".shx");
            }
            if (shxFilename == null)
            {
                throw new NullReferenceException(DataStrings.ArgumentNull_S.Replace("%S", fileName));
            }

            if (File.Exists(shxFilename) == false)
            {
                throw new FileNotFoundException(DataStrings.FileNotFound_S.Replace("%S", fileName));
            }

            // This will store the header elements that we read from the file.
            List<ShapeHeader> result = new List<ShapeHeader>();

            // Use a the length of the file to dimension the byte array
            BufferedBinaryReader bbReader = new BufferedBinaryReader(shxFilename);

            if (bbReader.FileLength == 100)
            {
                // the file is empty, so we are done
                bbReader.Close();
                return result;
            }

            // Skip the header and begin reading from the first record
            bbReader.Seek(100, SeekOrigin.Begin);

            _header.ShxLength = (int)bbReader.FileLength / 2;
            long length = bbReader.FileLength - 100;

            long numRecords = length / 8; // Each record consists of 2 Big-endian integers for a total of 8 bytes.
            for (long i = 0; i < numRecords; i++)
            {
                ShapeHeader sh = new ShapeHeader
                                 {
                                     Offset = bbReader.ReadInt32(false),
                                     ContentLength = bbReader.ReadInt32(false)
                                 };
                result.Add(sh);
            }
            bbReader.Close();
            return result;
        }