Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix polygonize with LinRange #190

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 2 additions & 2 deletions src/methods/polygonize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ function _polygonize(f::Base.Callable, xs::AbstractRange, ys::AbstractRange, A::
ybounds = first(ys) - yhalf : step(ys) : last(ys) + yhalf
Tx = eltype(xbounds)
Ty = eltype(ybounds)
xvec = similar(Vector{Tuple{Tx,Tx}}, xs)
yvec = similar(Vector{Tuple{Ty,Ty}}, ys)
xvec = similar(Vector{Tuple{Tx,Tx}}, axes(xs))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
xvec = similar(Vector{Tuple{Tx,Tx}}, axes(xs))
xvec = Vector{Vector{Tuple{Tx,Tx}}}(undef, length(axes(xs)))

Wont something like this work and skip the complexity of similar?

yvec = similar(Vector{Tuple{Ty,Ty}}, axes(ys))
for (xind, i) in enumerate(eachindex(xvec))
xvec[i] = xbounds[xind], xbounds[xind+1]
end
Expand Down
9 changes: 7 additions & 2 deletions test/methods/polygonize.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using GeometryOps, GeoInterface, Test
import OffsetArrays, DimensionalData, Rasters

# Missing holes throw a warning, so testing there are
# no warnings in a range of randomisation is one way to test
Expand Down Expand Up @@ -39,6 +38,12 @@ for i in (100, 300), j in (100, 300)
end
end

@testset "LinRange and offset arrays (#187)" begin
# Test that polygonize with LinRange axes works
@test_nowarn polygonize(1:10, 1:20, rand(Bool, 10, 20))
end

import OffsetArrays, DimensionalData, Rasters

@testset "Polygonize with exotic arrays" begin
@testset "OffsetArrays" begin
Expand Down Expand Up @@ -66,4 +71,4 @@ end
@test GO.equals(data_mp, evil_mp)
@test GI.crs(evil_mp) == GI.crs(evil)
end
end
end
Loading