@@ -5,7 +5,7 @@ use crate::{
55 geoarrow:: { Table , VERSION , VERSION_KEY } ,
66} ;
77use bytes:: Bytes ;
8- use geoarrow_geoparquet :: { GeoParquetRecordBatchReaderBuilder , GeoParquetWriterOptions } ;
8+ use geoparquet :: { GeoParquetRecordBatchReaderBuilder , GeoParquetWriterOptions } ;
99use parquet:: {
1010 file:: { properties:: WriterProperties , reader:: ChunkReader } ,
1111 format:: KeyValue ,
@@ -53,7 +53,7 @@ pub fn into_writer<W>(writer: W, item_collection: impl Into<ItemCollection>) ->
5353where
5454 W : Write + Send ,
5555{
56- into_writer_with_options ( writer, item_collection, & Default :: default ( ) )
56+ into_writer_with_options ( writer, item_collection, Default :: default ( ) )
5757}
5858
5959/// Writes a [ItemCollection] to a [std::io::Write] as
8989 } ] ) )
9090 . build ( ) ;
9191 options. writer_properties = Some ( writer_properties) ;
92- into_writer_with_options ( writer, item_collection, & options)
92+ into_writer_with_options ( writer, item_collection, options)
9393}
9494
9595/// Writes a [ItemCollection] to a [std::io::Write] as
@@ -103,18 +103,25 @@ where
103103///
104104/// let item: Item = stac::read("examples/simple-item.json").unwrap();
105105/// let mut cursor = Cursor::new(Vec::new());
106- /// stac::geoparquet::into_writer_with_options(&mut cursor, vec![item], & Default::default()).unwrap();
106+ /// stac::geoparquet::into_writer_with_options(&mut cursor, vec![item], Default::default()).unwrap();
107107/// ```
108108pub fn into_writer_with_options < W > (
109109 writer : W ,
110110 item_collection : impl Into < ItemCollection > ,
111- options : & GeoParquetWriterOptions ,
111+ mut options : GeoParquetWriterOptions ,
112112) -> Result < ( ) >
113113where
114114 W : Write + Send ,
115115{
116+ if let Some ( primary_column) = options. primary_column . as_deref ( ) {
117+ if primary_column != "geometry" {
118+ log:: warn!( "primary column not set to 'geometry'" ) ;
119+ }
120+ } else {
121+ options. primary_column = Some ( "geometry" . to_string ( ) ) ;
122+ }
116123 let table = Table :: from_item_collection ( item_collection) ?;
117- geoarrow_geoparquet :: write_geoparquet ( Box :: new ( table. into_reader ( ) ) , writer, options) ?;
124+ geoparquet :: write_geoparquet ( Box :: new ( table. into_reader ( ) ) , writer, & options) ?;
118125 Ok ( ( ) )
119126}
120127/// Create a STAC object from geoparquet data.
@@ -255,6 +262,7 @@ impl IntoGeoparquet for serde_json::Value {
255262mod tests {
256263 use crate :: { FromGeoparquet , Item , ItemCollection , SelfHref , Value } ;
257264 use bytes:: Bytes ;
265+ use parquet:: file:: reader:: { FileReader , SerializedFileReader } ;
258266 use std:: {
259267 fs:: File ,
260268 io:: { Cursor , Read } ,
@@ -296,6 +304,27 @@ mod tests {
296304 assert_eq ! ( item_collection. items. len( ) , 2 ) ;
297305 }
298306
307+ #[ test]
308+ fn geometry_primary_column ( ) {
309+ // https://github.com/stac-utils/rustac/issues/755
310+ let item_collection: ItemCollection = crate :: read ( "data/multi-polygons.json" ) . unwrap ( ) ;
311+ let mut cursor = Cursor :: new ( Vec :: new ( ) ) ;
312+ super :: into_writer ( & mut cursor, item_collection) . unwrap ( ) ;
313+ let bytes = Bytes :: from ( cursor. into_inner ( ) ) ;
314+ let reader = SerializedFileReader :: new ( bytes) . unwrap ( ) ;
315+ let key_value = reader
316+ . metadata ( )
317+ . file_metadata ( )
318+ . key_value_metadata ( )
319+ . unwrap ( )
320+ . into_iter ( )
321+ . find ( |key_value| key_value. key == "geo" )
322+ . unwrap ( ) ;
323+ let value: serde_json:: Value =
324+ serde_json:: from_str ( key_value. value . as_deref ( ) . unwrap ( ) ) . unwrap ( ) ;
325+ assert_eq ! ( value[ "primary_column" ] , "geometry" ) ;
326+ }
327+
299328 #[ test]
300329 fn from_bytes ( ) {
301330 let mut buf = Vec :: new ( ) ;
0 commit comments