I have a directory full of single spectral band tiff files. 3 of the tiff files correspond to one location in the united states (Iowa) and 3 other tiff files correspond to a totally separate area in the united states (florida). I have a small scala app that takes the tiff files related to iowa and produces a multi spectral band tiff file. It then takes the tiff files related to florida and produces another multi spectral band tiff tile. The code looks like this
package tutorial
import
geotrellis.proj4.WebMercator
import
geotrellis.raster._
import
geotrellis.raster.io.geotiff._
object
MaskBandsRandGandNIR
{
val directories = List("Iowa", "Florida")
//constants to differentiate which bands to use
val R_BAND = 0
val G_BAND = 1
val NIR_BAND = 2
// Path to our landsat band geotiffs.
def bandPath(directory: String) = s"data/landsat/${directory}"
def main(args: Array[String]): Unit = {
directories.map(directory => generateMultibandGeoTiffFile(directory))
}
def generateMultibandGeoTiffFile(directory: String) = {
val tiffFiles = new java.io.File(bandPath(directory)).listFiles.map(_.toString)
val singleBandGeoTiffArray = tiffFiles.foldLeft(Array[SinglebandGeoTiff]())((acc, el:String) => {
acc :+ SinglebandGeoTiff(el)
})
val tileArray = ArrayMultibandTile(singleBandGeoTiffArray.map(_.tile))
println(s"Writing out $directory multispectral
tif")
MultibandGeoTiff(tileArray, singleBandGeoTiffArray(0).extent, singleBandGeoTiffArray(0).crs).write(s"data/$directory.tif")
}
}
Now what I need to do is take those multi spectral tiff files that were generated and combine them somehow.
// Read the geotiff in as a single image RDD,
// using a method implicitly added to SparkContext by
// an implicit class available via the
// "import geotrellis.spark.io.hadoop._ " statement.
val floridaRdd: RDD[(ProjectedExtent, MultibandTile)] = sc.hadoopMultibandGeoTiffRDD(floridaPath)
val iowaRdd: RDD[(ProjectedExtent, MultibandTile)] = sc.hadoopMultibandGeoTiffRDD(iowaPath)
val inputRdd = floridaRdd ++ iowaRdd
// Use the "TileLayerMetadata.fromRdd" call to find the zoom
// level that the closest match to the resolution of our source image,
// and derive information such as the full bounding box and data type.
val (_, rasterMetaData) =
TileLayerMetadata.fromRdd(inputRdd, FloatingLayoutScheme(512))
//inputRdd.collectMetadata(FloatingLayoutScheme(512))
// Use the Tiler to cut our tiles into tiles that are index to a floating layout scheme.
// We'll repartition it so that there are more partitions to work with, since spark
// likes to work with more, smaller partitions (to a point) over few and large partitions.
val tiled: RDD[(SpatialKey, MultibandTile)] =
inputRdd
.tileToLayout(rasterMetaData.cellType, rasterMetaData.layout, Bilinear)
.repartition(100)
// We'll be tiling the images using a zoomed layout scheme
// in the web mercator format (which fits the slippy map tile specification).
// We'll be creating 256 x 256 tiles.
val layoutScheme = ZoomedLayoutScheme(WebMercator, tileSize = 256)
// We need to reproject the tiles to WebMercator
val (zoom, reprojected): (Int, RDD[(SpatialKey, MultibandTile)] with Metadata[TileLayerMetadata[SpatialKey]]) =
MultibandTileLayerRDD(tiled, rasterMetaData)
.reproject(WebMercator, layoutScheme, Bilinear)
// Create the attributes store that will tell us information about our catalog.
val attributeStore = FileAttributeStore(outputPath)
// Create the writer that we will use to store the tiles in the local catalog.
val writer = FileLayerWriter(attributeStore)
// Pyramiding up the zoom levels, write our tiles out to the local file system.
Pyramid.upLevels(reprojected, layoutScheme, zoom, Bilinear) { (rdd, z) =>
val layerId = LayerId("landsat", z)
// If the layer exists already, delete it out before writing
if(attributeStore.layerExists(layerId)) {
new FileLayerManager(attributeStore).delete(layerId)
}
writer.write(layerId, rdd, ZCurveKeyIndexMethod)
}
In the code above I combine the iowaRdd and the floridaRdd by using the ‘++’ operator. Now the compiler is complaining that it has more than one CRS. I’m very new to geo-spatial analysis of any sort. Am I even on the right path of doing this?
--
You received this message because you are subscribed to the Google Groups "geotrellis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geotrellis-us...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to geotrellis-user+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "geotrellis-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/geotrellis-user/9im26tWBDCo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to geotrellis-user+unsubscribe@googlegroups.com.