Skip to content

Commit

Permalink
Fix js bindings and update name
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebarron committed Dec 23, 2024
1 parent f757075 commit ff2b099
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions js/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions js/src/io/flatgeobuf.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::io::Cursor;

use arrow_array::RecordBatchReader;
use arrow_wasm::Table;
use geoarrow::io::flatgeobuf::{read_flatgeobuf as _read_flatgeobuf, FlatGeobufReaderOptions};
use geoarrow::io::flatgeobuf::{FlatGeobufReaderBuilder, FlatGeobufReaderOptions};
// use parquet_wasm::utils::assert_parquet_file_not_empty;
use wasm_bindgen::prelude::*;

Expand All @@ -27,12 +28,14 @@ use crate::error::WasmResult;
#[wasm_bindgen(js_name = readFlatGeobuf)]
pub fn read_flatgeobuf(file: &[u8], batch_size: Option<usize>) -> WasmResult<Table> {
// assert_parquet_file_not_empty(parquet_file)?;
let mut cursor = Cursor::new(file);
let cursor = Cursor::new(file);
let options = FlatGeobufReaderOptions {
batch_size,
..Default::default()
};
let geo_table = _read_flatgeobuf(&mut cursor, options)?;
let (batches, schema) = geo_table.into_inner();
let reader_builder = FlatGeobufReaderBuilder::open(cursor)?;
let record_batch_reader = reader_builder.read(options)?;
let schema = record_batch_reader.schema();
let batches = record_batch_reader.collect::<std::result::Result<_, _>>()?;
Ok(Table::new(schema, batches))
}
2 changes: 1 addition & 1 deletion rust/geoarrow/src/io/flatgeobuf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ mod writer;

#[cfg(feature = "flatgeobuf_async")]
pub use reader::read_flatgeobuf_async;
pub use reader::{FlatGeobufReaderBuilder, FlatGeobufReaderOptions, FlatGeobufRecordBatchReader};
pub use reader::{FlatGeobufReader, FlatGeobufReaderBuilder, FlatGeobufReaderOptions};
pub use writer::{write_flatgeobuf, write_flatgeobuf_with_options, FlatGeobufWriterOptions};
2 changes: 1 addition & 1 deletion rust/geoarrow/src/io/flatgeobuf/reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ mod sync;
pub use common::FlatGeobufReaderOptions;
#[cfg(feature = "flatgeobuf_async")]
pub use r#async::read_flatgeobuf_async;
pub use sync::{FlatGeobufReaderBuilder, FlatGeobufRecordBatchReader};
pub use sync::{FlatGeobufReader, FlatGeobufReaderBuilder};
33 changes: 15 additions & 18 deletions rust/geoarrow/src/io/flatgeobuf/reader/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use geozero::{FeatureProcessor, FeatureProperties};
use std::io::{Read, Seek};
use std::sync::Arc;

