


PURPOSE: calculate coordinate vectors and target grid size for a grid to
be resampled to a new cellsize .
-------------------------------------------------------------------------
USAGE: [nx,ny,newgrid] = get_target_gridsize(xll, yll, cols,rows,cellsize,targetcellsize);
where:
[xll,yll] are the coordinates of the lower left corner of the input grid
[cols],[rows] are the number of columns and rows of the existing
grid
[cellsize] is the current cellsize of the original grid
[targetcellsize] is the target cellsize the grid is resampled to
-------------------------------------------------------------------------
OUTPUTS:
[nx],[ny] are the x and y coordinate vectors of the new resampled
grid
[newgrid] is a matrix with cols and rows according to the new
cellsize
-------------------------------------------------------------------------
NOTES: All coordinates used are lower left corner coordinates! New matrix
has no of rows and cols that sum up to either same size or less than
original grid. If extent does not match, rows and cols are rounded
down. Couting from llc.
Felix Hebeler, Geography Dept., University Zurich, March 2006.

0001 function [nx,ny,newgrid] = get_target_gridsize(xll, yll, cols,rows,cellsize,targetcellsize); 0002 0003 % PURPOSE: calculate coordinate vectors and target grid size for a grid to 0004 % be resampled to a new cellsize . 0005 % ------------------------------------------------------------------------- 0006 % USAGE: [nx,ny,newgrid] = get_target_gridsize(xll, yll, cols,rows,cellsize,targetcellsize); 0007 % where: 0008 % [xll,yll] are the coordinates of the lower left corner of the input grid 0009 % [cols],[rows] are the number of columns and rows of the existing 0010 % grid 0011 % [cellsize] is the current cellsize of the original grid 0012 % [targetcellsize] is the target cellsize the grid is resampled to 0013 % ------------------------------------------------------------------------- 0014 % OUTPUTS: 0015 % [nx],[ny] are the x and y coordinate vectors of the new resampled 0016 % grid 0017 % [newgrid] is a matrix with cols and rows according to the new 0018 % cellsize 0019 % ------------------------------------------------------------------------- 0020 % NOTES: All coordinates used are lower left corner coordinates! New matrix 0021 % has no of rows and cols that sum up to either same size or less than 0022 % original grid. If extent does not match, rows and cols are rounded 0023 % down. Couting from llc. 0024 % 0025 % Felix Hebeler, Geography Dept., University Zurich, March 2006. 0026 0027 ncols = floor(cols*cellsize/targetcellsize); 0028 nrows = floor(rows*cellsize/targetcellsize); 0029 newgrid = zeros(nrows, ncols); 0030 0031 % construct index vectors of llc coords 0032 nx = xll + [0:targetcellsize:(ncols-1)*targetcellsize]; 0033 ny = yll + [0:targetcellsize:(nrows-1)*targetcellsize];