module Data.Geo.OSM.OSM(
OSM,
osm,
readOsmFile,
readOsmFiles,
interactOSMIO,
interactsOSMIO,
interactOSMIO',
interactsOSMIO',
interactOSM,
interactsOSM,
interactOSM',
interactsOSM'
) where
import Prelude hiding (mapM, foldr)
import Text.XML.HXT.Core
import Text.XML.HXT.Extras
import Control.Monad hiding (mapM)
import Data.Foldable
import Data.Traversable
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
import Data.Monoid
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) ([withRemoveWS yes, withFileMimeType v_1])
readOsmFiles ::
[FilePath]
-> IO [OSM]
readOsmFiles =
fmap join . mapM readOsmFile
interactOSMIO' ::
(OSM -> IO OSM)
-> SysConfigList
-> FilePath
-> SysConfigList
-> FilePath
-> IO ()
interactOSMIO' f froma from toa to =
runX (xunpickleDocument (xpickle :: PU OSM) froma from >>> arrIO f >>> xpickleDocument (xpickle :: PU OSM) toa to) >> return ()
interactsOSMIO' ::
Foldable t =>
t (OSM -> IO OSM)
-> SysConfigList
-> FilePath
-> SysConfigList
-> FilePath
-> IO ()
interactsOSMIO' =
interactOSMIO' . sumM
interactOSMIO ::
(OSM -> IO OSM)
-> FilePath
-> FilePath
-> IO ()
interactOSMIO f from =
interactOSMIO' f [withRemoveWS yes, withFileMimeType v_1] from [withIndent yes, withFileMimeType v_1]
interactsOSMIO ::
Foldable t =>
t (OSM -> IO OSM)
-> FilePath
-> FilePath
-> IO ()
interactsOSMIO =
interactOSMIO . sumM
interactOSM' ::
(OSM -> OSM)
-> SysConfigList
-> FilePath
-> SysConfigList
-> FilePath
-> IO ()
interactOSM' f =
interactOSMIO' (return . f)
interactsOSM' ::
Foldable t =>
t (OSM -> OSM)
-> SysConfigList
-> FilePath
-> SysConfigList
-> FilePath
-> IO ()
interactsOSM' =
interactOSM' . sum'
interactOSM ::
(OSM -> OSM)
-> FilePath
-> FilePath
-> IO ()
interactOSM f =
interactOSMIO (return . f)
interactsOSM ::
Foldable t =>
t (OSM -> OSM)
-> FilePath
-> FilePath
-> IO ()
interactsOSM =
interactOSM . sum'
sum' ::
Foldable t =>
t (a -> a)
-> a
-> a
sum' =
appEndo . foldMap Endo
sumM ::
(Monad m, Foldable t) =>
t (a -> m a)
-> a
-> m a
sumM =
foldr (>=>) return