Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Oct 3, 2023
1 parent 981431e commit 79c984e
Show file tree
Hide file tree
Showing 6 changed files with 845 additions and 133 deletions.
2 changes: 2 additions & 0 deletions src/Rasters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ include("methods/burning/geometry.jl")
include("methods/burning/point.jl")
include("methods/burning/line.jl")
include("methods/burning/polygon.jl")
include("methods/burning/extents.jl")
include("methods/burning/utils.jl")

include("methods/shared_docstrings.jl")
include("methods/mask.jl")
Expand Down
9 changes: 9 additions & 0 deletions src/methods/burning/point.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
# TODO use rasterize_points for this instead

# _fill_point!
# Fill a raster with `fill` where points are inside raster pixels
@noinline _fill_point!(x::RasterStackOrArray, geom; kw...) = _fill_point!(x, GI.geomtrait(geom), geom; kw...)
@noinline function _fill_point!(x::RasterStackOrArray, ::GI.GeometryCollectionTrait, geom; kw...)
_without_mapped_crs(x) do x1
for geom in GI.getgeom(geom)
_fill_point!(x, geom; kw...)
end
end
return true
end
@noinline function _fill_point!(x::RasterStackOrArray, ::GI.AbstractGeometryTrait, geom; kw...)
# Just find which pixels contain the points, and set them to true
_without_mapped_crs(x) do x1
Expand Down
29 changes: 19 additions & 10 deletions src/methods/rasterize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -632,11 +632,29 @@ function _rasterize_points!(A, ::GI.AbstractGeometryTrait, geom, fill, r::Raster
fill1 =_iterable_fill(points, fill)
_rasterize_points!(A, nothing, points, fill1, r)
end
function _rasterize_points!(A, ::GI.GeometryCollectionTrait, collection, fill, r::Rasterizer)
# TODO How to handle fill when there is another level of nesting
hasburned = false
for geom in _getgeom(collection)
hasburned |= _rasterize_points!(A, geom, fill, r)
end
return hasburned
end
function _rasterize_points!(A, ::Nothing, geoms, fillitr, r::Rasterizer)
(; reducer, op, missingval, init) = r
t1 = GI.trait(first(skipmissing(geoms)))
hasburned = false
if !(t1 isa GI.PointTrait)
if t1 isa GI.PointTrait
# Get extent information to properly shift the points
# to the region of the array during rounding
ext = Extents.extent(A)
xrange = ext.X[2] - ext.X[1]
yrange = ext.Y[2] - ext.Y[1]
xsize = size(A, X)
ysize = size(A, Y)
s = (; ext, xrange, yrange, xsize, ysize)
return _rasterize_points_inner!(A, geoms, fillitr, s, reducer, op, missingval, init)
else
# Recurse down until we hit points
if r.fillitr isa Function
for geom in _getgeom(geoms)
Expand All @@ -656,15 +674,6 @@ function _rasterize_points!(A, ::Nothing, geoms, fillitr, r::Rasterizer)
end
return hasburned
end
# Get extent information to properly shift the points
# to the region of the array during rounding
ext = Extents.extent(A)
xrange = ext.X[2] - ext.X[1]
yrange = ext.Y[2] - ext.Y[1]
xsize = size(A, X)
ysize = size(A, Y)
s = (; ext, xrange, yrange, xsize, ysize)
_rasterize_points_inner!(A, geoms, fillitr, s, reducer, op, missingval, init)
end

@noinline function _rasterize_points_inner!(A, geoms, fillitr::F, s, reducer::R, op::O, missingval, init)::Bool where {F,O,R}
Expand Down
Loading

0 comments on commit 79c984e

Please sign in to comment.