Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading