Skip to content

Commit

Permalink
Shapefile record batch reader
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebarron committed Dec 23, 2024
1 parent 9a1e946 commit 796350a
Show file tree
Hide file tree
Showing 4 changed files with 655 additions and 222 deletions.
7 changes: 4 additions & 3 deletions python/Cargo.lock

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

17 changes: 15 additions & 2 deletions python/geoarrow-io/src/io/shapefile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use std::path::PathBuf;

use crate::error::PyGeoArrowResult;
use crate::util::to_arro3_table;
use geoarrow::io::shapefile::{read_shapefile as _read_shapefile, ShapefileReaderOptions};
use arrow::array::RecordBatchReader;
use geoarrow::io::shapefile::{ShapefileReaderBuilder, ShapefileReaderOptions};
use geoarrow::table::Table;
use pyo3::prelude::*;
use pyo3_arrow::export::Arro3Table;
use pyo3_geoarrow::PyCoordType;
Expand Down Expand Up @@ -47,6 +49,17 @@ pub fn read_shapefile(
let shp_file = BufReader::new(File::open(shp_path)?);
let dbf_file = BufReader::new(File::open(dbf_path)?);

let table = _read_shapefile(shp_file, dbf_file, options)?;
let mut builder = ShapefileReaderBuilder::try_new(shp_file, dbf_file, options)?;
let reader = builder.read()?;

// Note: this fails because it's trying to cast to `'static` when passing to
// PyRecordBatchReader. We need to remove the `'a` lifetime in the core shapefile reader
// implementation, but to do that we need to change the iterators in the `shapefile` crate to
// be owning instead of borrowing.
// Ok(PyRecordBatchReader::new(reader).into())

let schema = reader.schema();
let batches = reader.collect::<std::result::Result<Vec<_>, _>>()?;
let table = Table::try_new(batches, schema).unwrap();
Ok(to_arro3_table(table))
}
2 changes: 1 addition & 1 deletion rust/geoarrow/src/io/shapefile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
mod reader;
mod scalar;

pub use reader::{read_shapefile, ShapefileReaderOptions};
pub use reader::{ShapefileReaderBuilder, ShapefileReaderOptions};
Loading

0 comments on commit 796350a

Please sign in to comment.