Esempio n. 1
0
        protected ShpReader(string fileName, ShapeType type)
        {
            //this.directoryName = System.IO.Path.GetDirectoryName(fileName);

            //this.fileNameWithoutExtension = System.IO.Path.GetFileNameWithoutExtension(fileName);

            if (!Shapefile.CheckAllNeededFilesExists(fileName))
            {
                throw new NotImplementedException();
            }

            ShxReader shxFile = new ShxReader(Shapefile.GetShxFileName(fileName));

            using (System.IO.FileStream shpStream = new System.IO.FileStream(fileName, System.IO.FileMode.Open))
            {
                using (this.shpReader = new System.IO.BinaryReader(shpStream))
                {
                    this.MainHeader = new MainFileHeader(this.shpReader.ReadBytes(ShapeConstants.MainHeaderLengthInBytes));

                    if ((ShapeType)this.MainHeader.ShapeType != type)
                    {
                        throw new NotImplementedException();
                    }

                    if (!MainFileHeader.CanBeForTheSameShapefile(this.MainHeader, shxFile.MainHeader))
                    {
                        throw new NotImplementedException();
                    }

                    this.elements = new ShapeCollection <T>(this.MainHeader);

                    int numberOfRecords = shxFile.NumberOfRecords;

                    for (int i = 0; i < numberOfRecords; i++)
                    {
                        int offset, contentLength02;

                        shxFile.GetRecord(i, out offset, out contentLength02);

                        shpReader.BaseStream.Position = offset * 2;

                        int recordNumber, contentLength;

                        ReadRecordHeader(out recordNumber, out contentLength);

                        if (contentLength != contentLength02)
                        {
                            System.Diagnostics.Trace.WriteLine("ERROR at contentLength != contentLength02: i=" + i.ToString());
                            //throw new NotImplementedException();
                        }

                        if (contentLength == 2)
                        {
                            continue;
                        }

                        elements.Add(ReadElement());

                        //4:                length of the record header in words
                        //contentLength:    length of the contents in words
                        //this.tempPosition = this.tempPosition - (ShapeConstants.RecordHeaderLengthInWords + contentLength);
                    }
                }
            }
        }