13.07.2013 Views

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

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

BEGIN<br />

newraster := arrayRastTemp[1].rast;<br />

width := ST_Width(newraster);<br />

height := ST_Height(newraster);<br />

size := array_upper(arrayRastTemp,1);<br />

-- Determine pixel type <strong>of</strong> temporal rasters<br />

IF ST_BandPixelType(newraster) = ’32BF’ OR ST_BandPixelType(newraster) = ’64BF’<br />

THEN intType = false;<br />

END IF;<br />

-- Check if all temporal rasters have same dimensions<br />

IF ST_Width(oldRast1) != ST_Width(oldRast2) OR ST_Width(oldRast1) != ST_Width(oldRast2)<br />

THEN<br />

-- If not then the function raises error<br />

RAISE EXCEPTION ’ST_Sum<strong>Raster</strong>: Attempting to sum a band with different width or height<br />

END IF;<br />

FOR cx IN 1..width LOOP<br />

FOR cy IN 1..height LOOP<br />

FOR s IN 1.. size LOOP<br />

value := value + ST_Value(arrayRastTemp[s].rast,cx,cy);<br />

END LOOP;<br />

value = value/size;<br />

-- Cast the result to an appropriate type<br />

IF intType = true<br />

THEN newraster := ST_SetValue(newraster,cx,cy,value::int);<br />

ELSE newraster := ST_SetValue(newraster,cx,cy,value);<br />

END IF;<br />

value := 0;<br />

END LOOP;<br />

END LOOP;<br />

RETURN newraster;<br />

END;<br />

$$<br />

LANGUAGE ’plpgsql’ IMMUTABLE STRICT;<br />

C.2 Temporal <strong>Raster</strong> Application<br />

Python code <strong>for</strong> loading layers into QGIS:<br />

def iniLayers(self):<br />

# Retrieve a connection string<br />

connstring=str(conn.getConnString(self,self.connection))<br />

# Retrieve a list <strong>of</strong> layer IDs<br />

rids=conn.listRIDs(self, connstring, str(self.table))<br />

# Change QGIS cursor to <strong>PostgreSQL</strong> cursor<br />

QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))\\<br />

<strong>for</strong> rid in rids:<br />

# Split table name from schema<br />

connstring = str(conn.getConnString(self,self.connection))<br />

table=str(self.table).split(".")<br />

93

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!