Created
September 19, 2019 18:01
-
-
Save metasim/b11392edf988ed48e348f94610679345 to your computer and use it in GitHub Desktop.
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.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