wschwanghart / topotoolbox

A MATLAB software for the analysis of digital elevation models -
https://topotoolbox.wordpress.com/
153 stars 89 forks source link

self-correcting error in polygon2GRIDobj #39

Closed oejwing closed 1 month ago

oejwing commented 1 year ago

In getmask, getextent is called with the order of the arguments being row/lat/y first and col/lon/x second. https://github.com/wschwanghart/topotoolbox/blob/21c93eb000e2bae559ba5669e92b609d3cef2018/%40GRIDobj/polygon2GRIDobj.m#L240

However, getextent requires the order to the opposite. https://github.com/wschwanghart/topotoolbox/blob/21c93eb000e2bae559ba5669e92b609d3cef2018/%40GRIDobj/polygon2GRIDobj.m#L272-L275

This means getmask has swapped X and Y dimensions. Fortunately, the ext(1:2) refers to Y and ext(3:4) refers to X, so the error corrects itself. But I suggest returning ext = [min(y) max(y) min(x) max(x)]; in getextent and call getextent(c,r) in getmask.

oejwing commented 1 year ago

(potentially we also just have different definitions of how x,y map to row,col!)

wschwanghart commented 1 year ago

Hi @oejwing well spotted ;-). I agree that the naming of the variables in getextent is confusing, and x and should be renamed to row and y should be col. I will change this because otherwise, this really makes reading the code difficult. In the end, it doesn't produce an error. In the end, it is the order to which we are used to and which is confusing: lat lon, x y, row col... Cheers, Wolfgang