Skip to content

Commit f6f5a22

Browse files
authored
Allow extracting full range of x and y coordinates (evetion#27)
1 parent 6f83bb1 commit f6f5a22

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

src/geoarray.jl

+32
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,35 @@ function indexmissing(ga::GeoArray)
7373
(ui, uj) = size(ga)[1:2]
7474
ci = [[i,j] for i in 1:ui, j in 1:uj if ismissing(ga.A[i, j])]
7575
end
76+
77+
# Generate coordinates for one dimension of a GeoArray
78+
function coords(ga::GeoArray, dim::Symbol)
79+
if is_rotated(ga)
80+
error("This method cannot be used for a rotated GeoArray")
81+
end
82+
if dim==:x
83+
ui = size(ga,1)
84+
ci = [coords(ga, SVector{2}(i,1))[1] for i in 1:ui+1]
85+
elseif dim==:y
86+
uj = size(ga,2)
87+
ci = [coords(ga, SVector{2}(1,j))[2] for j in 1:uj+1]
88+
else
89+
error("Use :x or :y as second argument")
90+
end
91+
return ci
92+
end
93+
function centercoords(ga::GeoArray, dim::Symbol)
94+
if is_rotated(ga)
95+
error("This method cannot be used for a rotated GeoArray")
96+
end
97+
if dim==:x
98+
ui = size(ga,1)
99+
ci = [centercoords(ga, SVector{2}(i,1))[1] for i in 1:ui]
100+
elseif dim==:y
101+
uj = size(ga,2)
102+
ci = [centercoords(ga, SVector{2}(1,j))[2] for j in 1:uj]
103+
else
104+
error("Use :x or :y as second argument")
105+
end
106+
return ci
107+
end

test/test_geoarray.jl

+11
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,14 @@
55
@test bboxes(ga)[1] == (min_x=440720.0, max_x=440780.0, min_y=3.75126e6, max_y=3.75132e6)
66
@test bboxes(ga)[end] == (min_x=446660.0, max_x=446720.0, min_y=3.74532e6, max_y=3.74538e6)
77
end
8+
9+
using CoordinateTransformations
10+
@testset "coords" begin
11+
straight = GeoArray(rand(5, 5, 1), AffineMap([1.0 0.0; 0.0 -1.0], [375000.03, 380000.03]),"")
12+
rot = GeoArray(rand(5, 5, 1), AffineMap([1.0 0.5; 0.1 1.0], [0.0, 0.0]),"")
13+
@test coords(straight, :x) == collect(375000.03:1:375005.03)
14+
@test coords(straight, :y) == collect(380000.03:-1:379995.03)
15+
@test_throws ErrorException coords(straight, :z)
16+
@test_throws ErrorException coords(rot, :x)
17+
@test_throws ErrorException coords(rot, :y)
18+
end

0 commit comments

Comments
 (0)