@@ -148,7 +148,7 @@ function Rasterizer(data::T; fill, geomcolumn=nothing, kw...) where T
148
148
schema = Tables. schema (data)
149
149
cols = Tables. columns (data)
150
150
colnames = Tables. columnnames (Tables. columns (data))
151
- fillitr = _iterable_fill (cols, fill)
151
+ fillitr = _iterable_fill (nothing , cols, fill)
152
152
# If fill is a symbol or tuple of Symbol we need to allocate based on the column type
153
153
geomcolname = if isnothing (geomcolumn)
154
154
geomcols = GI. geometrycolumns (data)
@@ -171,27 +171,27 @@ function Rasterizer(data::T; fill, geomcolumn=nothing, kw...) where T
171
171
Rasterizer (GeoInterface. trait (data), data; fill, kw... )
172
172
end
173
173
end
174
- function Rasterizer (:: GI.AbstractFeatureCollectionTrait , fc; name, fill, kw... )
175
- # TODO : how to handle when there are fillvals with different types
176
- # fillval = _featurefillval(GI.getfeature(fc, 1), fill)
177
- fillitr = _iterable_fill (fc, fill)
178
- geometries = map (f -> GI. geometry (f), GI. getfeature (fc))
179
- Rasterizer (geometries; kw... , fill, fillitr)
174
+ function Rasterizer (trait:: GI.AbstractFeatureCollectionTrait , fc; fill, kw... )
175
+ fillitr = _iterable_fill (trait, fc, fill)
176
+ geoms = map (f -> GI. geometry (f), GI. getfeature (fc))
177
+ Rasterizer (geoms, fill, fillitr; kw... )
180
178
end
181
- function Rasterizer (:: GI.AbstractFeatureTrait , feature; fill, kw... )
182
- fillitr = _iterable_fill (feature, fill)
183
- # fillval = _featurefillval (feature, fill )
184
- Rasterizer (GI . geometry (feature) , fill, fillitr; kw... )
179
+ function Rasterizer (trait :: GI.AbstractFeatureTrait , feature; fill, kw... )
180
+ fillitr = _iterable_fill (trait, feature, fill)
181
+ geom = GI . geometry (feature)
182
+ Rasterizer (geom , fill, fillitr; kw... )
185
183
end
186
- function Rasterizer (:: GI.GeometryCollectionTrait , collection; kw... )
187
- Rasterizer (collect (GI. getgeom (collection)); kw... )
184
+ function Rasterizer (trait:: GI.GeometryCollectionTrait , collection; kw... )
185
+ geoms = collect (GI. getgeom (collection))
186
+ Rasterizer (geoms; kw... )
188
187
end
189
- function Rasterizer (:: Nothing , geoms; fill, kw... )
190
- fillitr = _iterable_fill (geoms, fill)
188
+ function Rasterizer (trait :: Nothing , geoms; fill, kw... )
189
+ fillitr = _iterable_fill (trait, geoms, fill)
191
190
Rasterizer (geoms, fill, fillitr; kw... )
192
191
end
193
- function Rasterizer (:: GI.AbstractGeometryTrait , geom; fill, kw... )
194
- Rasterizer (geom, fill, _iterable_fill (geom, fill); kw... )
192
+ function Rasterizer (trait:: GI.AbstractGeometryTrait , geom; fill, kw... )
193
+ fillitr = _iterable_fill (trait, geom, fill)
194
+ Rasterizer (geom, fill, fillitr; kw... )
195
195
end
196
196
197
197
function get_eltype_missingval (eltype, missingval, fill, fillitr, init, filename, op, reducer)
@@ -274,51 +274,53 @@ function _filter_name(name, fill)
274
274
end
275
275
276
276
# A Tuple of `Symbol` is multiple keys to make a RasterStack
277
- _iterable_fill (data, keys:: Tuple{Symbol,Vararg} ) =
278
- NamedTuple {keys} (map (k -> _iterable_fill (data, k), keys))
277
+ _iterable_fill (trait, data, keys:: Tuple{Symbol,Vararg} ) =
278
+ NamedTuple {keys} (map (k -> _iterable_fill (trait, data, k), keys))
279
279
# A Symbol is a Table or FeatureCollection key, it cant be used as fill itself
280
- function _iterable_fill (data, key:: Symbol )
280
+ function _iterable_fill (trait, data, key:: Symbol )
281
281
if GI. isfeature (data)
282
- return get (x -> error (" feature has no key $key " ), GI. properties (data), key)
282
+ return get (() -> throw (ArgumentError (" feature has no property `:$key `" )), GI. properties (data), key)
283
+ elseif trait isa GI. FeatureCollectionTrait
284
+ return [get (() -> throw (ArgumentError (" feature has no property `:$key `" )), GI. properties (f), key) for f in GI. getfeature (data)]
283
285
end
284
286
cols = Tables. columns (data)
285
287
# For column tables, get the column now
286
288
names = Tables. columnnames (cols)
287
289
key in names || _fill_key_error (names, key)
288
290
return Tables. getcolumn (cols, key)
289
291
end
290
- _iterable_fill (data, fill:: Function ) = fill
291
- _iterable_fill (data, fill:: NamedTuple ) = begin
292
- map (f -> _iterable_fill (data, f), fill)
292
+ _iterable_fill (trait, data, fill:: Function ) = fill
293
+ _iterable_fill (trait, data, fill:: NamedTuple ) = begin
294
+ map (f -> _iterable_fill (trait, data, f), fill)
293
295
end
294
- # Inspect our data and fill as much as possible to check they match
295
- # and cycle any fill of known length one
296
- function _iterable_fill (data, fill)
297
- if GI. isgeometry (data) || GI. isfeature (data)
296
+ function _iterable_fill (trait, data, fill)
297
+ # trait isa Union{GI.AbstractGeometryTrait,GI.FeatureTrait} && return fill
298
+ if trait isa GI. AbstractGeometryTrait || trait isa GI. FeatureTrait
298
299
return fill
299
- end
300
- if fill isa Number
300
+ elseif fill isa Number
301
301
return Iterators. cycle (fill)
302
- end
303
- if Tables. istable (typeof (data))
302
+ elseif Tables. istable (typeof (data))
304
303
# we don't need the keys, just the column length
305
304
data = first (Tables. columns (data))
306
305
end
307
- if Base. IteratorSize (data) isa Union{Base. HasShape,Base. HasLength}
308
- fillvec = collect (fill)
309
- l = length (fillvec)
306
+
307
+ if trait isa GI. FeatureCollectionTrait
308
+ n = GI. nfeature (data)
309
+ elseif Base. IteratorSize (data) isa Union{Base. HasShape,Base. HasLength}
310
310
n = length (data)
311
- if l == 1
312
- # Cycle all length one iterables to fill every row
313
- return Iterators. cycle (fillvec[1 ])
314
- elseif ! (l == n)
315
- throw (ArgumentError (" Length of fill $l does not match length of iterator $n " ))
316
- else
317
- return fillvec
318
- end
319
311
else
320
312
return fill
321
313
end
314
+ fillvec = collect (fill)
315
+ l = length (fillvec)
316
+ if l == 1
317
+ # Cycle all length one iterables to fill every row
318
+ return Iterators. cycle (fillvec[1 ])
319
+ elseif ! (l == n)
320
+ throw (ArgumentError (" Length of fill $l does not match length of iterator $n " ))
321
+ else
322
+ return fillvec
323
+ end
322
324
end
323
325
324
326
_getfill (itrs:: NamedTuple , i:: Int ) = map (itr -> _getfill (itr, i), itrs)
660
662
_rasterize_points! (A, r:: Rasterizer ) = _rasterize_points! (A, r. geom, r. fillitr, r)
661
663
_rasterize_points! (A, geom, fillitr, r:: Rasterizer ) =
662
664
_rasterize_points! (A, GI. trait (geom), geom, fillitr, r)
663
- function _rasterize_points! (A, :: GI.AbstractGeometryTrait , geom, fill, r:: Rasterizer )
665
+
666
+ function _rasterize_points! (A, trait:: GI.AbstractGeometryTrait , geom, fill, r:: Rasterizer )
664
667
points = GI. getpoint (geom)
665
- fill1 = _iterable_fill (points, fill)
668
+ fill1 = _iterable_fill (nothing , points, fill)
666
669
_rasterize_points! (A, nothing , points, fill1, r)
667
670
end
668
671
function _rasterize_points! (A, :: GI.GeometryCollectionTrait , collection, fill, r:: Rasterizer )
0 commit comments