Home > custom > grid_tools > initialise_target_grid.m

initialise_target_grid

PURPOSE ^

PURPOSE: calculate coordinate vectors for a grid to be resampled to new cellsize .

SYNOPSIS ^

function [XI,YI] = initialise_target_grid(X, Y, targetcellsize)

DESCRIPTION ^

 PURPOSE:  calculate coordinate vectors for a grid to be resampled to new cellsize .
 -------------------------------------------------------------------
 USAGE: [XI,YI] = initialise_target_grid(X, Y, targetcellsize);
 where: [X,Y] are the coordinates vectors of the input grid
        [targetcellsize] is the target cellsize the grid shall be resampled to
 RETURNS:
        [XI],[YI] = the x and y coordinate vectors of the new resampled
        grid
 -------------------------------------------------------------------
 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. (rounding errors might cut 1 row!) Couting from llc.

 Felix Hebeler, Geography Dept., University Zurich, March 2006.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [XI,YI] = initialise_target_grid(X, Y, targetcellsize)
0002 % PURPOSE:  calculate coordinate vectors for a grid to be resampled to new cellsize .
0003 % -------------------------------------------------------------------
0004 % USAGE: [XI,YI] = initialise_target_grid(X, Y, targetcellsize);
0005 % where: [X,Y] are the coordinates vectors of the input grid
0006 %        [targetcellsize] is the target cellsize the grid shall be resampled to
0007 % RETURNS:
0008 %        [XI],[YI] = the x and y coordinate vectors of the new resampled
0009 %        grid
0010 % -------------------------------------------------------------------
0011 % NOTES: All coordinates used are lower left corner coordinates! New matrix
0012 %        has no of rows and cols that sum up to either same size or less than
0013 %        original grid. If extent does not match, rows and cols are rounded
0014 %        down. (rounding errors might cut 1 row!) Couting from llc.
0015 %
0016 % Felix Hebeler, Geography Dept., University Zurich, March 2006.
0017 
0018 xll = min(X);
0019 yll = min(Y);
0020 cols = size(X,2);
0021 rows = size(Y,2);
0022 xcs=abs(X(1)-X(2));
0023 ycs=abs(Y(1)-Y(2));
0024 
0025 ncols = round(cols*xcs/targetcellsize);
0026 nrows = round(rows*ycs/targetcellsize);
0027 %ncols = floor(cols*xcs/targetcellsize);
0028 %nrows = floor(rows*ycs/targetcellsize);
0029 
0030 
0031 % construct index vectors of llc coords
0032 nx = xll + (0.5*targetcellsize) - (0.5*xcs) + [0:targetcellsize:(ncols-1)*targetcellsize];
0033 ny = yll + (0.5*targetcellsize) - (0.5*ycs) + [0:targetcellsize:(nrows-1)*targetcellsize]; ny=ny(end:-1:1);
0034 
0035 [XI,YI]=meshgrid(nx,ny);

Generated on Tue 24-Feb-2009 19:14:50 by m2html © 2003