Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API refactoring for Rasterizing Reproject
Create RasterRegionReproject type class
- Loading branch information
Showing
15 changed files
with
134 additions
and
263 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 0 additions & 73 deletions
73
raster/src/main/scala/geotrellis/raster/reproject/MultibandRasterizeReprojectMethods.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
raster/src/main/scala/geotrellis/raster/reproject/RasterRegionReproject.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package geotrellis.raster.reproject | ||
|
||
import geotrellis.raster._ | ||
import geotrellis.raster.resample._ | ||
import geotrellis.raster.rasterize._ | ||
import geotrellis.vector.Polygon | ||
import geotrellis.proj4._ | ||
|
||
import spire.syntax.cfor._ | ||
|
||
trait RasterRegionReproject[T <: CellGrid]{ | ||
/** Reproject raster to a region that may partially intersect target raster extent. | ||
* | ||
* Back-projects only the cells overlapping the destination region before sampling their value from the source raster. | ||
* This can be used to avoid assigning destination cell values where there is insufficient data for resample kernel. | ||
* | ||
* @param src source raster CRS | ||
* @param dest target raster CRS | ||
* @param rasterExtent extent and resolution of target raster | ||
* @param region polygon boundry of source raster in target CRS | ||
* @param resampleMethod cell value resample method | ||
*/ | ||
def regionReproject(raster: Raster[T], src: CRS, dest: CRS, rasterExtent: RasterExtent, region: Polygon, resampleMethod: ResampleMethod): Raster[T] | ||
} | ||
|
||
object RasterRegionReproject { | ||
implicit val singlebandInstance = new RasterRegionReproject[Tile] { | ||
def regionReproject(raster: Raster[Tile], src: CRS, dest: CRS, rasterExtent: RasterExtent, region: Polygon, resampleMethod: ResampleMethod): Raster[Tile] = { | ||
val buffer = raster.tile.prototype(rasterExtent.cols, rasterExtent.rows) | ||
val trans = Proj4Transform(dest, src) | ||
val resampler = Resample.apply(resampleMethod, raster.tile, raster.extent, CellSize(raster.rasterExtent.cellwidth, raster.rasterExtent.cellheight)) | ||
|
||
if (raster.cellType.isFloatingPoint) { | ||
Rasterizer.foreachCellByPolygon(region, rasterExtent) { (px, py) => | ||
val (x, y) = rasterExtent.gridToMap(px, py) | ||
val (tx, ty) = trans(x, y) | ||
buffer.setDouble(px, py, resampler.resampleDouble(tx, ty)) | ||
} | ||
} else { | ||
Rasterizer.foreachCellByPolygon(region, rasterExtent) { (px, py) => | ||
val (x, y) = rasterExtent.gridToMap(px, py) | ||
val (tx, ty) = trans(x, y) | ||
buffer.set(px, py, resampler.resample(tx, ty)) | ||
} | ||
} | ||
|
||
Raster(buffer, rasterExtent.extent) | ||
} | ||
} | ||
|
||
implicit val multibandInstance = new RasterRegionReproject[MultibandTile] { | ||
def regionReproject(raster: Raster[MultibandTile], src: CRS, dest: CRS, rasterExtent: RasterExtent, region: Polygon, resampleMethod: ResampleMethod): Raster[MultibandTile] = { | ||
val trans = Proj4Transform(dest, src) | ||
val bands = Array.ofDim[MutableArrayTile](raster.tile.bandCount) | ||
|
||
cfor(0)(_ < bands.length, _ + 1) { i => | ||
bands(i) = raster.band(i).prototype(rasterExtent.cols, rasterExtent.rows).mutable | ||
} | ||
|
||
val resampler = (0 until raster.bandCount).map { i => | ||
Resample(resampleMethod, raster.band(i), raster.extent, raster.rasterExtent.cellSize) | ||
} | ||
|
||
if (raster.cellType.isFloatingPoint) { | ||
Rasterizer.foreachCellByPolygon(region, rasterExtent) { (px, py) => | ||
val (x, y) = rasterExtent.gridToMap(px, py) | ||
val (tx, ty) = trans(x, y) | ||
cfor(0)(_ < bands.length, _ + 1) { i => | ||
bands(i).setDouble(px, py, resampler(i).resampleDouble(tx, ty)) | ||
} | ||
} | ||
} else { | ||
Rasterizer.foreachCellByPolygon(region, rasterExtent) { (px, py) => | ||
val (x, y) = rasterExtent.gridToMap(px, py) | ||
val (tx, ty) = trans(x, y) | ||
cfor(0)(_ < bands.length, _ + 1) { i => | ||
bands(i).set(px, py, resampler(i).resample(tx, ty)) | ||
} | ||
} | ||
} | ||
|
||
Raster(MultibandTile(bands), rasterExtent.extent) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 0 additions & 51 deletions
51
raster/src/main/scala/geotrellis/raster/reproject/RasterizeReprojectMethods.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.