Skip to content

Add chunk_size parameter to from_shapely to create a chunked geometry array #1350

@kylebarron

Description

@kylebarron

Old code:

            #[classmethod]
            #[pyo3(signature = (input, *, chunk_size=65536, crs=None))]
            fn from_shapely(
                _cls: &Bound<PyType>,
                py: Python,
                input: &Bound<PyAny>,
                chunk_size: usize,
                crs: Option<PyCrs>,
            ) -> PyGeoArrowResult<Self> {
                let len = input.len()?;
                let num_chunks = (len as f64 / chunk_size as f64).ceil() as usize;
                let mut chunks = Vec::with_capacity(num_chunks);

                for chunk_idx in 0..num_chunks {
                    let slice = PySlice::new_bound(
                        py,
                        (chunk_idx * chunk_size).try_into().unwrap(),
                        ((chunk_idx + 1) * chunk_size).try_into().unwrap(),
                        1,
                    );
                    let input_slice = input.get_item(slice)?;
                    chunks.push(
                        <$py_array_struct>::from_shapely(_cls, py, &input_slice, crs.clone())?.0,
                    );
                }

                Ok(geoarrow_array::chunked_array::PyChunkedNativeArray::new(chunks).into())
            }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions