Skip to content

Commit

Permalink
rasterize GeometryCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Oct 3, 2023
1 parent 9e3cc04 commit 00d4564
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/methods/rasterize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ function Rasterizer(::GI.AbstractFeatureTrait, feature; fill, kw...)
# fillval = _featurefillval(feature, fill)
Rasterizer(GI.geometry(feature), fill, fillitr; kw...)
end
function Rasterizer(::GI.GeometryCollectionTrait, collection; kw...)
Rasterizer(collect(GI.getgeom(collection)); kw...)
end
function Rasterizer(::Nothing, geoms; fill, kw...)
fillitr = _iterable_fill(geoms, fill)
Rasterizer(geoms, fill, fillitr; kw...)
Expand Down
9 changes: 5 additions & 4 deletions test/rasterize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ multi_point = ArchGDAL.createmultipoint(pointvec)
linestring = ArchGDAL.createlinestring(pointvec)
multi_linestring = ArchGDAL.createmultilinestring([pointvec])
linearring = ArchGDAL.createlinearring(pointvec)
collection = GeoInterface.GeometryCollection([linestring, multi_linestring])
pointfc = map(GeoInterface.getpoint(polygon), vals) do geom, v
(geometry=geom, val1=v, val2=2.0f0v)
end
Expand All @@ -43,7 +44,7 @@ st = RasterStack((A1, copy(A1)))
geom = linearring
geom = pointvec

for A in (A1, A2), geom in (pointvec, pointfc, multi_point, linestring, multi_linestring, linearring, polygon, multi_polygon, table)
for A in (A1, A2), geom in (pointvec, pointfc, multi_point, linestring, multi_linestring, linearring, polygon, multi_polygon, table, collection)
fill!(A, 0)
rasterize!(sum, A, geom; shape=:point, fill=1);
@test sum(A) == 5.0
Expand All @@ -57,7 +58,7 @@ st = RasterStack((A1, copy(A1)))
end
end
geom = multi_point
for A in (A1, A2), geom in (table, pointvec, pointfc, multi_point, linestring, multi_linestring, linearring, polygon, multi_polygon)
for A in (A1, A2), geom in (table, pointvec, pointfc, multi_point, linestring, multi_linestring, linearring, polygon, multi_polygon, collection)
st.layer1 .= st.layer2 .= 0
rasterize!(sum, st, geom; shape=:point, fill=(layer1=2, layer2=3))
@test sum(st[:layer1]) == 10
Expand Down Expand Up @@ -91,13 +92,13 @@ end
@testset "all line and polygon geoms work as :line" begin
A = A1
geom = linestring
for A in (A1, A2), geom in (linestring, multi_linestring, linearring, polygon, multi_polygon)
for A in (A1, A2), geom in (linestring, multi_linestring, linearring, polygon, multi_polygon, collection)
A .= 0
rasterize!(sum, A, geom; shape=:line, fill=1)
@test sum(A) == 20 + 20 + 20 + 20
end
@testset ":line is detected for line geometries" begin
for A in (A1, A2), geom in (linestring, multi_linestring)
for A in (A1, A2), geom in (linestring, multi_linestring, collection)
A .= 0
rasterize!(A, geom; fill=1)
@test sum(A) == 20 + 20 + 20 + 20
Expand Down

0 comments on commit 00d4564

Please sign in to comment.