module Data.Geo.OSM.OSM(
OSM,
osm,
readOsmFile,
readOsmFiles,
interactOSMIO,
interactsOSMIO,
interactOSMIO',
interactsOSMIO',
interactOSM,
interactsOSM,
interactOSM',
interactsOSM'
) where
import Text.XML.HXT.Arrow
import Text.XML.HXT.Extras
import Control.Monad
import Data.List
import Data.Geo.OSM.OSMChildren
import Data.Geo.OSM.Bound
import Data.Geo.OSM.Bounds
import Data.Geo.OSM.Accessor.Version
import Data.Geo.OSM.Accessor.Generator
import Data.Geo.OSM.Accessor.BoundOrs
import Data.Geo.OSM.Accessor.NodeWayRelations
data OSM = OSM String (Maybe String) (Maybe (Either Bound Bounds)) OSMChildren
deriving Eq
instance XmlPickler OSM where
xpickle = xpElem "osm" (xpWrap (\(version', generator', bound', nwr') -> osm version' generator' bound' nwr', \(OSM version' generator' bound' nwr') -> (version', generator', bound', nwr'))
(xp4Tuple (xpAttr "version" xpText)
(xpOption (xpAttr "generator" xpText))
(xpOption (xpAlt (either (const 0) (const 1)) [xpWrap (Left, \(Left b) -> b) xpickle, xpWrap (Right, \(Right b) -> b) xpickle]))
xpickle))
instance Show OSM where
show = showPickled []
instance Version OSM String where
version (OSM x _ _ _) = x
setVersion a (OSM _ b c d) = osm a b c d
instance Generator OSM where
generator (OSM _ x _ _) = x
setGenerator b (OSM a _ c d) = osm a b c d
instance BoundOrs OSM where
boundOrs (OSM _ _ x _) n b bs = case x of Nothing -> n
Just (Left b') -> b b'
Just (Right b') -> bs b'
setBoundOrs c (OSM a b _ d) = osm a b c d
instance NodeWayRelations OSM where
nwrs (OSM _ _ _ x) = let t = const []
in foldOSMChildren t t t t t id x
setNwrs d (OSM a b c _) = osm a b c (osmNodeWayRelation d)
osm :: String
-> Maybe String
-> Maybe (Either Bound Bounds)
-> OSMChildren
-> OSM
osm = OSM
readOsmFile :: FilePath -> IO [OSM]
readOsmFile = runX . xunpickleDocument (xpickle :: PU OSM) [(a_remove_whitespace, v_1)]
readOsmFiles :: [FilePath] -> IO [OSM]
readOsmFiles = fmap join . (mapM readOsmFile)
interactOSMIO' :: Attributes
-> FilePath
-> (OSM -> IO OSM)
-> Attributes
-> FilePath
-> IO ()
interactOSMIO' froma from f toa to = runX (xunpickleDocument (xpickle :: PU OSM) froma from >>> arrIO f >>> xpickleDocument (xpickle :: PU OSM) toa to) >> return ()
interactsOSMIO' :: Attributes
-> FilePath
-> [OSM -> IO OSM]
-> Attributes
-> FilePath
-> IO ()
interactsOSMIO' froma from = interactOSMIO' froma from . sumIO'
interactOSMIO :: FilePath
-> (OSM -> IO OSM)
-> FilePath
-> IO ()
interactOSMIO from f = interactOSMIO' [(a_remove_whitespace, v_1)] from f [(a_indent, v_1)]
interactsOSMIO :: FilePath
-> [OSM -> IO OSM]
-> FilePath
-> IO ()
interactsOSMIO from = interactOSMIO from . sumIO'
interactOSM' :: Attributes
-> FilePath
-> (OSM -> OSM)
-> Attributes
-> FilePath
-> IO ()
interactOSM' froma from f = interactOSMIO' froma from (return . f)
interactsOSM' :: Attributes
-> FilePath
-> [OSM -> OSM]
-> Attributes
-> FilePath
-> IO ()
interactsOSM' froma from = interactOSM' froma from . sum'
interactOSM :: FilePath
-> (OSM -> OSM)
-> FilePath
-> IO ()
interactOSM from f = interactOSMIO from (return . f)
interactsOSM :: FilePath
-> [OSM -> OSM]
-> FilePath
-> IO ()
interactsOSM from = interactOSM from . sum'
sum' :: [a -> a] -> a -> a
sum' = foldl' (.) id
sumIO' :: (Monad m) => [a -> m a] -> a -> m a
sumIO' x = foldl' (>=>) return x