Created
July 14, 2015 18:30
-
-
Save lossyrob/45c6352ce2ed28dda7c9 to your computer and use it in GitHub Desktop.
Create a GeoTiff from an RDD of [(K, Iterator[(x, y, z)])]
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
import geotrellis.proj4._ | |
import geotrellis.vector._ | |
import geotrellis.raster._ | |
import geotrellis.raster.io.geotiff._ | |
import org.apache.spark.rdd._ | |
trait Example { | |
// Some information you'll need to supply... | |
val crs = CRS.fromName("EPSG") | |
// Depends on your key type | |
type KeyType | |
// The dimensions of each GeoTiff. You could derive this from each of | |
// the groupings if need be. | |
val (cols, rows): (Int, Int) = ??? | |
// We need to get the bounding box for the GeoTiff. I'm assuming this changes | |
// per key, but perhaps it's only one extent for each key? If so this can be a | |
// val instead of a def. | |
def extentFromKey(k: KeyType): Extent = ??? | |
def filePathFromKey(k: KeyType): String = ??? | |
val rdd: RDD[(KeyType, Iterator[(Int, Int, Double)])] = ??? | |
rdd | |
.foreach { case (key, iterator) => | |
val tile = DoubleArrayTile.empty(cols, rows) | |
for((col, row, value) <- iterator) { | |
tile.setDouble(col, row, value) | |
} | |
val extent = extentFromKey(key) | |
val filePath = filePathFromKey(key) | |
SingleBandGeoTiff(tile, extent, crs).write(filePath) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment