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
1 change: 1 addition & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions rust/pyo3-geoarrow/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ keywords = ["python", "arrow"]
categories = []
rust-version = { workspace = true }

[features]
geozero = ["dep:geozero", "geoarrow-array/geozero"]

[dependencies]
arrow-array = { workspace = true }
arrow-cast = { workspace = true }
Expand All @@ -19,6 +22,7 @@ arrow-schema = { workspace = true }
geoarrow-array = { workspace = true }
geoarrow-cast = { workspace = true }
geoarrow-schema = { workspace = true }
geozero = { workspace = true, optional = true }
pyo3 = { workspace = true, features = ["chrono", "indexmap"] }
pyo3-arrow = { workspace = true }
serde_json = { workspace = true }
Expand Down
54 changes: 34 additions & 20 deletions rust/pyo3-geoarrow/src/array.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
use std::sync::Arc;

// use geoarrow::ArrayBase;
// use geoarrow::NativeArray;
// use geoarrow::error::GeoArrowError;
// use geoarrow::scalar::GeometryScalar;
// use geoarrow::trait_::NativeArrayRef;
use geoarrow_array::GeoArrowArray;
use geoarrow_array::array::from_arrow_array;
use geoarrow_cast::downcast::NativeType;
use geoarrow_schema::GeoArrowType;
use geoarrow_schema::{
BoxType, GeometryCollectionType, LineStringType, MultiLineStringType, MultiPointType,
MultiPolygonType, PointType, PolygonType,
};
// use geozero::ProcessToJson;
use pyo3::intern;
use pyo3::prelude::*;
use pyo3::types::{PyCapsule, PyTuple, PyType};
Expand Down Expand Up @@ -91,23 +86,42 @@ impl PyGeoArrowArray {
}
}

// #[getter]
// fn __geo_interface__<'py>(&'py self, py: Python<'py>) -> PyGeoArrowResult<Bound<'py, PyAny>> {
// // Note: We create a Table out of this array so that each row can be its own Feature in a
// // FeatureCollection
#[cfg(feature = "geozero")]
#[getter]
fn __geo_interface__<'py>(&'py self, py: Python<'py>) -> PyGeoArrowResult<Bound<'py, PyAny>> {
// Note: We create a Table out of this array so that each row can be its own Feature in a
// FeatureCollection

// use

use GeoArrowType::*;
use geoarrow_array::cast::AsGeoArrowArray;
match self.0.data_type() {
GeoArrowType::Point(_) => {
use geoarrow_array::GeoArrowArrayAccessor;

let x = self.0.as_point();
for geom in x.iter_values() {
use geozero::ToJson;

let geom = geom.unwrap();
let json = geom.to_json().unwrap();
}
}
}

// let field = self.0.extension_field();
// let geometry = self.0.to_array_ref();
// let schema = Arc::new(Schema::new(vec![field]));
// let batch = RecordBatch::try_new(schema.clone(), vec![geometry])?;
let field = self.0.extension_field();
let geometry = self.0.to_array_ref();
let schema = Arc::new(Schema::new(vec![field]));
let batch = RecordBatch::try_new(schema.clone(), vec![geometry])?;

// let mut table = geoarrow::table::Table::try_new(vec![batch], schema)?;
// let json_string = table.to_json().map_err(GeoArrowError::GeozeroError)?;
let mut table = geoarrow::table::Table::try_new(vec![batch], schema)?;
let json_string = table.to_json().map_err(GeoArrowError::GeozeroError)?;

// let json_mod = py.import(intern!(py, "json"))?;
// let args = (json_string,);
// Ok(json_mod.call_method1(intern!(py, "loads"), args)?)
// }
let json_mod = py.import(intern!(py, "json"))?;
let args = (json_string,);
Ok(json_mod.call_method1(intern!(py, "loads"), args)?)
}

// fn __getitem__(&self, i: isize) -> PyGeoArrowResult<Option<PyGeometry>> {
// // Handle negative indexes from the end
Expand Down
Loading