Skip to content

Commit

Permalink
Tweaked remote file example and improved error handling on missing data.
Browse files Browse the repository at this point in the history
  • Loading branch information
metasim committed Oct 20, 2021
1 parent f29820e commit dbdcaa2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import org.apache.spark.sql.types.{DataType, StructType}
import org.apache.spark.sql.{Column, Row, TypedColumn}

class ProjectedLayerMetadataAggregate(destCRS: CRS, destDims: Dimensions[Int]) extends UserDefinedAggregateFunction {

import ProjectedLayerMetadataAggregate._

def inputSchema: StructType = InputRecord.inputRecordEncoder.schema
Expand All @@ -47,10 +48,10 @@ class ProjectedLayerMetadataAggregate(destCRS: CRS, destDims: Dimensions[Int]) e
def initialize(buffer: MutableAggregationBuffer): Unit = ()

def update(buffer: MutableAggregationBuffer, input: Row): Unit = {
if(!input.isNullAt(0)) {
if (!input.isNullAt(0)) {
val in = input.as[InputRecord]

if(buffer.isNullAt(0)) {
if (buffer.isNullAt(0)) {
in.toBufferRecord(destCRS).write(buffer)
} else {
val br = buffer.as[BufferRecord]
Expand All @@ -71,16 +72,15 @@ class ProjectedLayerMetadataAggregate(destCRS: CRS, destDims: Dimensions[Int]) e
case _ => ()
}

def evaluate(buffer: Row): Any = {
val buf = buffer.as[BufferRecord]
if (buf.isEmpty) throw new IllegalArgumentException("Can not collect metadata from empty data frame.")
def evaluate(buffer: Row): Any =
Option(buffer).map(_.as[BufferRecord]).filter(!_.isEmpty).map(buf => {
val re = RasterExtent(buf.extent, buf.cellSize)
val layout = LayoutDefinition(re, destDims.cols, destDims.rows)

val re = RasterExtent(buf.extent, buf.cellSize)
val layout = LayoutDefinition(re, destDims.cols, destDims.rows)
val kb = KeyBounds(layout.mapTransform(buf.extent))
TileLayerMetadata(buf.cellType, layout, buf.extent, destCRS, kb).toRow

val kb = KeyBounds(layout.mapTransform(buf.extent))
TileLayerMetadata(buf.cellType, layout, buf.extent, destCRS, kb).toRow
}
}).getOrElse(throw new IllegalArgumentException("Can not collect metadata from empty data frame."))
}

object ProjectedLayerMetadataAggregate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class SlippyDataSourceSpec extends TestEnvironment with TestData with BeforeAndA
}

it("should construct map on a file in the wild") {
val modisUrl = "s3://astraea-opendata/MCD43A4.006/27/05/2020161/MCD43A4.A2020161.h27v05.006.2020170060718_B01.TIF"
val modisUrl = "s3://modis-pds/MCD43A4.006/27/05/2020161/MCD43A4.A2020161.h27v05.006.2020170060718_B01.TIF"
val modisRf = spark.read.raster.from(Seq(modisUrl))
.withLazyTiles(false)
.load()
Expand Down

0 comments on commit dbdcaa2

Please sign in to comment.