/// <summary> /// Computes the WKB representation of a coordinate list. /// </summary> /// <param name="byteArray">The byte-array.</param> /// <param name="byteIndex">The starting index.</param> /// <param name="byteOrder">The byte-order of the conversion.</param> /// <param name="coordinateList">The coordinate list.</param> /// <param name="geometryModel">The geometry model of the conversion.</param> private static void ComputeCoordinateList(Byte[] byteArray, ref Int32 byteIndex, ByteOrder byteOrder, IList <Coordinate> coordinateList, GeometryModel geometryModel) { EndianBitConverter.CopyBytes(coordinateList.Count, byteArray, byteIndex, byteOrder); // the number of coordinates byteIndex += 4; for (Int32 i = 0; i < coordinateList.Count; i++) { EndianBitConverter.CopyBytes(coordinateList[i].X, byteArray, byteIndex, byteOrder); EndianBitConverter.CopyBytes(coordinateList[i].Y, byteArray, byteIndex + 8, byteOrder); if (geometryModel == GeometryModel.Spatial3D) { EndianBitConverter.CopyBytes(coordinateList[i].Z, byteArray, byteIndex + 16, byteOrder); byteIndex += 24; } else { byteIndex += 16; } } }
/// <summary> /// Computes the Well-known Binary (WKB) representation. /// </summary> /// <param name="geometry">The geometry.</param> /// <param name="byteOrder">The byte-order of the conversion.</param> /// <param name="geometryModel">The geometry model of the conversion.</param> /// <returns>The WKB representation of the <paramref name="geometry" />.</returns> private static Byte[] ComputeWellKnownBinary(IMultiPolygon geometry, ByteOrder byteOrder, GeometryModel geometryModel) { Byte[] geometryBytes = new Byte[9 + 4 * geometry.Count + 4 * geometry.Sum(polygon => polygon.HoleCount + 1) + ((geometryModel == GeometryModel.Spatial3D) ? 24 : 16) * geometry.Sum(polygon => polygon.Shell.Count + polygon.Holes.Sum(hole => hole.Count))]; if (byteOrder == ByteOrder.LittleEndian) { geometryBytes[0] = 1; } if (geometryModel == GeometryModel.Spatial3D) { EndianBitConverter.CopyBytes((Int32)WellKnownBinaryTypes.MultiPolygonZ, geometryBytes, 1, byteOrder); } else { EndianBitConverter.CopyBytes((Int32)WellKnownBinaryTypes.MultiPolygon, geometryBytes, 1, byteOrder); } EndianBitConverter.CopyBytes(geometry.Count, geometryBytes, 5, byteOrder); // the number of polygons Int32 byteIndex = 9; for (Int32 i = 0; i < geometry.Count; i++) // polygons { EndianBitConverter.CopyBytes(geometry[i].HoleCount + 1, geometryBytes, byteIndex, byteOrder); // the number of rings byteIndex += 4; ComputeCoordinateList(geometryBytes, ref byteIndex, byteOrder, geometry[i].Shell.Coordinates, geometryModel); // shell for (Int32 j = 0; j < geometry[i].Holes.Count; j++) // holes { ComputeCoordinateList(geometryBytes, ref byteIndex, byteOrder, geometry[i].Holes[j].Coordinates, geometryModel); } } return(geometryBytes); }
/// <summary> /// Converts the coordinates to Well-known Binary representation. /// </summary> /// <param name="byteArray">The byte-array.</param> /// <param name="byteIndex">The starting index.</param> /// <param name="byteOrder">The byte-order of the conversion.</param> /// <param name="coordinateList">The coordinate list.</param> /// <param name="dimension">The dimension of the coordinates.</param> private static void ConvertCoordinates(Byte[] byteArray, ref Int32 byteIndex, ByteOrder byteOrder, IReadOnlyList <Coordinate> coordinateList, Int32 dimension) { // number of coordinates EndianBitConverter.CopyBytes(coordinateList.Count, byteArray, byteIndex, byteOrder); byteIndex += 4; // coordinates for (Int32 coordIndex = 0; coordIndex < coordinateList.Count; coordIndex++) { EndianBitConverter.CopyBytes(coordinateList[coordIndex].X, byteArray, byteIndex, byteOrder); EndianBitConverter.CopyBytes(coordinateList[coordIndex].Y, byteArray, byteIndex + 8, byteOrder); if (dimension == 3) { EndianBitConverter.CopyBytes(coordinateList[coordIndex].Z, byteArray, byteIndex + 16, byteOrder); byteIndex += 24; } else { byteIndex += 16; } } }
/// <summary> /// Computes the Well-known Binary (WKB) representation. /// </summary> /// <param name="geometry">The geometry.</param> /// <param name="byteOrder">The byte-order of the conversion.</param> /// <param name="geometryModel">The geometry model of the conversion.</param> /// <returns>The WKB representation of the <paramref name="geometry" />.</returns> private static Byte[] ComputeWellKnownBinary(ILineString geometry, ByteOrder byteOrder, GeometryModel geometryModel) { Byte[] geometryBytes = new Byte[9 + ((geometryModel == GeometryModel.Spatial3D) ? 24 : 16) * geometry.Count]; if (byteOrder == ByteOrder.LittleEndian) { geometryBytes[0] = 1; } if (geometryModel == GeometryModel.Spatial3D) { EndianBitConverter.CopyBytes((Int32)WellKnownBinaryTypes.LineStringZ, geometryBytes, 1, byteOrder); } else { EndianBitConverter.CopyBytes((Int32)WellKnownBinaryTypes.LineString, geometryBytes, 1, byteOrder); } Int32 byteIndex = 5; ComputeCoordinateList(geometryBytes, ref byteIndex, byteOrder, geometry.Coordinates, geometryModel); return(geometryBytes); }
/// <summary> /// Writes the file header. /// </summary> private void WriteHeader() { Byte[] headerBytes = new Byte[100]; // header identifiers EndianBitConverter.CopyBytes(9994, headerBytes, 0, ByteOrder.BigEndian); EndianBitConverter.CopyBytes(50 + _shapeIndex.Sum(recordInfo => recordInfo.Length + 4), headerBytes, 24, ByteOrder.BigEndian); EndianBitConverter.CopyBytes(1000, headerBytes, 28, ByteOrder.LittleEndian); EndianBitConverter.CopyBytes((Int32)_shapeType, headerBytes, 32, ByteOrder.LittleEndian); // envelope EndianBitConverter.CopyBytes(_envelope.MinX, headerBytes, 36, ByteOrder.LittleEndian); EndianBitConverter.CopyBytes(_envelope.MinY, headerBytes, 44, ByteOrder.LittleEndian); EndianBitConverter.CopyBytes(_envelope.MaxX, headerBytes, 52, ByteOrder.LittleEndian); EndianBitConverter.CopyBytes(_envelope.MaxY, headerBytes, 60, ByteOrder.LittleEndian); if (_geometryModel == GeometryModel.Spatial3D || _geometryModel == GeometryModel.SpatioTemporal3D) { EndianBitConverter.CopyBytes(_envelope.MinZ, headerBytes, 68, ByteOrder.LittleEndian); EndianBitConverter.CopyBytes(_envelope.MaxZ, headerBytes, 76, ByteOrder.LittleEndian); } _baseStream.Seek(0, SeekOrigin.Begin); _baseStream.Write(headerBytes, 0, headerBytes.Length); }
/// <summary> /// Converts the line string to Well-known Binary (WKB) representation. /// </summary> /// <param name="geometry">The geometry.</param> /// <param name="byteOrder">The byte-order of the conversion.</param> /// <param name="dimension">The dimension of the geometry.</param> /// <returns>The WKB representation of the <paramref name="geometry" />.</returns> private static Byte[] ToWellKnownBinary(ILineString geometry, ByteOrder byteOrder, Int32 dimension) { Byte[] geometryBytes = new Byte[9 + ((dimension == 3) ? 24 : 16) * geometry.Count]; if (byteOrder == ByteOrder.LittleEndian) { geometryBytes[0] = 1; } if (dimension == 3) { EndianBitConverter.CopyBytes((Int32)WellKnownBinaryTypes.LineStringZ, geometryBytes, 1, byteOrder); } else { EndianBitConverter.CopyBytes((Int32)WellKnownBinaryTypes.LineString, geometryBytes, 1, byteOrder); } Int32 byteIndex = 5; ConvertCoordinates(geometryBytes, ref byteIndex, byteOrder, geometry, dimension); return(geometryBytes); }
/// <summary> /// Writes a boolean value to the stream. 1 byte is written. /// </summary> /// <param name="value">The value to write</param> public void Write(bool value) { bitConverter.CopyBytes(value, buffer, 0); WriteInternal(buffer, 1); }
/// <summary> /// Sets the value of a TIFF tag. /// </summary> /// <param name="type">The type of the tag.</param> /// <param name="value">The value.</param> /// <param name="array">The array.</param> /// <param name="startIndex">The zero-based start index.</param> /// <returns>The index of the array after the operation.</returns> public static Int32 SetValue(TiffTagType type, Object value, Byte[] array, Int32 startIndex) { Int32 dataSize = GetSize(type); switch (type) { case TiffTagType.Byte: EndianBitConverter.CopyBytes(Convert.ToByte(value), array, startIndex); break; case TiffTagType.ASCII: Byte[] asciiValues = System.Text.Encoding.ASCII.GetBytes(value as String); Array.Copy(asciiValues, 0, array, startIndex, asciiValues.Length); return(startIndex + asciiValues.Length); case TiffTagType.Short: EndianBitConverter.CopyBytes(Convert.ToUInt16(value), array, startIndex); break; case TiffTagType.Long: EndianBitConverter.CopyBytes(Convert.ToUInt32(value), array, startIndex); break; case TiffTagType.SByte: EndianBitConverter.CopyBytes(Convert.ToSByte(value), array, startIndex); break; case TiffTagType.SShort: EndianBitConverter.CopyBytes(Convert.ToInt16(value), array, startIndex); break; case TiffTagType.Rational: EndianBitConverter.CopyBytes((Rational)value, array, startIndex); break; case TiffTagType.SRational: EndianBitConverter.CopyBytes((Rational)value, array, startIndex); break; case TiffTagType.SLong: EndianBitConverter.CopyBytes(Convert.ToInt32(value), array, startIndex); break; case TiffTagType.Float: EndianBitConverter.CopyBytes(Convert.ToSingle(value), array, startIndex); break; case TiffTagType.Double: EndianBitConverter.CopyBytes(Convert.ToDouble(value), array, startIndex); break; case TiffTagType.Long8: case TiffTagType.LongOffset: EndianBitConverter.CopyBytes(Convert.ToUInt64(value), array, startIndex); break; case TiffTagType.SLong8: EndianBitConverter.CopyBytes(Convert.ToInt64(value), array, startIndex); break; } return(startIndex + dataSize); }
/// <summary> /// Writes an image file directory to the stream. /// </summary> /// <param name="imageFileDirectory">The image file directory.</param> private void WriteImageFileDirectory(TiffImageFileDirectory imageFileDirectory) { _currentImageFileDirectoryStartPosition = _baseStream.Position; // write starting position _baseStream.Seek(_currentImageFileDirectoryEndPosition, SeekOrigin.Begin); _baseStream.Write(EndianBitConverter.GetBytes((UInt32)_currentImageFileDirectoryStartPosition), 0, _imageFileDirectoryFieldSize); // compute size of directory (without additional fields) Int64 imageFileDirectorySize = 2 + _imageFileDirectoryEntrySize * imageFileDirectory.Count; _currentImageFileDirectoryEndPosition = _currentImageFileDirectoryStartPosition + imageFileDirectorySize; // position after the IFD to write exceeding values _baseStream.Seek(_currentImageFileDirectoryEndPosition + _imageFileDirectoryFieldSize, SeekOrigin.Begin); // the IFD should be written in one operation Byte[] bytes; if (_imageCount == _maxImageCount - 1) { bytes = new Byte[imageFileDirectorySize + _imageFileDirectoryFieldSize]; } else { bytes = new Byte[imageFileDirectorySize]; } EndianBitConverter.CopyBytes((UInt16)imageFileDirectory.Count, bytes, 0); // number of entries Int32 byteIndex = 2; TiffTagType entryType; UInt16 dataSize; Int64 dataCount; foreach (UInt16 entryTag in imageFileDirectory.Keys) { entryType = TiffTag.GetType(imageFileDirectory[entryTag][0]); dataSize = TiffTag.GetSize(entryType); if (entryType == TiffTagType.ASCII) { dataCount = 0; for (Int32 i = 0; i < imageFileDirectory[entryTag].Length; i++) { dataCount += (imageFileDirectory[entryTag][i] as String).Length; } } else { dataCount = imageFileDirectory[entryTag].Length; } EndianBitConverter.CopyBytes(entryTag, bytes, byteIndex); EndianBitConverter.CopyBytes((UInt16)entryType, bytes, byteIndex + 2); EndianBitConverter.CopyBytes((UInt32)dataCount, bytes, byteIndex + 4); // values exceeding he field size (4) must be written to another position Byte[] dataBytes; Int32 dataStartIndex; if (dataCount * dataSize <= 4) { dataBytes = bytes; dataStartIndex = byteIndex + 8; } else { dataBytes = new Byte[dataCount * dataSize + (dataCount * dataSize) % 2]; dataStartIndex = 0; } for (Int32 valueIndex = 0; valueIndex < imageFileDirectory[entryTag].Length; valueIndex++) { dataStartIndex = TiffTag.SetValue(entryType, imageFileDirectory[entryTag][valueIndex], dataBytes, dataStartIndex); } if (dataCount * dataSize > 4) { Int64 valuePosition = _baseStream.Position; _baseStream.Write(dataBytes, 0, dataBytes.Length); EndianBitConverter.CopyBytes((UInt32)valuePosition, bytes, byteIndex + 8); } byteIndex += _imageFileDirectoryEntrySize; } _currentImageStartPosition = _baseStream.Position; // write the IFD _baseStream.Seek(_currentImageFileDirectoryStartPosition, SeekOrigin.Begin); _baseStream.Write(bytes, 0, bytes.Length); }
/// <summary> /// Initializes the stream. /// </summary> /// <param name="structure">The TIFF structure.</param> private void InitializeStream(TiffStructure structure) { if (structure == TiffStructure.Undefined || _structure != TiffStructure.Undefined) { return; } _structure = structure; _imageCount = 0; Byte[] headerBytes = null; switch (structure) { case TiffStructure.RegularTiff: headerBytes = new Byte[4]; _imageFileDirectoryEntrySize = 12; _imageFileDirectoryFieldSize = 4; break; case TiffStructure.BigTiff: headerBytes = new Byte[8]; _imageFileDirectoryEntrySize = 20; _imageFileDirectoryFieldSize = 8; break; } _baseStream.Seek(0, SeekOrigin.Begin); switch (EndianBitConverter.DefaultByteOrder) // the default endianness should be used for the encoding { case ByteOrder.LittleEndian: EndianBitConverter.CopyBytes((UInt16)0x4949, headerBytes, 0); break; case ByteOrder.BigEndian: EndianBitConverter.CopyBytes((UInt16)0x4D4D, headerBytes, 0); break; } switch (structure) { case TiffStructure.RegularTiff: EndianBitConverter.CopyBytes((UInt16)42, headerBytes, 2); // TIFF identifier _baseStream.Write(headerBytes, 0, headerBytes.Length); _baseStream.Seek(8, SeekOrigin.Begin); _currentImageFileDirectoryEndPosition = 4; break; case TiffStructure.BigTiff: EndianBitConverter.CopyBytes((UInt16)43, headerBytes, 2); // BigTIFF identifier EndianBitConverter.CopyBytes((UInt16)8, headerBytes, 4); // BigTIFF field size EndianBitConverter.CopyBytes((UInt16)0, headerBytes, 6); _baseStream.Write(headerBytes, 0, headerBytes.Length); _baseStream.Seek(16, SeekOrigin.Begin); _currentImageFileDirectoryEndPosition = 8; break; } }
public void ToBytes(byte[] buffer, int offset, EndianBitConverter bitConverter) { if (buffer == null) { throw new ArgumentNullException("byte buffer cannot be null"); } if (buffer.Length < offset + 400) { throw new ArgumentException("buffer length is too small to write bytes from header to it"); } bitConverter.CopyBytes(JobId, buffer, offset); bitConverter.CopyBytes(LineNum, buffer, offset + 4); bitConverter.CopyBytes(Reelnum, buffer, offset + 8); bitConverter.CopyBytes(DataTracesPerRecord, buffer, offset + 12); bitConverter.CopyBytes(AuxTracesPerRecord, buffer, offset + 14); bitConverter.CopyBytes(SampleIntervalOfFileMicrosec, buffer, offset + 16); bitConverter.CopyBytes(SampleIntervalOrigRecordingMicrosec, buffer, offset + 18); bitConverter.CopyBytes(SamplesPerTraceOfFile, buffer, offset + 20); bitConverter.CopyBytes(SamplesPerTraceOrigRecording, buffer, offset + 22); bitConverter.CopyBytes(DataSampleFormatCode, buffer, offset + 24); bitConverter.CopyBytes(CdpFold, buffer, offset + 26); bitConverter.CopyBytes(TraceSortingCode, buffer, offset + 28); bitConverter.CopyBytes(VerticalSumCode, buffer, offset + 30); bitConverter.CopyBytes(SweepFrequencyStart, buffer, offset + 32); bitConverter.CopyBytes(SweepFrequencyEnd, buffer, offset + 34); bitConverter.CopyBytes(SweepLengthMs, buffer, offset + 36); bitConverter.CopyBytes(SweepType, buffer, offset + 38); bitConverter.CopyBytes(TraceNumSweepChannel, buffer, offset + 40); bitConverter.CopyBytes(SweepTraceTaperLengthStartMs, buffer, offset + 42); bitConverter.CopyBytes(SweepTraceTaperLengthEndMs, buffer, offset + 44); bitConverter.CopyBytes(SweepTaperType, buffer, offset + 46); bitConverter.CopyBytes(CorrelatedDataTraces, buffer, offset + 48); bitConverter.CopyBytes(BinaryGainRecovered, buffer, offset + 50); bitConverter.CopyBytes(AplitudeRecovery, buffer, offset + 52); bitConverter.CopyBytes(UnitSystem, buffer, offset + 54); bitConverter.CopyBytes(ImpulseSignal, buffer, offset + 56); bitConverter.CopyBytes(VibratoryPolarityCode, buffer, offset + 58); bitConverter.CopyBytes(SegyFormatRevisionNum, buffer, offset + 300); bitConverter.CopyBytes(FixedLengthTraceFlag, buffer, offset + 302); bitConverter.CopyBytes(ExtendedTextHeadersCount, buffer, offset + 304); }
/// <summary> /// Converts the shape into a binary record. /// </summary> /// <param name="shape">The shape.</param> /// <param name="number">The number of the shape used for indexing.</param> /// <returns>The byte array representing the <paramref name="shape" />.</returns> public Byte[] ToRecord(Int32 number) { Byte[] shapeBytes; switch (Type) // compute the size of the array according to the type { case ShapeType.Point: case ShapeType.PointM: shapeBytes = new Byte[28]; break; case ShapeType.PointZ: shapeBytes = new Byte[44]; break; case ShapeType.MultiPoint: case ShapeType.MultiPointM: shapeBytes = new Byte[48 + CoordinateCount * 16]; break; case ShapeType.MultiPointZ: shapeBytes = new Byte[80 + CoordinateCount * 32]; break; case ShapeType.PolyLine: case ShapeType.PolyLineM: case ShapeType.Polygon: case ShapeType.PolygonM: shapeBytes = new Byte[52 + PartCount * 4 + CoordinateCount * 16]; break; case ShapeType.PolyLineZ: case ShapeType.PolygonZ: shapeBytes = new Byte[84 + PartCount * 4 + CoordinateCount * 32]; break; case ShapeType.MultiPatch: shapeBytes = new Byte[84 + PartCount * 8 + CoordinateCount * 32]; break; default: shapeBytes = new Byte[12]; break; } // compute header information of the record EndianBitConverter.CopyBytes(number, shapeBytes, 0, ByteOrder.BigEndian); EndianBitConverter.CopyBytes(shapeBytes.Length / 2 - 4, shapeBytes, 4, ByteOrder.BigEndian); EndianBitConverter.CopyBytes((Int32)_type, shapeBytes, 8, ByteOrder.LittleEndian); // compute envelope coordinates and shape coordinates switch (Type) { case ShapeType.Point: case ShapeType.PointM: EndianBitConverter.GetBytes(Coordinates[0], 2, ByteOrder.LittleEndian).CopyTo(shapeBytes, 12); break; case ShapeType.PointZ: EndianBitConverter.GetBytes(Coordinates[0], 3, ByteOrder.LittleEndian).CopyTo(shapeBytes, 12); break; case ShapeType.MultiPoint: case ShapeType.MultiPointM: EndianBitConverter.GetBytes(Envelope.Minimum, 2, ByteOrder.LittleEndian).CopyTo(shapeBytes, 12); EndianBitConverter.GetBytes(Envelope.Maximum, 2, ByteOrder.LittleEndian).CopyTo(shapeBytes, 28); EndianBitConverter.GetBytes(CoordinateCount, ByteOrder.LittleEndian).CopyTo(shapeBytes, 44); for (Int32 i = 0; i < CoordinateCount; i++) { EndianBitConverter.GetBytes(Coordinates[i], 2, ByteOrder.LittleEndian).CopyTo(shapeBytes, 48 + i * 16); } break; case ShapeType.MultiPointZ: EndianBitConverter.GetBytes(Envelope.Minimum, 3, ByteOrder.LittleEndian).CopyTo(shapeBytes, 12); EndianBitConverter.GetBytes(Envelope.Maximum, 3, ByteOrder.LittleEndian).CopyTo(shapeBytes, 28); EndianBitConverter.GetBytes(CoordinateCount, ByteOrder.LittleEndian).CopyTo(shapeBytes, 44); for (Int32 i = 0; i < CoordinateCount; i++) { EndianBitConverter.GetBytes(Coordinates[i], 2, ByteOrder.LittleEndian).CopyTo(shapeBytes, 48 + i * 16); } EndianBitConverter.GetBytes(Envelope.Minimum.Z, ByteOrder.LittleEndian).CopyTo(shapeBytes, 48 + CoordinateCount * 16); EndianBitConverter.GetBytes(Envelope.Maximum.Z, ByteOrder.LittleEndian).CopyTo(shapeBytes, 56 + CoordinateCount * 16); for (Int32 i = 0; i < CoordinateCount; i++) { EndianBitConverter.GetBytes(Coordinates[i].Z, ByteOrder.LittleEndian).CopyTo(shapeBytes, 64 + CoordinateCount * 16 + i * 8); } break; case ShapeType.PolyLine: case ShapeType.PolyLineM: case ShapeType.Polygon: case ShapeType.PolygonM: EndianBitConverter.GetBytes(Envelope.Minimum, 2, ByteOrder.LittleEndian).CopyTo(shapeBytes, 12); EndianBitConverter.GetBytes(Envelope.Maximum, 2, ByteOrder.LittleEndian).CopyTo(shapeBytes, 28); EndianBitConverter.GetBytes(PartCount, ByteOrder.LittleEndian).CopyTo(shapeBytes, 44); EndianBitConverter.GetBytes(CoordinateCount, ByteOrder.LittleEndian).CopyTo(shapeBytes, 48); for (Int32 i = 0; i < PartCount; i++) { EndianBitConverter.GetBytes(_parts[i], ByteOrder.LittleEndian).CopyTo(shapeBytes, 52 + i * 4); } for (Int32 i = 0; i < CoordinateCount; i++) { EndianBitConverter.GetBytes(Coordinates[i], 2, ByteOrder.LittleEndian).CopyTo(shapeBytes, 52 + PartCount * 4 + i * 16); } break; case ShapeType.PolyLineZ: case ShapeType.PolygonZ: EndianBitConverter.GetBytes(Envelope.Minimum, 3, ByteOrder.LittleEndian).CopyTo(shapeBytes, 12); EndianBitConverter.GetBytes(Envelope.Maximum, 3, ByteOrder.LittleEndian).CopyTo(shapeBytes, 28); EndianBitConverter.GetBytes(PartCount, ByteOrder.LittleEndian).CopyTo(shapeBytes, 44); EndianBitConverter.GetBytes(CoordinateCount, ByteOrder.LittleEndian).CopyTo(shapeBytes, 48); for (Int32 i = 0; i < PartCount; i++) { EndianBitConverter.GetBytes(_parts[i], ByteOrder.LittleEndian).CopyTo(shapeBytes, 52 + i * 4); } for (Int32 i = 0; i < CoordinateCount; i++) { EndianBitConverter.GetBytes(Coordinates[i], 2, ByteOrder.LittleEndian).CopyTo(shapeBytes, 52 + PartCount * 4 + i * 16); } EndianBitConverter.GetBytes(Envelope.Minimum.Z, ByteOrder.LittleEndian).CopyTo(shapeBytes, 52 + PartCount * 4 + CoordinateCount * 16); EndianBitConverter.GetBytes(Envelope.Maximum.Z, ByteOrder.LittleEndian).CopyTo(shapeBytes, 60 + PartCount * 4 + CoordinateCount * 16); for (Int32 i = 0; i < CoordinateCount; i++) { EndianBitConverter.GetBytes(Coordinates[i].Z, ByteOrder.LittleEndian).CopyTo(shapeBytes, 68 + PartCount * 4 + CoordinateCount * 16 + i * 8); } break; case ShapeType.MultiPatch: EndianBitConverter.GetBytes(Envelope.Minimum, 3, ByteOrder.LittleEndian).CopyTo(shapeBytes, 12); EndianBitConverter.GetBytes(Envelope.Maximum, 3, ByteOrder.LittleEndian).CopyTo(shapeBytes, 28); EndianBitConverter.GetBytes(PartCount, ByteOrder.LittleEndian).CopyTo(shapeBytes, 44); EndianBitConverter.GetBytes(CoordinateCount, ByteOrder.LittleEndian).CopyTo(shapeBytes, 48); for (Int32 i = 0; i < PartCount; i++) { EndianBitConverter.GetBytes(_parts[i], ByteOrder.LittleEndian).CopyTo(shapeBytes, 52 + i * 4); } for (Int32 i = 0; i < PartCount; i++) { EndianBitConverter.GetBytes((Int32)PartTypes[i], ByteOrder.LittleEndian).CopyTo(shapeBytes, 52 + PartCount * 4 + i * 4); } for (Int32 i = 0; i < CoordinateCount; i++) { EndianBitConverter.GetBytes(Coordinates[i], 2, ByteOrder.LittleEndian).CopyTo(shapeBytes, 52 + PartCount * 8 + i * 16); } EndianBitConverter.GetBytes(Envelope.Minimum.Z, ByteOrder.LittleEndian).CopyTo(shapeBytes, 52 + PartCount * 8 + CoordinateCount * 16); EndianBitConverter.GetBytes(Envelope.Maximum.Z, ByteOrder.LittleEndian).CopyTo(shapeBytes, 60 + PartCount * 8 + CoordinateCount * 16); for (Int32 i = 0; i < CoordinateCount; i++) { EndianBitConverter.GetBytes(Coordinates[i].Z, ByteOrder.LittleEndian).CopyTo(shapeBytes, 68 + PartCount * 8 + CoordinateCount * 16 + i * 8); } break; } return(shapeBytes); }
public void ToBytes(byte[] buffer, int offset, EndianBitConverter bitConverter) { bitConverter.CopyBytes(TraceNumInLine, buffer, offset + offset + 0); bitConverter.CopyBytes(TraceNumInFile, buffer, offset + offset + 4); bitConverter.CopyBytes(ShotNumOrStackTraceNum, buffer, offset + offset + 8); bitConverter.CopyBytes(TraceNumInShot, buffer, offset + 12); bitConverter.CopyBytes(EnergySourcePtNum, buffer, offset + 16); bitConverter.CopyBytes(CdpNum, buffer, offset + 20); bitConverter.CopyBytes(TraceNumber, buffer, offset + 24); bitConverter.CopyBytes((Int16)TraceId, buffer, offset + 28); bitConverter.CopyBytes((Int16)NumVerticalStackedTraces, buffer, offset + 30); bitConverter.CopyBytes((Int16)CdpFold, buffer, offset + 32); bitConverter.CopyBytes((Int16)DataUse, buffer, offset + 34); bitConverter.CopyBytes(SourceReceiverDistance, buffer, offset + 36); bitConverter.CopyBytes(RecieverGroupElevation, buffer, offset + 40); bitConverter.CopyBytes(SurfaceElevationAtSource, buffer, offset + 44); bitConverter.CopyBytes(SourceDepthBelowSurf, buffer, offset + 48); bitConverter.CopyBytes(DatumElevAtRecieverGroup, buffer, offset + 52); bitConverter.CopyBytes(DatumElevationAtSource, buffer, offset + 56); bitConverter.CopyBytes(WaterDepthAtSource, buffer, offset + 60); bitConverter.CopyBytes(WaterDepthAtRecieverGroup, buffer, offset + 64); bitConverter.CopyBytes((Int16)ScalarForElevationAndDepth, buffer, offset + 68); bitConverter.CopyBytes((Int16)ScalarForCoordinates, buffer, offset + 70); bitConverter.CopyBytes(XSourceCoordinate, buffer, offset + 72); bitConverter.CopyBytes(YSourceCoordinate, buffer, offset + 76); bitConverter.CopyBytes(XRecieverGroupCoordinate, buffer, offset + 80); bitConverter.CopyBytes(YRecieverGroupCoordinate, buffer, offset + 84); bitConverter.CopyBytes((Int16)CoordinateUnit, buffer, offset + 88); bitConverter.CopyBytes((Int16)WeatheringVelocity, buffer, offset + 90); bitConverter.CopyBytes((Int16)SubweatheringVelocity, buffer, offset + 92); bitConverter.CopyBytes((Int16)UpholeTimeAtSource, buffer, offset + 94); bitConverter.CopyBytes((Int16)UpholeTimeAtReceiverGroup, buffer, offset + 96); bitConverter.CopyBytes((Int16)SourceStaticCorrection, buffer, offset + 98); bitConverter.CopyBytes((Int16)ReceiverGroupStaticCorrection, buffer, offset + 100); bitConverter.CopyBytes((Int16)TotalStaticApplied, buffer, offset + 102); bitConverter.CopyBytes((Int16)HeaderTimeBreakLagMs, buffer, offset + 104); bitConverter.CopyBytes((Int16)TimeBreakShotLagMs, buffer, offset + 106); bitConverter.CopyBytes((Int16)ShotRecordingLag, buffer, offset + 108); bitConverter.CopyBytes((Int16)MuteTimeStart, buffer, offset + 110); bitConverter.CopyBytes((Int16)MuteTimeEnd, buffer, offset + 112); bitConverter.CopyBytes((UInt16)SampleCount, buffer, offset + 114); bitConverter.CopyBytes((Int16)SampleIntervalMs, buffer, offset + 116); bitConverter.CopyBytes((Int16)GainType, buffer, offset + 118); bitConverter.CopyBytes((Int16)GainConst, buffer, offset + 120); bitConverter.CopyBytes((Int16)EarlyGainDb, buffer, offset + 122); bitConverter.CopyBytes((Int16)Correlated, buffer, offset + 124); bitConverter.CopyBytes((Int16)SweepFrequencyStart, buffer, offset + 126); bitConverter.CopyBytes((Int16)SweepFrequencyEnd, buffer, offset + 128); bitConverter.CopyBytes((Int16)SweepLengthMs, buffer, offset + 130); bitConverter.CopyBytes((Int16)SweepType, buffer, offset + 132); bitConverter.CopyBytes((Int16)SweepTaperTraceLengthStartMs, buffer, offset + 134); bitConverter.CopyBytes((Int16)SweepTaperTraceLengthEndMs, buffer, offset + 136); bitConverter.CopyBytes((Int16)TaperType, buffer, offset + 138); bitConverter.CopyBytes((Int16)AliasFilterFrequency, buffer, offset + 140); bitConverter.CopyBytes((Int16)AliasFilterSlope, buffer, offset + 142); bitConverter.CopyBytes((Int16)NotchFilterFrequency, buffer, offset + 144); bitConverter.CopyBytes((Int16)NotchFilterSlope, buffer, offset + 146); bitConverter.CopyBytes((Int16)LowCutFrequency, buffer, offset + 148); bitConverter.CopyBytes((Int16)HighCutFrequency, buffer, offset + 150); bitConverter.CopyBytes((Int16)LowCutSlope, buffer, offset + 152); bitConverter.CopyBytes((Int16)HighCutSlope, buffer, offset + 154); bitConverter.CopyBytes((Int16)Yr, buffer, offset + 156); bitConverter.CopyBytes((Int16)Day, buffer, offset + 158); bitConverter.CopyBytes((Int16)Hour, buffer, offset + 160); bitConverter.CopyBytes((Int16)Minute, buffer, offset + 162); bitConverter.CopyBytes((Int16)Second, buffer, offset + 164); bitConverter.CopyBytes((Int16)TimeBasis, buffer, offset + 166); bitConverter.CopyBytes((Int16)TraceWeightFactor, buffer, offset + 168); bitConverter.CopyBytes((Int16)GeophoneGroupNumOfRollSwitchPositionOne, buffer, offset + 170); bitConverter.CopyBytes((Int16)GeophoneGroupNumOfFirstTraceOrigRecord, buffer, offset + 172); bitConverter.CopyBytes((Int16)GeophoneGroupNumOfLastTraceOrigRecord, buffer, offset + 174); bitConverter.CopyBytes((Int16)GapSize, buffer, offset + 176); bitConverter.CopyBytes((Int16)TaperOverTravel, buffer, offset + 178); bitConverter.CopyBytes(XCdp, buffer, offset + 180); bitConverter.CopyBytes(YCdp, buffer, offset + 184); bitConverter.CopyBytes(Inline, buffer, offset + 188); bitConverter.CopyBytes(Crossline, buffer, offset + 192); bitConverter.CopyBytes(ShotPoint, buffer, offset + 196); bitConverter.CopyBytes((Int16)ShotPointScalar, buffer, offset + 200); bitConverter.CopyBytes((Int16)TraceValueMeasurementUnit, buffer, offset + 202); bitConverter.CopyBytes(TransductionConstantMantissa, buffer, offset + 204); bitConverter.CopyBytes((Int16)TransductionConstantPower, buffer, offset + 208); bitConverter.CopyBytes((Int16)TransductionUnit, buffer, offset + 210); bitConverter.CopyBytes((Int16)TraceIdentifier, buffer, offset + 212); bitConverter.CopyBytes((Int16)ScalarTraceHeader, buffer, offset + 214); bitConverter.CopyBytes((Int16)SourceType, buffer, offset + 216); bitConverter.CopyBytes(SourceEnergyDirectionMantissa, buffer, offset + 218); bitConverter.CopyBytes((Int16)SourceEnergyDirectionExponent, buffer, offset + 222); bitConverter.CopyBytes(SourceMeasurementMantissa, buffer, offset + 224); bitConverter.CopyBytes((Int16)SourceMeasurementExponent, buffer, offset + 228); bitConverter.CopyBytes((Int16)SourceMeasurementUnit, buffer, offset + 230); bitConverter.CopyBytes(UnassignedInt1, buffer, offset + 232); bitConverter.CopyBytes(UnassignedInt2, buffer, offset + 236); }