Skip to content
Permalink
Browse files

SpatialKey.tileExtent -> SpatialKey.extent

- And the underlying methods in `MapKeyTransform` have been renamed
  `keyToExtent` to match the naming scheme of the other methods there.
  • Loading branch information
fosskers authored and echeipesh committed Oct 6, 2017
1 parent 1231603 commit f5221e4979d4f54d9323f27a83c05c68afa29157
@@ -28,7 +28,7 @@ abstract class CellGridLayoutCollectionMethods[K: SpatialComponent, V <: CellGri
val layout = self.metadata.getComponent[LayoutDefinition]

self.map { case (key, tile) =>
(key, Raster(tile, key.getComponent[SpatialKey].tileExtent(layout)))
(key, Raster(tile, key.getComponent[SpatialKey].extent(layout)))
}
}
}
@@ -31,7 +31,7 @@ abstract class CellGridLayoutRDDMethods[K: SpatialComponent: ClassTag, V <: Cell

self.mapPartitions({ part =>
part.map { case (key, tile) =>
(key, Raster(tile, key.getComponent[SpatialKey].tileExtent(layout)))
(key, Raster(tile, key.getComponent[SpatialKey].extent(layout)))
}
}, true)
}
@@ -26,7 +26,7 @@ case class SpatialKey(col: Int, row: Int) extends Product2[Int, Int] {
def _2 = row

/** Retrieve the [[Extent]] that corresponds to this key, given a layout. */
def tileExtent(layout: LayoutDefinition): Extent = layout.mapTransform(this)
def extent(layout: LayoutDefinition): Extent = layout.mapTransform.keyToExtent(this)
}

