Skip to content

Commit d0766dd

Browse files
committed
Tweaked remote file example and improved error handling on missing data.
1 parent 0ab48d9 commit d0766dd

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

core/src/main/scala/org/locationtech/rasterframes/expressions/aggregates/ProjectedLayerMetadataAggregate.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import org.apache.spark.sql.types.{DataType, StructType}
3434
import org.apache.spark.sql.{Column, Row, TypedColumn}
3535

3636
class ProjectedLayerMetadataAggregate(destCRS: CRS, destDims: Dimensions[Int]) extends UserDefinedAggregateFunction {
37+
3738
import ProjectedLayerMetadataAggregate._
3839

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

4950
def update(buffer: MutableAggregationBuffer, input: Row): Unit = {
50-
if(!input.isNullAt(0)) {
51+
if (!input.isNullAt(0)) {
5152
val in = input.as[InputRecord]
5253

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

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

78-
val re = RasterExtent(buf.extent, buf.cellSize)
79-
val layout = LayoutDefinition(re, destDims.cols, destDims.rows)
80+
val kb = KeyBounds(layout.mapTransform(buf.extent))
81+
TileLayerMetadata(buf.cellType, layout, buf.extent, destCRS, kb).toRow
8082

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

8686
object ProjectedLayerMetadataAggregate {

datasource/src/test/scala/org/locationtech/rasterframes/datasource/slippy/SlippyDataSourceSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class SlippyDataSourceSpec extends TestEnvironment with TestData with BeforeAndA
107107
}
108108

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

0 commit comments

Comments
 (0)