public IShxRecord ReadRecord(int recordIndex) { var recordOffset = GetRecordOffset(recordIndex); var shxRecordField = new ShxRecordField(recordOffset); return(shxRecordField.Read(BinaryReader)); }
public IShapefileRecord <T> Write(T shape) { //TODO: Write BoundingBox merge method(s)... dynamic shapeBox = shape.Box; if (BoundingBox == null) { BoundingBox = new BoundingBox <PointZ>() { Min = new PointZ(shapeBox.Min), Max = new PointZ(shapeBox.Max) }; } else { BoundingBox.Min.Minimize(shapeBox.Min); BoundingBox.Max.Maximize(shapeBox.Max); } var shpRecordOffset = WordCount.FromBytes(ShpWriter.BaseStream.Position); var shpContentOffset = shpRecordOffset + ShpRecordHeaderField.FieldLength; var record = new ShapefileRecord <T>() { RecordNumber = RecordNumber, Shape = shape }; //TODO: Write the SHP header first... // But we have to write the shape, to figure out its length, to add the length to the header... var shapeField = new ShapeField(shpContentOffset); shapeField.Write(ShpWriter, shape); var shpStreamLengthAfterRecordWrite = ShpWriter.BaseStream.Length; var shpHeader = new ShpRecordHeader() { //TODO: The shapeField should just have a Length... vs assuming the writer will be at the correct length... ContentLength = WordCount.FromBytes(shpStreamLengthAfterRecordWrite) - shpContentOffset, RecordNumber = RecordNumber }; var shpHeaderField = new ShpRecordHeaderField(shpRecordOffset); shpHeaderField.Write(ShpWriter, shpHeader); //Reset so we are at the correct position for the next shape... ShpWriter.BaseStream.Position = shpStreamLengthAfterRecordWrite; var shxRecord = new ShxRecord() { Offset = shpRecordOffset, ContentLength = WordCount.FromBytes((int)ShpWriter.BaseStream.Position) - shpRecordOffset }; var shxRecordField = new ShxRecordField(WordCount.FromBytes(ShxWriter.BaseStream.Position)); shxRecordField.Write(ShxWriter, shxRecord); RecordNumber++; return(record); }