Home > custom > grid_tools > get_coordinates.m

get_coordinates

PURPOSE ^

PURPOSE: calculate new coordinate vectors for an original grid to be

SYNOPSIS ^

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

DESCRIPTION ^

 PURPOSE:  calculate new coordinate vectors for an original grid to be 
           resampled to new cellsize .
 -------------------------------------------------------------------
 USAGE: [XI,YI] = get_coordinates(X, Y, targetcellsize);
 where: [X,Y] are the coordinates vectors of the input grid
        [targetcellsize] is the target cellsize the new 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/col!) Counting from llc.

 See also: grid2mat(), mat2grid()

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

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