<commit_before>package geotrellis.osme.server

import akka.actor._
import geotrellis.vector.Line
import geotrellis.vector.io.json.{GeoJson => GJson}
import geotrellis.vector.io.json.JsonFeatureCollection
import geotrellis.vector.io.json.FeatureFormats.writeFeatureJson
import geotrellis.vector.LineFeature
import geotrellis.vector.Feature
import geotrellis.vector.io.json.GeometryFormats.MultiLineFormat
import org.apache.spark._
import spray.http.HttpHeaders.RawHeader
import spray.routing._
import spray.json.JsString


class OsmeServiceActor(
  sc: SparkContext
) extends Actor with OsmeService{

  def actorRefFactory = context
  def receive = runRoute(root)

}


trait ElevationUtility {
 def applyElevation(line:Line) = {
   val stubElevation: Array[Double]= new Map('elevation': new Array[Double](line.vertices.length).map(x => 5.0))
   writeFeatureJson(LineFeature(line, stubElevation))
 }

}

// trait partitioned off to enable better testing
trait OsmeService extends HttpService with ElevationUtility {

  def cors: Directive0 = respondWithHeader(RawHeader("Access-Control-Allow-Origin", "*"))


  def root =
    path("getVectorData") {
      post {
        entity(as[String]) { geoJson =>
          val GJsonCollection:JsonFeatureCollection = GJson.parse[JsonFeatureCollection](geoJson)
          val lines: Vector[Line] = GJsonCollection.getAllLines()
          val linesWithElevation= lines.map(line => applyElevation(line))
          println(lines.toString())
          complete {
            linesWithElevation.toJson
          }
        }
      }
    }
}<commit_msg>mock out polygon -> line feature service<commit_after>package geotrellis.osme.server

import akka.actor._
import geotrellis.vector._
import geotrellis.vector.io._
import geotrellis.vector.io.json._
import org.apache.spark._
import spray.http.HttpHeaders.RawHeader
import spray.routing._
import spray.json._
import spray.httpx.SprayJsonSupport._

class OsmeServiceActor(
  sc: SparkContext
) extends Actor with OsmeService{
  def actorRefFactory = context
  def receive = runRoute(root)
}

// trait partitioned off to enable better testing
trait OsmeService extends HttpService {
  import Formats._

  def cors: Directive0 = respondWithHeader(RawHeader("Access-Control-Allow-Origin", "*"))

  def root =
    path("getVectorData") {
      post {
        entity(as[Polygon]) { queryPolygon =>
          complete {
            // we can for and return Features and geometries because we import spray.httpx.SprayJsonSupport._
            // and import JsonFormat[_] for the required types from geotrellis.vector.io._
            OsmeService.riverFeatures.filter{ feature =>
              feature.geom.intersects(queryPolygon)
            }
          }
        }
      }
    }
}

object OsmeService {
  import Formats._

  lazy val riverFeatures: Vector[LineFeature[Stats]] =
    Resource.string("/rivers-west.json")
      .parseJson
      .convertTo[JsonFeatureCollection]
      .getAllLineFeatures[Stats]
}
{'fraction_non_alphanumeric': 0.09346733668341708, 'fraction_numerical': 0.001340033500837521, 'mean_word_length': 3.565749235474006, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1088860', 'n_tokens_mistral': 897, 'n_tokens_neox': 869, 'n_words': 191}