Skip to main content

PbfWriter

Struct PbfWriter 

Source
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 the Write trait, 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 PbfWriter<BufWriter<File>>

Source

pub fn from_path<P: AsRef<Path>>(path: P, use_dense: bool) -> Result<Self>

Creates a new PbfWriter from a file path.

§Parameters
  • path - The path to the file to write the PBF data to.
  • use_dense - A boolean value indicating whether to use dense format for writing nodes.
Source§

impl<W: Write> PbfWriter<W>

Source

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 the Write trait, which is used to write the PBF data.
  • use_dense - A boolean value indicating whether to use dense format for writing nodes.
Source

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.

Source

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.

Source

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.

Source

pub fn finish(&mut self) -> Result<()>

Finishes writing the PBF file.

This method should be called after writing all elements to the PBF file. It writes the header (even for an empty file) and flushes any buffered elements.

Trait Implementations§

Source§

impl<W: Write> Drop for PbfWriter<W>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.