All Downloads are FREE. Search and download functionalities are using the official Maven repository.

software.purpledragon.poi4s.kml.KmlWriter.scala Maven / Gradle / Ivy

There is a newer version: 0.0.2
Show newest version
package software.purpledragon.poi4s.kml

import java.io.OutputStream

import software.purpledragon.poi4s.model.PoiFile

import scala.xml.{Elem, PrettyPrinter}

object KmlWriter {
  private val prettyPrinter = new PrettyPrinter(80, 4)

  def write(poiFile: PoiFile, os: OutputStream): Unit = {
    val xml = generateKml(poiFile)
    os.write(prettyPrinter.format(xml).getBytes("UTF-8"))
  }

  private def generateKml(kmlFile: PoiFile): Elem = {
    
      
        {kmlFile.name.map(n => {n}).orNull}
        {kmlFile.description.map(d => {d}).orNull}
        {
          kmlFile.waypoints map { waypoint =>
            
              {waypoint.name.map(n => {n}).orNull}
              {waypoint.description.map(p => {p}).orNull}
              
                
                  {
                    waypoint.elevation match {
                      case Some(e) =>
                        s"${waypoint.lon},${waypoint.lat},$e"
                      case None =>
                        s"${waypoint.lon},${waypoint.lat}"
                    }
                  }
                
              
            
          }
        }
      
    
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy