Esempio n. 1
0
        public EsriShapeCollection(IEnumerable <T> values)
        {
            if (typeof(T) is IRI.Ket.ShapefileFormat.EsriType.IEsriPointsWithMeasure)
            {
                throw new NotImplementedException();
            }

            if (values.Select(i => i.Type).Distinct().Count() > 1)
            {
                throw new NotImplementedException();
            }

            this.AddRange(values);

            ////////this.mainHeader = new MainFileHeader(length, values[0].Type, minimumBoundingBox);

            var minimumBoundingBox = IRI.Msh.Common.Primitives.BoundingBox.GetMergedBoundingBox(values.Select(i => i.MinimumBoundingBox));

            //The content length for a record is the length of the record contents section measured in
            //16-bit words. Each record, therefore, contributes (4 + content length) 16-bit words
            //toward the total length of the file, as stored at Byte 24 in the file header.
            var length = values.Sum(i => i.ContentLength + 4);

            this.mainHeader = new MainFileHeader(length, values.First().Type, minimumBoundingBox);
        }
Esempio n. 2
0
        public ShxReader(string shxFileName)
        {
            if (!System.IO.File.Exists(shxFileName))
            {
                throw new NotImplementedException();
            }

            this.Offsets = new List <int>();

            this.ContentLengthes = new List <int>();

            System.IO.FileStream stream = new System.IO.FileStream(shxFileName, System.IO.FileMode.Open);

            System.IO.BinaryReader reader = new System.IO.BinaryReader(stream);

            this.mainHeader = new MainFileHeader(reader.ReadBytes(ShapeConstants.MainHeaderLengthInBytes));

            double numberOfRecords = (mainHeader.FileLength - 50) / 4.0;

            for (int i = 0; i < numberOfRecords; i++)
            {
                byte[] temp = reader.ReadBytes(ShapeConstants.IntegerSize); Array.Reverse(temp);

                this.Offsets.Add(System.BitConverter.ToInt32(temp, 0));

                temp = reader.ReadBytes(ShapeConstants.IntegerSize); Array.Reverse(temp);

                this.ContentLengthes.Add(System.BitConverter.ToInt32(temp, 0));
            }

            reader.Close();

            stream.Close();
        }
Esempio n. 3
0
        public EsriShapeCollection(MainFileHeader header, List <T> values)
        {
            this.AddRange(values);

            this.mainHeader = header;
        }
Esempio n. 4
0
 public EsriShapeCollection(MainFileHeader header)
 {
     this.mainHeader = header;
 }
Esempio n. 5
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);
                    }
                }
            }
        }