


PURPOSE: calculates standard statistics for all cells that fall within a block (neighbourhood)
of defined size at location x-y.
-------------------------------------------------------------------
USAGE: value = block_statistics(scs, tcs, sx, sy, xll, yll, grid)
where:
[scs] is the source cell size of the input grid in map units
[tcs] is the target cell size in map units, that is the size of
the block to calculate statistics for
[sx],[sy] are the the x and y coordinates (center of the analysis
block)
[xll,yll] are the coordinates of the lower left corner of the input grid
[grid] is the grid with the cells to be analysed
-------------------------------------------------------------------------
OUTPUTS:
[value] is a vector holding the statistics of all cells that fall
into the block (>50% area) in the form of
[value(mean,median,1stquartile,3rdquartile,max,min,stdv)]
-------------------------------------------------------------------
NOTES: This function was written to analyse the effect of generalisation.
While usually cells of higher resolution are simply subsampled when
generalising to lower resolution, with this script the mean, min/max,
std etc of all source cells that fall within a larger target cell can be
calculated. Thus, this script can be used to generalise a grid to a lower
resolution using the mean of all underlying higher resolution cells.
SEE ALSO: neighbourhood_statistics
Felix Hebeler, Geography Dept., University Zurich, March 2006.

0001 function value = block_statistics(scs, tcs, sx, sy, xll, yll, grid) 0002 % PURPOSE: calculates standard statistics for all cells that fall within a block (neighbourhood) 0003 % of defined size at location x-y. 0004 % ------------------------------------------------------------------- 0005 % USAGE: value = block_statistics(scs, tcs, sx, sy, xll, yll, grid) 0006 % where: 0007 % [scs] is the source cell size of the input grid in map units 0008 % [tcs] is the target cell size in map units, that is the size of 0009 % the block to calculate statistics for 0010 % [sx],[sy] are the the x and y coordinates (center of the analysis 0011 % block) 0012 % [xll,yll] are the coordinates of the lower left corner of the input grid 0013 % [grid] is the grid with the cells to be analysed 0014 % ------------------------------------------------------------------------- 0015 % OUTPUTS: 0016 % [value] is a vector holding the statistics of all cells that fall 0017 % into the block (>50% area) in the form of 0018 % [value(mean,median,1stquartile,3rdquartile,max,min,stdv)] 0019 % ------------------------------------------------------------------- 0020 % NOTES: This function was written to analyse the effect of generalisation. 0021 % While usually cells of higher resolution are simply subsampled when 0022 % generalising to lower resolution, with this script the mean, min/max, 0023 % std etc of all source cells that fall within a larger target cell can be 0024 % calculated. Thus, this script can be used to generalise a grid to a lower 0025 % resolution using the mean of all underlying higher resolution cells. 0026 % 0027 % SEE ALSO: neighbourhood_statistics 0028 % 0029 % Felix Hebeler, Geography Dept., University Zurich, March 2006. 0030 0031 % get distance of sample cell from llc 0032 dx = abs(xll- sx); dy = abs(yll- sy); 0033 %x = floor(dx/scs)+1; y = floor(dy/scs)+1; % distance to center source cell in cells 0034 i=1; 0035 block=nan(1,size([round((dx - 0.5*tcs)/scs):1:(round((dx + 0.5*tcs)/scs)-1)],2)*size([round((dy - 0.5*tcs)/scs):1:(round((dy + 0.5*tcs)/scs)-1)],2)); 0036 for n = round((dx - 0.5*tcs)/scs):1:(round((dx + 0.5*tcs)/scs)-1) 0037 for m = round((dy - 0.5*tcs)/scs):1:(round((dy + 0.5*tcs)/scs)-1) 0038 block(i) = grid(size(grid,1)-m+1,n+1); 0039 i=i+1; 0040 end 0041 end 0042 value=[mean(block),median(block),quantile(block,[0.25]),quantile(block,[0.75]),max(block),min(block),std(block)]; 0043