@@ -80,16 +80,12 @@ pub struct GeometryBuilder {
80
80
81
81
impl < ' a > GeometryBuilder {
82
82
/// Creates a new empty [`GeometryBuilder`].
83
- pub fn new ( typ : GeometryType , prefer_multi : bool ) -> Self {
84
- Self :: with_capacity ( typ, Default :: default ( ) , prefer_multi )
83
+ pub fn new ( typ : GeometryType ) -> Self {
84
+ Self :: with_capacity ( typ, Default :: default ( ) )
85
85
}
86
86
87
87
/// Creates a new [`GeometryBuilder`] with given capacity and no validity.
88
- pub fn with_capacity (
89
- typ : GeometryType ,
90
- capacity : GeometryCapacity ,
91
- prefer_multi : bool ,
92
- ) -> Self {
88
+ pub fn with_capacity ( typ : GeometryType , capacity : GeometryCapacity ) -> Self {
93
89
let metadata = typ. metadata ( ) . clone ( ) ;
94
90
let coord_type = typ. coord_type ( ) ;
95
91
@@ -140,7 +136,6 @@ impl<'a> GeometryBuilder {
140
136
GeometryCollectionBuilder :: with_capacity (
141
137
GeometryCollectionType :: new ( coord_type, dim, Default :: default ( ) ) ,
142
138
capacity. geometry_collection ( dim) ,
143
- prefer_multi,
144
139
)
145
140
} ) ;
146
141
@@ -156,8 +151,27 @@ impl<'a> GeometryBuilder {
156
151
mpolygons,
157
152
gcs,
158
153
offsets : vec ! [ ] ,
159
- prefer_multi,
160
154
deferred_nulls : 0 ,
155
+ prefer_multi : DEFAULT_PREFER_MULTI ,
156
+ }
157
+ }
158
+
159
+ /// Change whether to prefer multi or single arrays for new single-part geometries.
160
+ ///
161
+ /// If `true`, a new `Point` will be added to the `MultiPointBuilder` child array, a new
162
+ /// `LineString` will be added to the `MultiLineStringBuilder` child array, and a new `Polygon`
163
+ /// will be added to the `MultiPolygonBuilder` child array.
164
+ ///
165
+ /// This can be desired when the user wants to downcast the array to a single geometry array
166
+ /// later, as casting to a, say, `MultiPointArray` from a `GeometryArray` could be done
167
+ /// zero-copy.
168
+ ///
169
+ /// Note that only geometries added _after_ this method is called will be affected.
170
+ pub fn with_prefer_multi ( self , prefer_multi : bool ) -> Self {
171
+ Self {
172
+ prefer_multi,
173
+ gcs : self . gcs . map ( |gc| gc. with_prefer_multi ( prefer_multi) ) ,
174
+ ..self
161
175
}
162
176
}
163
177
@@ -285,20 +299,18 @@ impl<'a> GeometryBuilder {
285
299
pub fn with_capacity_from_iter < T : WktNum > (
286
300
geoms : impl Iterator < Item = Option < & ' a ( impl GeometryTrait < T = T > + ' a ) > > ,
287
301
typ : GeometryType ,
288
- prefer_multi : bool ,
289
302
) -> Result < Self > {
290
- let counter = GeometryCapacity :: from_geometries ( geoms, prefer_multi ) ?;
291
- Ok ( Self :: with_capacity ( typ, counter, prefer_multi ) )
303
+ let counter = GeometryCapacity :: from_geometries ( geoms) ?;
304
+ Ok ( Self :: with_capacity ( typ, counter) )
292
305
}
293
306
294
307
/// Reserve more space in the underlying buffers with the capacity inferred from the provided
295
308
/// geometries.
296
309
pub fn reserve_from_iter < T : WktNum > (
297
310
& mut self ,
298
311
geoms : impl Iterator < Item = Option < & ' a ( impl GeometryTrait < T = T > + ' a ) > > ,
299
- prefer_multi : bool ,
300
312
) -> Result < ( ) > {
301
- let counter = GeometryCapacity :: from_geometries ( geoms, prefer_multi ) ?;
313
+ let counter = GeometryCapacity :: from_geometries ( geoms) ?;
302
314
self . reserve ( counter) ;
303
315
Ok ( ( ) )
304
316
}
@@ -308,9 +320,8 @@ impl<'a> GeometryBuilder {
308
320
pub fn reserve_exact_from_iter < T : WktNum > (
309
321
& mut self ,
310
322
geoms : impl Iterator < Item = Option < & ' a ( impl GeometryTrait < T = T > + ' a ) > > ,
311
- prefer_multi : bool ,
312
323
) -> Result < ( ) > {
313
- let counter = GeometryCapacity :: from_geometries ( geoms, prefer_multi ) ?;
324
+ let counter = GeometryCapacity :: from_geometries ( geoms) ?;
314
325
self . reserve_exact ( counter) ;
315
326
Ok ( ( ) )
316
327
}
@@ -786,9 +797,8 @@ impl<'a> GeometryBuilder {
786
797
pub fn from_geometries (
787
798
geoms : & [ impl GeometryTrait < T = f64 > ] ,
788
799
typ : GeometryType ,
789
- prefer_multi : bool ,
790
800
) -> Result < Self > {
791
- let mut array = Self :: with_capacity_from_iter ( geoms. iter ( ) . map ( Some ) , typ, prefer_multi ) ?;
801
+ let mut array = Self :: with_capacity_from_iter ( geoms. iter ( ) . map ( Some ) , typ) ?;
792
802
array. extend_from_iter ( geoms. iter ( ) . map ( Some ) ) ;
793
803
Ok ( array)
794
804
}
@@ -797,10 +807,8 @@ impl<'a> GeometryBuilder {
797
807
pub fn from_nullable_geometries (
798
808
geoms : & [ Option < impl GeometryTrait < T = f64 > > ] ,
799
809
typ : GeometryType ,
800
- prefer_multi : bool ,
801
810
) -> Result < Self > {
802
- let mut array =
803
- Self :: with_capacity_from_iter ( geoms. iter ( ) . map ( |x| x. as_ref ( ) ) , typ, prefer_multi) ?;
811
+ let mut array = Self :: with_capacity_from_iter ( geoms. iter ( ) . map ( |x| x. as_ref ( ) ) , typ) ?;
804
812
array. extend_from_iter ( geoms. iter ( ) . map ( |x| x. as_ref ( ) ) ) ;
805
813
Ok ( array)
806
814
}
@@ -816,7 +824,7 @@ impl<O: OffsetSizeTrait> TryFrom<(WkbArray<O>, GeometryType)> for GeometryBuilde
816
824
. iter ( )
817
825
. map ( |x| x. transpose ( ) )
818
826
. collect :: < Result < Vec < _ > > > ( ) ?;
819
- Self :: from_nullable_geometries ( & wkb_objects, typ, DEFAULT_PREFER_MULTI )
827
+ Self :: from_nullable_geometries ( & wkb_objects, typ)
820
828
}
821
829
}
822
830
@@ -876,7 +884,7 @@ mod test {
876
884
fn all_items_null ( ) {
877
885
// Testing the behavior of deferred nulls when there are no valid geometries.
878
886
let typ = GeometryType :: new ( CoordType :: Interleaved , Default :: default ( ) ) ;
879
- let mut builder = GeometryBuilder :: new ( typ, false ) ;
887
+ let mut builder = GeometryBuilder :: new ( typ) ;
880
888
881
889
builder. push_null ( ) ;
882
890
builder. push_null ( ) ;
@@ -894,7 +902,7 @@ mod test {
894
902
let coord_type = CoordType :: Interleaved ;
895
903
let typ = GeometryType :: new ( coord_type, Default :: default ( ) ) ;
896
904
897
- let mut builder = GeometryBuilder :: new ( typ, false ) ;
905
+ let mut builder = GeometryBuilder :: new ( typ) ;
898
906
builder. push_null ( ) ;
899
907
builder. push_null ( ) ;
900
908
@@ -926,7 +934,7 @@ mod test {
926
934
let coord_type = CoordType :: Interleaved ;
927
935
let typ = GeometryType :: new ( coord_type, Default :: default ( ) ) ;
928
936
929
- let mut builder = GeometryBuilder :: new ( typ, false ) ;
937
+ let mut builder = GeometryBuilder :: new ( typ) ;
930
938
builder. push_null ( ) ;
931
939
builder. push_null ( ) ;
932
940
@@ -966,7 +974,7 @@ mod test {
966
974
let coord_type = CoordType :: Interleaved ;
967
975
let typ = GeometryType :: new ( coord_type, Default :: default ( ) ) ;
968
976
969
- let mut builder = GeometryBuilder :: new ( typ, false ) ;
977
+ let mut builder = GeometryBuilder :: new ( typ) ;
970
978
let point = wkt ! { POINT Z ( 30. 10. 40. ) } ;
971
979
builder. push_point ( Some ( & point) ) . unwrap ( ) ;
972
980
builder. push_null ( ) ;
0 commit comments