-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e35e12c
commit 1086c43
Showing
10 changed files
with
72 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,15 @@ | ||
use crate::error::PyGeoArrowResult; | ||
use crate::io::input::sync::FileReader; | ||
use crate::util::table_to_pytable; | ||
use crate::util::Arro3Table; | ||
use geoarrow::io::shapefile::read_shapefile as _read_shapefile; | ||
use pyo3::prelude::*; | ||
|
||
#[pyfunction] | ||
// #[pyo3(signature = (file, *, batch_size=65536))] | ||
pub fn read_shapefile( | ||
py: Python, | ||
mut shp_file: FileReader, | ||
mut dbf_file: FileReader, | ||
) -> PyGeoArrowResult<PyObject> { | ||
) -> PyGeoArrowResult<Arro3Table> { | ||
let table = _read_shapefile(&mut shp_file, &mut dbf_file)?; | ||
Ok(table_to_pytable(table).to_arro3(py)?) | ||
Ok(Arro3Table::from_geoarrow(table)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,32 @@ | ||
use pyo3::prelude::*; | ||
use pyo3_arrow::PyTable; | ||
|
||
pub(crate) fn table_to_pytable(table: geoarrow::table::Table) -> PyTable { | ||
let (batches, schema) = table.into_inner(); | ||
PyTable::try_new(batches, schema).unwrap() | ||
/// A wrapper around a [PyTable] that implements [IntoPyObject] to convert to a runtime-available | ||
/// arro3.core.Table | ||
/// | ||
/// This ensures that we return with the user's runtime-provided arro3.core.Table and not the one | ||
/// we linked from Rust. | ||
pub struct Arro3Table(PyTable); | ||
|
||
impl Arro3Table { | ||
pub fn from_geoarrow(table: geoarrow::table::Table) -> Self { | ||
let (batches, schema) = table.into_inner(); | ||
PyTable::try_new(batches, schema).unwrap().into() | ||
} | ||
} | ||
|
||
impl From<PyTable> for Arro3Table { | ||
fn from(value: PyTable) -> Self { | ||
Self(value) | ||
} | ||
} | ||
|
||
impl<'py> IntoPyObject<'py> for Arro3Table { | ||
type Target = PyAny; | ||
type Output = Bound<'py, PyAny>; | ||
type Error = PyErr; | ||
|
||
fn into_pyobject(self, py: pyo3::Python<'py>) -> Result<Self::Output, Self::Error> { | ||
Ok(self.0.to_arro3(py)?.bind(py).clone()) | ||
} | ||
} |