geotrellis icon indicating copy to clipboard operation
geotrellis copied to clipboard

Should Mask a Layer With an RDD[Geometry]

Open jbouffard opened this issue 6 years ago • 0 comments

Having geometries in an RDD is becoming more common due to our work on OSMesa. However, we have little support with working with that format in GeoTrellis. One area in particular is masking a layer with an RDD[Geometry]. This should be fairly straightforward to implement, and it could look something like this:


val geomRDD: RDD[Geometry] = ???

val options: Rasterizer.Options = ???

val partitioner: SpacePartitioner = ???

val mapTransform: MapKeyTransform = ???
val layout: Layout = ???

val clippedGeoms: RDD[(SpatialKey, Geometry)] = geomRDD.clipToGrid(layout)

val groupedClippedGeoms: RDD[(SpatialKey, Iterable[Geometry])] = clippedGeoms.groupByKey(partitioner)

val joinedRDD: RDD[(SpatialKey, (Tile, Iterable[Geometry]))] =
  tiledLayer.join(groupedClippedGeoms, partitioner)

val maskedRDD: RDD[(SpatialKey, Tile)] =
  joinedRDD.mapPartitions({ partition =>
    partition.map { case (k, (v, geoms)) =>
      (k, v.mask(mapTransform(k), geoms, options))
    }
  }, preservesPartitioning = true)

jbouffard avatar Dec 12 '18 18:12 jbouffard