module TerraHS.Misc.Translib --( -- saveVectorFile, -- loadVectorFile --) where import TerraHS.TerraLib import TerraHS.TerraLib.TeGeoObject import TerraHS.Algebras.Base import Foreign import Foreign.C import Foreign.C.String import qualified System.IO.Unsafe (unsafePerformIO) import qualified Foreign.Ptr (Ptr) import qualified Data.Int (Int32) data TESTIntanceSet = TESTIntanceSet deriving (Show) data VectorFile = VectorFile deriving (Show) type TESTIntanceSetPTR = Foreign.Ptr.Ptr TESTIntanceSet -- | Load a geoobject collection from a vector file in Esri shape file format (*.shp) loadVectorFile fn = (newCString fn >>= \cfn -> teinstanceset_new >>= \instances -> file2instances cfn instances >> (testinstances2geos instances)) -- | Save a a geoobject collection to a vector file from a Esri shape file format (*.shp). saveVectorFile gos fn = do cfn <- newCString fn cln <- newCString "name" layer <- melayer_new cln toLayer layer gos exportshapefile layer cfn testinstances2geos ptr = teinstanceset_size ptr >>= \s -> (toInstances ptr 0 s) toInstances p i s = do if i >= s then return [] else teinstanceset_getteinstance p i >>= testInstance2geObject4 >>= \x -> toInstances p (i+1) s >>= \xs -> return (x : xs) -- essa era a versao correta, eu tive que modifica-la por causa de um erro na terralib, preciso testar depois testInstance2geObject4 :: TeSTInstancePtr -> IO TeGeoObject testInstance2geObject4 st = objectId st >>= \obid -> getProperties st >>= \attrs -> getGeometry4 st >>= \geo -> return (TeGeoObject (ObjectId obid) (map Attr attrs) geo) foreign import ccall unsafe "c_exportshapefile" exportshapefile :: TeLayerPtr -> CString -> Prelude.IO Bool foreign import ccall unsafe "c_teinstanceset_size" teinstanceset_size :: TESTIntanceSetPTR -> Prelude.IO Int32 foreign import ccall unsafe "c_teinstanceset_getteinstance" teinstanceset_getteinstance :: TESTIntanceSetPTR -> Int32 -> Prelude.IO TeSTInstancePtr foreign import ccall unsafe "c_teinstanceset_new" teinstanceset_new :: Prelude.IO TESTIntanceSetPTR foreign import ccall unsafe "c_file2instances" file2instances :: CString -> TESTIntanceSetPTR -> Prelude.IO Bool