module GIS.Exe.OptCairo
(
Program (..)
, exec
) where
import Control.Lens
import Data.Semigroup
import GIS.Exe.Parser hiding (projection)
import GIS.Graphics.PlotPNG
import GIS.Graphics.Types hiding (projection)
import GIS.Hylo
import Options.Applicative
import System.Directory
exec :: IO ()
exec = pick =<< execParser helpDisplay
pick :: Program -> IO ()
pick (Program (MapMaker outfile False projection) infile) = let p = pickProjection projection in
mkMap outfile =<< districtToMapP p <$> getDistricts infile
pick (Program (MapMaker _ True projection) infile) = let p = pickProjection projection in
makeFoldersPng =<< districtToMapFilesP p <$> getDistricts infile
pick (Program (Computation comp Nothing) infile) =
case comp of
"perimeter" -> putStrLn =<< districtPerimeter <$> getDistricts infile
"area" -> putStrLn =<< districtArea <$> getDistricts infile
"compactness" -> putStrLn =<< districtCompactness <$> getDistricts infile
_ -> putStrLn "computation not recognized"
pick (Program (MapLabel outfile False _ lensName) infile) =
mkLensMap "" outfile (pickLens lensName) =<< getDistricts infile
pick _ = error "not yet supported."
makeFoldersPng :: [Map] -> IO ()
makeFoldersPng maps = do
createDirectoryIfMissing False "maps"
mapM_ (\m -> mkMapPng ("maps/" <> view title m <> ".png") m) maps