Search code examples
scalaapache-sparkgeotrellis

Scala, Spark, Geotrellis Rdd CRS reprojection


I load a set of point from a CSV file to a RDD:

case class yieldrow(Elevation:Double,DryYield:Double)

val points :RDD[PointFeature[yieldrow]] = lines.map { line =>
  val fields = line.split(",")
  val point = Point(fields(1).toDouble,fields(0).toDouble)
  Feature(point, yieldrow(fields(4).toDouble,fields(20)))
}

Then get:

points: org.apache.spark.rdd.RDD[geotrellis.vector.PointFeature[yieldrow]] 

Now need to reproject from EPSG:4326 to EPSG:3270

So I create the CRS from and to:

val crsFrom : geotrellis.proj4.CRS =  geotrellis.proj4.CRS.fromName("EPSG:4326")
val crsTo : geotrellis.proj4.CRS =  geotrellis.proj4.CRS.fromEpsgCode(32720)

But I can not create the transform and also i don not know:

Hot to apply a transform to a single point:

val pt = Point( -64.9772376007928, -33.6408083223936)

How to use the mapGeom method of Feature to make a CRS transformation ?

points.map(_.mapGeom(?????))
points.map(feature => feature.mapGeom(????))

How to use ReprojectPointFeature(pointfeature) ?

The documentation not have basic code samples.

Any help will be appreciate


Solution

  • I'll start from the last question:

    Indeed to perform a reproject on a PointFeature you can use ReprojectPointFeature implict case class. To use it just be sure that you have import geotrellis.vector._ in reproject function call scope.

    import geotrellis.vector._
    points.map(_.reproject(crsFrom, crsTo))
    

    The same import works for a Point too:

    import geotrellis.vector._
    pt.reproject(crsFrom, crsTo)
    points.map(_.mapGeom(_.reproject(crsFrom, crsTo)))