Skip to content

Commit f12d92e

Browse files
committed
feat: add to search-to
1 parent c875293 commit f12d92e

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

python/rustac/rustac.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ async def search_to(
350350
filter: str | dict[str, Any] | None = None,
351351
query: dict[str, Any] | None = None,
352352
format: str | None = None,
353+
parquet_compression: str | None = None,
353354
store: AnyObjectStore | None = None,
354355
use_duckdb: bool | None = None,
355356
) -> int:
@@ -389,6 +390,10 @@ async def search_to(
389390
It is recommended to use filter instead, if possible.
390391
format: The output format. If none, will be inferred from
391392
the outfile extension, and if that fails will fall back to compact JSON.
393+
parquet_compression: If writing stac-geoparquet, sets the compression
394+
algorithm.
395+
https://docs.rs/parquet/latest/parquet/basic/enum.Compression.html
396+
is a list of what's available.
392397
store: An optional [ObjectStore][]
393398
use_duckdb: Query with DuckDB. If None and the href has a
394399
'parquet' or 'geoparquet' extension, will be set to True. Defaults

src/search.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub fn search<'py>(
5858
}
5959

6060
#[pyfunction]
61-
#[pyo3(signature = (outfile, href, *, intersects=None, ids=None, collections=None, max_items=None, limit=None, bbox=None, datetime=None, include=None, exclude=None, sortby=None, filter=None, query=None, format=None, store=None, use_duckdb=None, **kwargs))]
61+
#[pyo3(signature = (outfile, href, *, intersects=None, ids=None, collections=None, max_items=None, limit=None, bbox=None, datetime=None, include=None, exclude=None, sortby=None, filter=None, query=None, format=None, parquet_compression=None, store=None, use_duckdb=None, **kwargs))]
6262
#[allow(clippy::too_many_arguments)]
6363
pub fn search_to<'py>(
6464
py: Python<'py>,
@@ -77,6 +77,7 @@ pub fn search_to<'py>(
7777
filter: Option<StringOrDict>,
7878
query: Option<Bound<'py, PyDict>>,
7979
format: Option<String>,
80+
parquet_compression: Option<String>,
8081
store: Option<AnyObjectStore>,
8182
use_duckdb: Option<bool>,
8283
kwargs: Option<Bound<'_, PyDict>>,
@@ -95,12 +96,18 @@ pub fn search_to<'py>(
9596
query,
9697
kwargs,
9798
)?;
98-
let format = format
99+
let mut format = format
99100
.map(|s| s.parse())
100101
.transpose()
101102
.map_err(Error::from)?
102103
.or_else(|| Format::infer_from_href(&outfile))
103104
.unwrap_or_default();
105+
if matches!(format, Format::Geoparquet(_)) {
106+
if let Some(parquet_compression) = parquet_compression {
107+
tracing::debug!("setting parquet compression: {parquet_compression}");
108+
format = Format::Geoparquet(Some(parquet_compression.parse().map_err(Error::from)?));
109+
}
110+
}
104111
if use_duckdb
105112
.unwrap_or_else(|| matches!(Format::infer_from_href(&href), Some(Format::Geoparquet(_))))
106113
{

src/write.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ use stac::{Item, ItemCollection};
66
use stac_io::{Format, StacStore};
77

88
#[pyfunction]
9-
#[pyo3(signature = (href, value, *, format=None, store=None, parquet_compression=None))]
9+
#[pyo3(signature = (href, value, *, format=None, parquet_compression=None, store=None))]
1010
pub fn write<'py>(
1111
py: Python<'py>,
1212
href: String,
1313
value: Bound<'_, PyAny>,
1414
format: Option<String>,
15-
store: Option<AnyObjectStore>,
1615
parquet_compression: Option<String>,
16+
store: Option<AnyObjectStore>,
1717
) -> PyResult<Bound<'py, PyAny>> {
1818
let value: Value = pythonize::depythonize(&value)?;
1919
let value = if let Value::Array(array) = value {

0 commit comments

Comments
 (0)