Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/methods/rasterize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ struct RasterCreator{E,D,MD,MV,C,MC}
missingval::MV
crs::C
mappedcrs::MC
force::Bool
end
function RasterCreator(to::DimTuple;
eltype,
Expand All @@ -73,11 +74,12 @@ function RasterCreator(to::DimTuple;
mappedcrs=nothing,
name=nothing,
metadata=Metadata(Dict()),
force=false,
kw...
)
name = Symbol(_filter_name(name, fill))
to = _as_intervals(to) # Only makes sense to rasterize to intervals
RasterCreator(eltype, to, filename, suffix, name, metadata, missingval, crs, mappedcrs)
RasterCreator(eltype, to, filename, suffix, name, metadata, missingval, crs, mappedcrs, force)
end
RasterCreator(to::RasterStackOrArray, data; kw...) = RasterCreator(dims(to); kw...)
RasterCreator(to::DimTuple, data; kw...) = RasterCreator(to; kw...)
Expand Down Expand Up @@ -498,7 +500,7 @@ function alloc_rasterize(f, r::RasterCreator;
if prod(size(r.to)) == 0
throw(ArgumentError("Destination array is is empty, with size $(size(r.to))). Rasterization is not possible"))
end
A = create(r.filename, fill=missingval, eltype, r.to; name, missingval, metadata, suffix) do O
A = create(r.filename, fill=missingval, eltype, r.to; name, missingval, metadata, suffix, r.force) do O
f(O)
end
return A
Expand Down
3 changes: 3 additions & 0 deletions test/rasterize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,9 @@ end
end
filename = tempname() * ".tif"
prod_r = rasterize(prod, polygons; res=5, fill=1:4, boundary=:center, filename, threaded)
prod_r2 = rasterize(prod, polygons; res=5, fill=1:4, boundary=:center, filename, threaded, force=true)
@test size(prod_r2) == (11,11)

prod_r = rasterize(prod, polygons; res=5, fill=1:4, boundary=:center, threaded)
@test sum(skipmissing(prod_r)) ==
(12 * 1 + 8 * 2 + 8 * 3 + 12 * 4) + (4 * 1 * 2 + 4 * 2 * 3 + 4 * 3 * 4)
Expand Down
8 changes: 5 additions & 3 deletions test/test_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ end

# create `N` random rasters with eltype `type` and x,y,band size `size`
function temporary_random_rasters(f, N, size, type=UInt8)
filenames = [tempname() * ".tif" for _ in 1:N]
tmpdir = tempname()
mkdir(tmpdir)
filenames = [tempname(tmpdir) * ".tif" for _ in 1:N]
try
for f in filenames
write(f, Raster(rand(type, size); dims=(X(1:size[1]), Y(1:size[2]), Band(1:size[3]))))
for fi in filenames
write(fi, Raster(rand(type, size); dims=(X(1:size[1]), Y(1:size[2]), Band(1:size[3]))))
end
f(filenames)
finally
Expand Down
Loading