locationtech / geotrellis

GeoTrellis is a geographic data processing engine for high performance applications.
http://geotrellis.io
Other
1.33k stars 360 forks source link

Bug in the LayoutTileSource by key reads #3420

Open pomadchin opened 2 years ago

pomadchin commented 2 years ago

Describe the bug

Working on the AVIRIS imagery ingest bug, we noticed that some TMS requests are failing.

The original failing function is the renderMosaicMultiband function.

The source of the error is a call of the .tileToLayout(layoutDefinition).read(SpatialKey(x, y), subsetBands) function.

Full log:

java.lang.IllegalArgumentException: requirement failed: chunk at GridBounds(254,0,256,255) exceeds tile boundary at (256, 256)
backsplash_1              |     at scala.Predef$.require(Predef.scala:281)
backsplash_1              |     at geotrellis.raster.PaddedTile.<init>(PaddedTile.scala:33)
backsplash_1              |     at geotrellis.layer.LayoutTileSource.$anonfun$read$3(LayoutTileSource.scala:102)
backsplash_1              |     at geotrellis.layer.LayoutTileSource.$anonfun$read$3$adapted(LayoutTileSource.scala:101)
backsplash_1              |     at geotrellis.raster.MultibandTile.mapBands(MultibandTile.scala:113)
backsplash_1              |     at geotrellis.layer.LayoutTileSource.$anonfun$read$2(LayoutTileSource.scala:101)
backsplash_1              |     at scala.Option.map(Option.scala:230)
backsplash_1              |     at geotrellis.layer.LayoutTileSource.$anonfun$read$1(LayoutTileSource.scala:80)
backsplash_1              |     at scala.Option.flatMap(Option.scala:271)
backsplash_1              |     at geotrellis.layer.LayoutTileSource.read(LayoutTileSource.scala:79)
backsplash_1              |     at com.rasterfoundry.backsplash.BacksplashGeotiff.$anonfun$read$5(BacksplashImage.scala:153)
backsplash_1              |     at map @ com.rasterfoundry.backsplash.BacksplashGeotiff.$anonfun$read$4(BacksplashImage.scala:154)
backsplash_1              |     at use @ doobie.util.transactor$Transactor$$anon$4.apply(transactor.scala:162)
backsplash_1              |     at map @ com.colisweb.tracing.context.OpenTracingContext$.$anonfun$apply$2(OpenTracingContext.scala:57)
backsplash_1              |     at eval @ org.http4s.server.blaze.BlazeServerBuilder.$anonfun$resource$1(BlazeServerBuilder.scala:434)
backsplash_1              |     at use @ doobie.util.transactor$Transactor$$anon$4.apply(transactor.scala:162)
backsplash_1              |     at make @ doobie.util.transactor$Transactor$fromDataSource$FromDataSourceUnapplied.$anonfun$apply$13(transactor.scala:282)
backsplash_1              |     at make @ doobie.util.transactor$Transactor$fromDataSource$FromDataSourceUnapplied.$anonfun$apply$13(transactor.scala:282)
backsplash_1              |     at use @ doobie.util.transactor$Transactor$$anon$4.apply(transactor.scala:162)
backsplash_1              |     at map @ com.rasterfoundry.backsplash.BacksplashGeotiff.$anonfun$read$3(BacksplashImage.scala:148)

The error could be the result of

  1. A bug (very much likely) in the LayoutTileSource (confirmed, see replication steps)
  2. ~Incorrect out of bounds handling by the backsplash?~

To Reproduce

    it("should tile to layout AVIRIS") {
      val tmsLevels = {
        val scheme = ZoomedLayoutScheme(WebMercator, 256)
        for (zoom <- 0 to 64) yield scheme.levelForZoom(zoom).layout
      }.toArray

      val z = 10

      val layoutDefinition = tmsLevels(z)

      // lives under the AWS GeoTrellis account
      val uri = "s3://geotrellis-test/issue-1340-rf-platform/f180627t01p00r05rdn_e_sc01_ort_img_falsecolor-cog.tiff"

      val rs = RasterSource(uri).reproject(WebMercator, method = NearestNeighbor)
      val tl = rs.tileToLayout(layoutDefinition)

      tl.keys.toList.map(tl.read)
    }

Expected behavior

No errors in the logs and the code above should not fail.

The branch: https://github.com/pomadchin/geotrellis/tree/bug/layout-tile-source Commit: https://github.com/pomadchin/geotrellis/commit/485857d6d989571fd43c8bf8abfd8d8a7790f071

cc @aaronxsu