{-- TerraHS - Interface between TerraLib and Haskell

    (c) Sergio Costa (INPE) - Setembro, 2005

	This program is free software; you can redistribute it 
    and/or modify it under the terms of the GNU General 
    Public License 2.1 as published by the Free Software Foundation

{--  --}

module Algebras.Base.Raster
		loadRasterFile, loadRaster, Rasters (..), importRaster, importRasterWParameter

import TerraHS.Misc.Databases

import TerraHS.TerraLib.TeRaster
import TerraHS.TerraLib.TeLayer
import TerraHS.TerraLib.TeDatabase
import Foreign.C.String
import qualified Foreign.Ptr (Ptr)
import TerraHS.Misc.Object

class Rasters r  where
	getValues ::  r a -> [[a]]
	setValues :: [[a]] -> r a
instance Rasters TeRaster where
	getValues (TeRaster rs) = rs
	setValues rs = (TeRaster rs)

instance Databases (TeRaster Double) TeDatabase where
	retrieve db ln = do
		layer <- loadLayer db ln
		ptr <- getRaster layer
		-- convert to haskell object
		raster <- fromPointer ptr 
		return raster
	store db name rs = do
		l <- newCString name
		rsptr <- new rs
		teimportraster l rsptr db