Skip to content

Commit

Permalink
Optimize RasterizeRDD.fromGeometry small intersections
Browse files Browse the repository at this point in the history
Expect that for large layers a geometry will intersect small fraction of the tiles.
In such a case keeping a set of keys is more efficient than a bitmap.
For small layer it doesn't matter what choice we made.
If this ever fails the next step is a BloomFilter instead of a Set.
  • Loading branch information
echeipesh committed Aug 31, 2017
1 parent 3aed6de commit 697d090
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions spark/src/main/scala/geotrellis/spark/rasterize/RasterizeRDD.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,12 @@ object RasterizeRDD {
val layoutRasterizerOptions = Rasterizer.Options(includePartial=true, sampleType=PixelIsArea)

/** Key geometry by spatial keys of intersecting tiles */
def keyGeom(geom: Geometry): List[(SpatialKey, (Geometry, SpatialKey))] = {
val mask = ArrayTile.empty(BitCellType, layout.layoutCols, layout.layoutRows)
var buff = List.empty[(SpatialKey, (Geometry, SpatialKey))]
// Visit all layout tiles intersected by the geometry
def keyGeom(geom: Geometry): Iterator[(SpatialKey, (Geometry, SpatialKey))] = {
var keySet = Set.empty[SpatialKey]
geom.foreach(layoutRasterExtent, layoutRasterizerOptions){ (col, row) =>
if (mask.get(col, row) == 0) { // have not seen this key before
val key = SpatialKey(col, row)
buff = (key, (geom, key)) :: buff
}
mask.set(col, row, 1)
keySet = keySet + SpatialKey(col, row)
}
buff
keySet.toIterator.map { key => (key, (geom, key)) }
}

// key the geometry to intersecting tiles so it can be rasterized in the map-side combine
Expand Down

0 comments on commit 697d090

Please sign in to comment.