/// A builder for [FlatGeobufRecordBatchReader]
/// A builder for [FlatGeobufReader]
pub struct FlatGeobufReaderBuilder<R> {
reader: FgbReader<R>,
}
Expand Down Expand Up @@ -86,12 +86,12 @@ impl<R: Read> FlatGeobufReaderBuilder<R> {
pub fn read_seq(
self,
options: FlatGeobufReaderOptions,
) -> Result<FlatGeobufRecordBatchReader<R, NotSeekable>> {
) -> Result<FlatGeobufReader<R, NotSeekable>> {
let (data_type, properties_schema, array_metadata) = self.infer_from_header()?;
if let Some((min_x, min_y, max_x, max_y)) = options.bbox {
let selection = self.reader.select_bbox_seq(min_x, min_y, max_x, max_y)?;
let num_rows = selection.features_count();
Ok(FlatGeobufRecordBatchReader {
Ok(FlatGeobufReader {
selection,
data_type,
batch_size: options.batch_size.unwrap_or(65_536),
Expand All @@ -102,7 +102,7 @@ impl<R: Read> FlatGeobufReaderBuilder<R> {
} else {
let selection = self.reader.select_all_seq()?;
let num_rows = selection.features_count();
Ok(FlatGeobufRecordBatchReader {
Ok(FlatGeobufReader {
selection,
data_type,
batch_size: options.batch_size.unwrap_or(65_536),
Expand All @@ -116,15 +116,12 @@ impl<R: Read> FlatGeobufReaderBuilder<R> {

impl<R: Read + Seek> FlatGeobufReaderBuilder<R> {
/// Read features
pub fn read(
self,
options: FlatGeobufReaderOptions,
) -> Result<FlatGeobufRecordBatchReader<R, Seekable>> {
pub fn read(self, options: FlatGeobufReaderOptions) -> Result<FlatGeobufReader<R, Seekable>> {
let (data_type, properties_schema, array_metadata) = self.infer_from_header()?;
if let Some((min_x, min_y, max_x, max_y)) = options.bbox {
let selection = self.reader.select_bbox(min_x, min_y, max_x, max_y)?;
let num_rows = selection.features_count();
Ok(FlatGeobufRecordBatchReader {
Ok(FlatGeobufReader {
selection,
data_type,
batch_size: options.batch_size.unwrap_or(65_536),
Expand All @@ -135,7 +132,7 @@ impl<R: Read + Seek> FlatGeobufReaderBuilder<R> {
} else {
let selection = self.reader.select_all()?;
let num_rows = selection.features_count();
Ok(FlatGeobufRecordBatchReader {
Ok(FlatGeobufReader {
selection,
data_type,
batch_size: options.batch_size.unwrap_or(65_536),
Expand All @@ -150,7 +147,7 @@ impl<R: Read + Seek> FlatGeobufReaderBuilder<R> {
/// An iterator over record batches from a FlatGeobuf file.
///
/// This implements [arrow_array::RecordBatchReader], which you can use to access data.
pub struct FlatGeobufRecordBatchReader<R, S> {
pub struct FlatGeobufReader<R, S> {
selection: FeatureIter<R, S>,
data_type: NativeType,
batch_size: usize,
Expand All @@ -159,7 +156,7 @@ pub struct FlatGeobufRecordBatchReader<R, S> {
array_metadata: Arc<ArrayMetadata>,
}

impl<R, S> FlatGeobufRecordBatchReader<R, S> {
impl<R, S> FlatGeobufReader<R, S> {
fn construct_options(&self) -> GeoTableBuilderOptions {
let coord_type = self.data_type.coord_type();
let mut batch_size = self.batch_size;
Expand All @@ -177,7 +174,7 @@ impl<R, S> FlatGeobufRecordBatchReader<R, S> {
}
}

impl<R: Read> FlatGeobufRecordBatchReader<R, NotSeekable> {
impl<R: Read> FlatGeobufReader<R, NotSeekable> {
fn process_batch(&mut self) -> Result<Option<RecordBatch>> {
let options = self.construct_options();
let batch_size = options.batch_size;
Expand Down Expand Up @@ -252,7 +249,7 @@ impl<R: Read> FlatGeobufRecordBatchReader<R, NotSeekable> {
}
}

impl<R: Read + Seek> FlatGeobufRecordBatchReader<R, Seekable> {
impl<R: Read + Seek> FlatGeobufReader<R, Seekable> {
fn process_batch(&mut self) -> Result<Option<RecordBatch>> {
let options = self.construct_options();
let batch_size = options.batch_size;
Expand Down Expand Up @@ -332,7 +329,7 @@ impl<R: Read + Seek> FlatGeobufRecordBatchReader<R, Seekable> {
}
}

impl<R: Read> Iterator for FlatGeobufRecordBatchReader<R, NotSeekable> {
impl<R: Read> Iterator for FlatGeobufReader<R, NotSeekable> {
type Item = std::result::Result<RecordBatch, ArrowError>;

fn next(&mut self) -> Option<Self::Item> {
Expand All @@ -342,7 +339,7 @@ impl<R: Read> Iterator for FlatGeobufRecordBatchReader<R, NotSeekable> {
}
}

impl<R: Read> RecordBatchReader for FlatGeobufRecordBatchReader<R, NotSeekable> {
impl<R: Read> RecordBatchReader for FlatGeobufReader<R, NotSeekable> {
fn schema(&self) -> SchemaRef {
let geom_field =
self.data_type
Expand All @@ -356,7 +353,7 @@ impl<R: Read> RecordBatchReader for FlatGeobufRecordBatchReader<R, NotSeekable>
}
}

impl<R: Read + Seek> Iterator for FlatGeobufRecordBatchReader<R, Seekable> {
impl<R: Read + Seek> Iterator for FlatGeobufReader<R, Seekable> {
type Item = std::result::Result<RecordBatch, ArrowError>;

fn next(&mut self) -> Option<Self::Item> {
Expand All @@ -366,7 +363,7 @@ impl<R: Read + Seek> Iterator for FlatGeobufRecordBatchReader<R, Seekable> {
}
}

impl<R: Read + Seek> RecordBatchReader for FlatGeobufRecordBatchReader<R, Seekable> {
impl<R: Read + Seek> RecordBatchReader for FlatGeobufReader<R, Seekable> {
fn schema(&self) -> SchemaRef {
let geom_field =
self.data_type
Expand Down

0 comments on commit ff2b099

Please sign in to comment.