Skip to content

Instantly share code, notes, and snippets.

@metasim
Created September 19, 2019 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metasim/b11392edf988ed48e348f94610679345 to your computer and use it in GitHub Desktop.
Save metasim/b11392edf988ed48e348f94610679345 to your computer and use it in GitHub Desktop.
import geotrellis.raster.io.geotiff.SinglebandGeoTiff
import org.apache.spark.SparkFiles
import org.apache.spark.sql.SparkSession
import org.locationtech.rasterframes._
import org.locationtech.rasterframes.datasource.geotiff._
object LayerToGeoTiff {
def main(args: Array[String]): Unit = {
implicit val spark = new SparkSession.Builder()
.master("local[*]")
.withKryoSerialization
.getOrCreate()
.withRasterFrames
val imageName = "LC08_B7_Memphis_COG.tiff"
spark.sparkContext.addFile("https://raw.githubusercontent.com/locationtech/rasterframes/develop/core/src/test/resources/" + imageName)
val tiff = SinglebandGeoTiff(SparkFiles.get(imageName))
val layer = tiff.projectedRaster.toLayer(64, 64)
// Could write the layer out if we wanted to
// import org.locationtech.rasterframes.datasource.geotrellis._
//val layerDest = Files.createTempFile("gt-", "-layer")
//layer.write.geotrellis.asLayer(Layer(layerDest.toUri, "test", 0))
layer.write.geotiff.save("former-layer.tif")
spark.stop()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment