/// <summary> /// Method to write the feature to an index /// </summary> /// <param name="writer"></param> internal void Write(BinaryWriter writer) { writer.Write(MinX); writer.Write(MinY); writer.Write(MaxX); writer.Write(MaxY); BinaryIOExtensions.WriteBE(writer, _fid); }
/// <summary> /// Method to write a bin /// </summary> /// <param name="bid">The bin's id</param> /// <param name="sbnWriter">The writer to use</param> /// <param name="sbxWriter"></param> internal void Write(ref int bid, BinaryWriter sbnWriter, BinaryWriter sbxWriter = null) { if (sbxWriter != null) { BinaryIOExtensions.WriteBE(sbxWriter, (int)(sbnWriter.BaseStream.Position / 2)); BinaryIOExtensions.WriteBE(sbxWriter, NumFeatures * 4); } BinaryIOExtensions.WriteBE(sbnWriter, bid++); BinaryIOExtensions.WriteBE(sbnWriter, NumFeatures * 4); WriteBuffer(sbnWriter); if (Next != null) { Next.Write(ref bid, sbnWriter, sbxWriter); } }
/// <summary> /// Method to write the bin header to the sbn file /// </summary> /// <param name="sbnsw"></param> /// <param name="lastBinIndex"></param> private void WriteBinHeader(BinaryWriter sbnsw, int lastBinIndex) { var binIndex = 2; for (var i = 1; i <= lastBinIndex; i++) { if (Nodes[i].FeatureCount > 0) { BinaryIOExtensions.WriteBE(sbnsw, binIndex); BinaryIOExtensions.WriteBE(sbnsw, Nodes[i].FeatureCount); binIndex += (int)Math.Ceiling(Nodes[i].FeatureCount / 100d); } else { BinaryIOExtensions.WriteBE(sbnsw, -1); BinaryIOExtensions.WriteBE(sbnsw, 0); } } }
/// <summary> /// Method to write the index header using the provided writer /// </summary> /// <param name="writer">The writer to use</param> /// <param name="fileLength"></param> internal void Write(BinaryWriter writer, int?fileLength = null) { BinaryIOExtensions.WriteBE(writer, FileCode); BinaryIOExtensions.WriteBE(writer, FileCodeIndex); writer.Write(new byte[16]); BinaryIOExtensions.WriteBE(writer, (fileLength ?? FileLength) / 2); BinaryIOExtensions.WriteBE(writer, NumRecords); BinaryIOExtensions.WriteBE(writer, XRange.Min); BinaryIOExtensions.WriteBE(writer, YRange.Min); BinaryIOExtensions.WriteBE(writer, XRange.Max); BinaryIOExtensions.WriteBE(writer, YRange.Max); BinaryIOExtensions.WriteBE(writer, ZRange); BinaryIOExtensions.WriteBE(writer, MRange); writer.Write(0); }
/// <summary> /// Method to write the tree /// </summary> /// <param name="sbnsw">A writer for the sbn stream</param> /// <param name="sbxsw">A writer for the sbx stream</param> private void Write(BinaryWriter sbnsw, BinaryWriter sbxsw) { // Gather header data int numBins, lastBinIndex; GetHeaderValues(out numBins, out lastBinIndex); // we have one additional bin numBins++; // first bin descriptors var numBinHeaderRecords = lastBinIndex; var binHeaderSize = (numBinHeaderRecords) * 8; // then bins with features var usedBinSize = numBins * 8; var sbxSize = 100 + usedBinSize; var sbnSize = 100 + binHeaderSize + usedBinSize + FeatureCount * 8; // Write headers _header.Write(sbnsw, sbnSize); _header.Write(sbxsw, sbxSize); // sbn and sbx records // first create bin descriptors record var recLen = (numBinHeaderRecords) * 4; BinaryIOExtensions.WriteBE(sbnsw, 1); BinaryIOExtensions.WriteBE(sbnsw, recLen); BinaryIOExtensions.WriteBE(sbxsw, 50); BinaryIOExtensions.WriteBE(sbxsw, recLen); WriteBinHeader(sbnsw, lastBinIndex); WriteBins(sbnsw, sbxsw); }