PostGIS Raster : Extending PostgreSQL for The Support of ... - CoDE
PostGIS Raster : Extending PostgreSQL for The Support of ... - CoDE
PostGIS Raster : Extending PostgreSQL for The Support of ... - CoDE
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Appendix C<br />
Code Implementation<br />
C.1 Temporal <strong>Raster</strong> Functions<br />
<strong>PostgreSQL</strong> allows also abilities <strong>for</strong> users to define new types and their own functions. <strong>The</strong>n<br />
CREATE AGGREGATE can be used to provide the desired features that are not provided by <strong>PostgreSQL</strong>.<br />
An aggregate function is identified by its name and input data type. An aggregate function is made<br />
from one or two ordinary functions: a state transition function sfunc and an optional final calculation<br />
function ffunc.<br />
An temporary variable <strong>of</strong> type stype is used to hold the current value <strong>of</strong> the state transition<br />
function. At each input data item, the state transition function is invoked to calculate a new state<br />
value. After all the data has been processed, the final function is invoked once to calculate the<br />
aggregate result. If there is no final function then the aggregate returns the current state value as<br />
final result. sum is an example <strong>of</strong> this kind <strong>of</strong> aggregate, where <strong>for</strong> each input, sum adds its value to<br />
current state value and returns the sum <strong>of</strong> all input value as final result.<br />
A final function is specified in the case where the final result is different from the input data type.<br />
Average aggregate function is an example <strong>of</strong> this case and will be examined thereafter. If the final<br />
function is declared "strict", then it will not be called when the current state value is null. Instead a<br />
null result will be returned automatically.<br />
Example <strong>of</strong> creating the aggregate function ST_Avg:<br />
CREATE AGGREGATE ST_Avg(st_rastertemp) (<br />
SFUNC=array_append,<br />
STYPE=st_rastertemp[],<br />
FINALFUNC=ST_AvgTemp<strong>Raster</strong><br />
);<br />
CREATE OR REPLACE FUNCTION ST_AvgTemp<strong>Raster</strong>(arrayRastTemp st_rastertemp[])<br />
RETURNS raster AS<br />
$$<br />
DECLARE<br />
newraster raster;<br />
oldRast1 raster;<br />
oldRast2 raster;<br />
width int;<br />
height int;<br />
cx int;<br />
cy int;<br />
size int;<br />
s int;<br />
value double precision = 0;<br />
intType boolean = true;<br />
92