Struct osm_io::osm::pbf::writer::Writer

source ·
pub struct Writer { /* private fields */ }
Expand description

*.osm.pbf file reader

Write an ordered *.osm.pbf file split into blocks of 8000 or less elements of the same variant - Nodes, Ways, Relations. Example:


use std::path::PathBuf;
use osm_io::osm::model::element::Element;
use osm_io::osm::pbf;
use osm_io::osm::pbf::compression_type::CompressionType;
use osm_io::osm::pbf::file_info::FileInfo;
fn example() -> Result<(), anyhow::Error> {
    let input_path = PathBuf::from("./tests/fixtures/malta-230109.osm.pbf");
    let output_path = PathBuf::from("./target/results/malta-230109.osm.pbf");
    let reader = pbf::reader::Reader::new(&input_path)?;
    let mut file_info = FileInfo::default();
    file_info.with_writingprogram_str("pbf-io-example");
    let mut writer = pbf::writer::Writer::from_file_info(
            output_path,
            file_info,
            CompressionType::Zlib,
    )?;

    writer.write_header()?;
    for element in reader.elements()? {
        let mut filtered_out = false;
        match &element {
            Element::Node { node: _ } => {}
            Element::Way { way: _ } => {}
            Element::Relation { relation: _ } => {}
            Element::Sentinel => {
                filtered_out = true;
            }
        }
        if !filtered_out {
            writer.write_element(element)?;
        }
    }
    writer.close()?;
    Ok(())
}

Implementations§

source§

impl Writer

source

pub fn from_file_info( path: PathBuf, file_info: FileInfo, compression_type: CompressionType ) -> Result<Writer, Error>

Create a new Writer from FileInfo

source

pub fn new( path: PathBuf, program_name: &str, data_source: &str, osmosis_replication_timestamp: Option<i64>, osmosis_replication_sequence_number: Option<i64>, osmosis_replication_base_url: Option<String>, compression_type: CompressionType, precomputed_bounding_box: Option<BoundingBox>, contains_history: bool ) -> Result<Writer, Error>

Create a new Writer

source

pub fn write_header(&mut self) -> Result<(), Error>

Write the *.osm.pbf file header.

Must be called before writing elements. That means that all header values, specifically the bounding box must be calculated before writing the file. I some cases that can incur a costly additional iteration.

source

pub fn write_file_block(&mut self, file_block: FileBlock) -> Result<(), Error>

Low level API to write a FileBlock

source

pub fn write_blob( &mut self, blob_header: Vec<u8>, blob_body: Vec<u8> ) -> Result<(), Error>

Low level API to write a bytes of a blob

source

pub fn write_element(&mut self, element: Element) -> Result<(), Error>

Write element

Elements must be ordered, that is each element must be less then or equal to the following element

source

pub fn write_elements(&mut self, elements: Vec<Element>) -> Result<(), Error>

Write elements

Elements must be ordered, that is each element must be less then or equal to the following element

source

pub fn close(&mut self) -> Result<(), Error>

Flush the internal buffers.

Must be called in the end to write any elements accumulated in internal buffers

source

pub fn path(&self) -> &PathBuf

Output path

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

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

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V