pub struct PbfWriter<W: Write> { /* private fields */ }Expand description
A writer for creating PBF files.
The PbfWriter struct provides functionality to write PBF data to an underlying writer.
It supports writing elements in either dense or non-dense format and can include optional
bounding box information.
Elements are buffered and flushed as blocks of 8000; the output blobs are compressed with
zlib. Elements marked visible = false that are seen before the header is emitted (the
first automatic flush or finish()) cause the header to declare the required
HistoricalInformation feature; callers streaming historical data whose invisible
elements may arrive after the first block must declare it up front with
PbfWriter::set_historical_data. finish() must be called to flush the last partial
block; dropping the writer flushes it best-effort (errors are only surfaced by
finish()).
Please note: the PBF format does not require sorted elements, but the conventional layout
(all nodes by id, then all ways by id, then all relations by id) is assumed by
IndexedReader and most other tools. PbfWriter stores elements in the order in which
write is called, so it is up to the caller to provide them in the desired order.
§Type Parameters
W- A type that implements theWritetrait, which is used to write the PBF data.
§Example
use pbf_craft::models::{Element, Node};
use pbf_craft::writers::PbfWriter;
let mut writer = PbfWriter::from_path(std::env::temp_dir().join("output.pbf"), true).unwrap();
writer.write(Element::Node(Node::default())).unwrap();
writer.finish().unwrap();Implementations§
Source§impl<W: Write> PbfWriter<W>
impl<W: Write> PbfWriter<W>
Sourcepub fn new(writer: W, use_dense: bool) -> PbfWriter<W>
pub fn new(writer: W, use_dense: bool) -> PbfWriter<W>
Creates a new PbfWriter from an existing writer.
§Parameters
writer- The writer to use for writing the PBF data. It should implement theWritetrait, which is used to write the PBF data.use_dense- A boolean value indicating whether to use dense format for writing nodes.
Sourcepub fn set_bbox(&mut self, bbox: Bound)
pub fn set_bbox(&mut self, bbox: Bound)
Sets the bounding box for the PBF file.
If you want to include a bounding box in the PBF file, you set it before writing any elements.
Sourcepub fn set_historical_data(&mut self, historical: bool) -> Result<()>
pub fn set_historical_data(&mut self, historical: bool) -> Result<()>
Declares that the data being written is historical, i.e. contains elements with
visible = false, so the header block declares the required HistoricalInformation
feature.
The writer also auto-detects visible = false elements, but only those seen before
the header is emitted — the header is written together with the first flushed block
(8000 elements) or at finish() and can never be amended afterwards. Callers
streaming historical data that cannot guarantee an invisible element inside the first
block must call this before writing, like PbfWriter::set_bbox.
Returns an error if the header has already been written (i.e. the first block was already flushed) and the declaration can no longer take effect.
Sourcepub fn write(&mut self, element: Element) -> Result<()>
pub fn write(&mut self, element: Element) -> Result<()>
Writes an element.
Please note: the PBF format does not require sorted elements, but IndexedReader and
most other tools assume the conventional ordering (all nodes by id, then all ways by
id, then all relations by id). The writer stores elements in the order they are
written — the caller is responsible for providing them in the desired order.
Trait Implementations§
Auto Trait Implementations§
impl<W> Freeze for PbfWriter<W>where
W: Freeze,
impl<W> RefUnwindSafe for PbfWriter<W>where
W: RefUnwindSafe,
impl<W> Send for PbfWriter<W>where
W: Send,
impl<W> Sync for PbfWriter<W>where
W: Sync,
impl<W> Unpin for PbfWriter<W>where
W: Unpin,
impl<W> UnsafeUnpin for PbfWriter<W>where
W: UnsafeUnpin,
impl<W> UnwindSafe for PbfWriter<W>where
W: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more