Advertisement
Guest User

Untitled

a guest
Jul 29th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.78 KB | None | 0 0
  1.  
  2.   implicit class RichString(val s: String) extends AnyVal {
  3.  
  4.     def parseGeoJson[T: JsonReader] = s.parseJson.convertTo[T]
  5.  
  6.     def extractFeatures[T: JsonReader] = s.parseJson.convertTo[T]
  7.  
  8.     def extractGeometries[G <: Geometry] = {
  9.       val geoms = s.parseJson.convertTo[G]
  10.       geoms match {
  11.         case _:Geometry => geoms
  12.         case _ => Seq[G]()
  13.       }
  14.     }
  15.   }
  16.  
  17.   /*
  18.   val json: String = ???
  19.  
  20.   val p = json.extractGeometries[G <: Geometry]: Seq[G] // May be empty
  21.   val p = json.extractFeatures[G <: Geometry, D]: Seq[Feature[G, D]]
  22.   val p = json.parseGeoJson[PolygonFeature[Int]]: PolygonFeature[Int] // This expects all the types to line up, throws if not.
  23.   val p = json.parseGeojson[JsonFeatureCollection].getAllPolygonFeature[D]().head
  24.  
  25.   p
  26.    */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement