module Geometry.Shapefile.MergeShpDbf ( readShpWithDbf ) where
import System.FilePath
import qualified Data.ByteString.Lazy as BL
import Geometry.Shapefile.ReadDbf
import Geometry.Shapefile.ReadShp
import Geometry.Shapefile.Types
readShpWithDbf :: String -> IO ShpData
readShpWithDbf fp = do
shpData <- readShpData <$> BL.readFile fp
let dbfPath = dropExtension fp ++ ".dbf"
dbfData <- readDbfData <$> BL.readFile dbfPath
return shpData {
dbfFieldDescs = Just $ dbfFields dbfData,
shpRecs = zipWith addRecLabel (shpRecs shpData) (dbfRecords dbfData)
}
addRecLabel :: ShpRec -> [DbfRecord] -> ShpRec
addRecLabel sr labels = sr { shpRecLabel = Just (labels) }