Skip to content

Commit 063d825

Browse files
CHG: handle different types of geotiffs
1 parent 19232cd commit 063d825

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/m/modeldata/ReadGeotiff.m

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,27 @@
1818
Tinfo = imfinfo(geotiffname);
1919
N = Tinfo(1).Width;
2020
M = Tinfo(1).Height;
21-
dx = Tinfo(1).ModelPixelScaleTag(1);
22-
dy = Tinfo(1).ModelPixelScaleTag(2);
23-
minx = Tinfo(1).ModelTiepointTag(4);
24-
maxy = Tinfo(1).ModelTiepointTag(5);
21+
if isfield(Tinfo(1),'ModelPixelScaleTag')
22+
dx = Tinfo(1).ModelPixelScaleTag(1);
23+
dy = Tinfo(1).ModelPixelScaleTag(2);
24+
minx = Tinfo(1).ModelTiepointTag(4);
25+
maxy = Tinfo(1).ModelTiepointTag(5);
26+
assert(dx>0); assert(dy>0);
27+
elseif isfield(Tinfo(1),'ModelTransformationTag')
28+
dx = Tinfo(1).ModelTransformationTag(1);
29+
dy = -Tinfo(1).ModelTransformationTag(6);
30+
minx = Tinfo(1).ModelTransformationTag(4);
31+
maxy = Tinfo(1).ModelTransformationTag(8);
32+
assert(dx>0); assert(dy<0);
33+
else
34+
error('image info cannot be retrieved for this geotiff');
35+
end
2536

2637
%Generate vectors
2738
xm = minx + dx/2 + ((0:N-1).*dx);
2839
ym = maxy - dy/2 - ((M -1:-1:0).*dy);
2940

3041
%Read image
31-
assert(dx>0); assert(dy>0);
3242
ym = fliplr(ym);
3343

3444
data = double(imread(geotiffname));

0 commit comments

Comments
 (0)