object SpatialKey {
@@ -42,7 +42,7 @@ object Crop {
rdd
.mapPartitions({ partition =>
partition.flatMap({ case (key, tile) =>
val srcExtent: Extent = mapTransform.tileExtent(key.getComponent[SpatialKey])
val srcExtent: Extent = mapTransform.keyToExtent(key.getComponent[SpatialKey])

if (extent.contains(srcExtent)) {
Some((key, tile))
@@ -135,7 +135,7 @@ object Intersects {
def apply(metadata: M, kb: KeyBounds[K], polygon: MultiPolygon) = {
val mapTransform = metadata.getComponent[LayoutDefinition].mapTransform
val extent: Extent = polygon.envelope
val keyext: Extent = mapTransform.tileExtent(kb.minKey.getComponent[SpatialKey])
val keyext: Extent = mapTransform.keyToExtent(kb.minKey.getComponent[SpatialKey])
val bounds: GridBounds = mapTransform.extentToBounds(extent)
val options = Options(includePartial=true, sampleType=PixelIsArea)

@@ -216,7 +216,7 @@ object Intersects {
def apply(metadata: M, kb: KeyBounds[K], multiLine: MultiLine) = {
val mapTransform = metadata.getComponent[LayoutDefinition].mapTransform
val extent: Extent = multiLine.envelope
val keyext: Extent = mapTransform.tileExtent(kb.minKey.getComponent[SpatialKey])
val keyext: Extent = mapTransform.keyToExtent(kb.minKey.getComponent[SpatialKey])
val bounds: GridBounds = mapTransform(extent)
val options = Options(includePartial=true, sampleType=PixelIsArea)

@@ -41,14 +41,14 @@ object RDDLayoutMerge {
val cutRdd =
right
.flatMap { case (k: K, tile: V) =>
val extent: Extent = k.getComponent[SpatialKey].tileExtent(thatLayout)
val extent: Extent = k.getComponent[SpatialKey].extent(thatLayout)

thisLayout.mapTransform(extent)
.coordsIter
.map { case (col, row) =>
val outKey = k.setComponent(SpatialKey(col, row))
val newTile = tile.prototype(thisLayout.tileCols, thisLayout.tileRows)
val merged = newTile.merge(outKey.getComponent[SpatialKey].tileExtent(thisLayout), extent, tile)
val merged = newTile.merge(outKey.getComponent[SpatialKey].extent(thisLayout), extent, tile)
(outKey, merged)
}
}
@@ -96,19 +96,19 @@ object Pyramid extends LazyLogging {
val nextRdd = {
val transformedRdd = rdd
.map { case (key, tile) =>
val extent: Extent = key.getComponent[SpatialKey].tileExtent(sourceLayout)
val extent: Extent = key.getComponent[SpatialKey].extent(sourceLayout)
val newSpatialKey = nextLayout.mapTransform(extent.center)
(key.setComponent(newSpatialKey), (key, tile))
}

partitioner
.fold(transformedRdd.combineByKey(createTiles, mergeTiles1, mergeTiles2))(transformedRdd.combineByKey(createTiles _, mergeTiles1 _, mergeTiles2 _, _))
.mapPartitions ( partition => partition.map { case (newKey: K, seq: Seq[(K, V)]) =>
val newExtent = newKey.getComponent[SpatialKey].tileExtent(nextLayout)
val newExtent = newKey.getComponent[SpatialKey].extent(nextLayout)
val newTile = seq.head._2.prototype(nextLayout.tileLayout.tileCols, nextLayout.tileLayout.tileRows)

for ((oldKey, tile) <- seq) {
val oldExtent = oldKey.getComponent[SpatialKey].tileExtent(sourceLayout)
val oldExtent = oldKey.getComponent[SpatialKey].extent(sourceLayout)
newTile.merge(newExtent, oldExtent, tile, resampleMethod)
}
(newKey, newTile: V)
@@ -87,7 +87,7 @@ object TileRDDReproject {
val inverseTransform = Transform(destCrs, crs)

partition.map { case (key, BufferedTile(tile, gridBounds)) =>
val innerExtent = key.getComponent[SpatialKey].tileExtent(layout)
val innerExtent = key.getComponent[SpatialKey].extent(layout)
val innerRasterExtent = RasterExtent(innerExtent, gridBounds.width, gridBounds.height)
val outerGridBounds =
GridBounds(
@@ -208,7 +208,7 @@ object TileRDDReproject {
val transform = Transform(crs, destCrs)

partition.map { case (key, _) =>
val extent = key.getComponent[SpatialKey].tileExtent(layout)
val extent = key.getComponent[SpatialKey].extent(layout)
val rasterExtent = RasterExtent(extent, tileLayout.tileCols, tileLayout.tileRows)
(key, (rasterExtent, ReprojectRasterExtent(rasterExtent, transform)))
}
@@ -90,8 +90,8 @@ object ZoomResample {
gbaz.map { gb =>
gb.coordsIter
.map { case (col, row) =>
val sourceExtent = sourceMapTransform.tileExtent(key.getComponent[SpatialKey])
val targetExtent = targetMapTransform.tileExtent(col, row)
val sourceExtent = sourceMapTransform.keyToExtent(key.getComponent[SpatialKey])
val targetExtent = targetMapTransform.keyToExtent(col, row)
val resampled = tile.resample(
sourceExtent,
RasterExtent(targetExtent, tileSize, tileSize),
@@ -130,8 +130,8 @@ object ZoomResample {
gridBoundsAtZoom(sourceZoom, key.getComponent[SpatialKey], targetZoom)
.coordsIter
.map { case (col, row) =>
val sourceExtent = sourceMapTransform.tileExtent(key.getComponent[SpatialKey])
val targetExtent = targetMapTransform.tileExtent(col, row)
val sourceExtent = sourceMapTransform.keyToExtent(key.getComponent[SpatialKey])
val targetExtent = targetMapTransform.keyToExtent(col, row)
val resampled =
tile.resample(sourceExtent, RasterExtent(targetExtent, tileSize, tileSize), method)
(key.setComponent(SpatialKey(col, row)), resampled)
@@ -56,7 +56,7 @@ object CutTiles {
logger.debug(s"Merge $inKey into $outKey of (${tileCols}, ${tileRows}) cells")
val newTile = tile.prototype(cellType, tileCols, tileRows)
(outKey, newTile.merge(
mapTransform.tileExtent(outKey.getComponent[SpatialKey]),
mapTransform.keyToExtent(outKey.getComponent[SpatialKey]),
extent,
tile,
resampleMethod
@@ -108,12 +108,12 @@ class MapKeyTransform(val extent: Extent, val layoutCols: Int, val layoutRows: I
def apply[K: SpatialComponent](key: K): Extent = apply(key.getComponent[SpatialKey])

/** Get the [[Extent]] corresponding to a [[SpatialKey]] in some zoom level. */
def tileExtent(key: SpatialKey): Extent = apply(key)
def keyToExtent(key: SpatialKey): Extent = apply(key)

def apply(key: SpatialKey): Extent = apply(key.col, key.row)

/** 'col' and 'row' correspond to a [[SpatialKey]] column and row in some grid. */
def tileExtent(col: Int, row: Int): Extent = apply(col, row)
def keyToExtent(col: Int, row: Int): Extent = apply(col, row)

def apply(col: Int, row: Int): Extent =
Extent(

0 comments on commit f5221e4

Please sign in to comment.
You can’t perform that action at this time.