Skip to content

Commit

Permalink
Fixed profile tool.
Browse files Browse the repository at this point in the history
  • Loading branch information
evetion committed Dec 14, 2022
1 parent 8adfb28 commit 87202ca
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
ArchGDAL = "0.7 - 0.9"
CoordinateTransformations = "0.5 - 0.6"
GeoFormatTypes = "0.4"
GeoInterface = "1"
GeoStatsBase = "0.21 - 0.25"
IterTools = "1"
RecipesBase = "0.7, 0.8, 1.0"
StaticArrays = "0.12, 1.0"
julia = "1.6 - 1"
25 changes: 13 additions & 12 deletions src/geoutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -261,18 +261,19 @@ function profile!(values, ga, a, b, band)

δx = i1 - i0
δy = j1 - j0
δe = abs(δy / δx)
er = 0.0

j = j0
ystep = δy > 0 ? 1 : -1
xstep = i0 < i1 ? 1 : -1
for i in i0:xstep:i1
push!(values, ga[i, j, band])
er += δe
if er > 0.5
j += ystep
er -= 1.0

if abs(δx) >= abs(δy)
j = j0
xstep = δx > 0 ? 1 : -1
for (d, i) in enumerate(i0:xstep:i1)
push!(values, ga[i, j+div((d - 1) * δy, abs(δx), RoundNearest), band])
end
else
i = i0
ystep = δy > 0 ? 1 : -1
for (d, j) in enumerate(j0:ystep:j1)
push!(values, ga[i+div((d - 1) * δx, abs(δy), RoundNearest), j, band])
end
end
return indices
end
6 changes: 6 additions & 0 deletions test/test_geoutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ const tbbox = (min_x=440720.0, min_y=3.74532e6, max_x=446720.0, max_y=3.75132e6)
ga = GeoArray(rand(4, 4))
values = GeoArrays.profile(ga, LineString())
@test length(values) == 3

GI.getgeom(::GI.LineStringTrait, ::LineString) = [[3, 4], [1, 2]]
values2 = GeoArrays.profile(ga, LineString())
@test length(values2) == 3
@test values == reverse(values2)

end

end

2 comments on commit 87202ca

@evetion
Copy link
Owner Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/74112

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.10 -m "<description of version>" 87202caf5e7cb20cb47e9c1b4bf355c5a895f7a1
git push origin v0.7.10

Please sign in to comment.