Skip to content

Commit

Permalink
Add GeoTiffRasterSource.resampleToRegion spec
Browse files Browse the repository at this point in the history
  • Loading branch information
pomadchin committed Jun 10, 2020
1 parent e750add commit 7d6384a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,38 +190,5 @@ class GDALRasterSourceSpec extends FunSpec with RasterMatchers with GivenWhenThe
}
}
}


ignore("resampleToRegion should behave like GeoTiffRasterSource.resampleToRegion") {
val crs = CRS.fromEpsgCode(32618)

val uri = Resource.path("vlm/lc8-utm-1.tif")

val gt = GeoTiffRasterSource(uri)
val gd = GDALRasterSource(uri)

val re = GridExtent[Long](Extent(222285.0, 4187685.0, 589815.0, 4584315.0),CellSize(657.4776386404293,658.8538205980067)).toRasterExtent()
val e = Extent(222285.0, 4187685.0, 589815.0, 4584315.0)

val resgt =
gt
.reprojectToRegion(crs, re, NearestNeighbor, AutoHigherResolution)
.read(e).get

resgt.tile.band(0) // .renderPng().write("/Users/daunnc/Downloads/test-gt1.png")

val resgd =
gd
.reprojectToRegion(crs, re, NearestNeighbor, AutoHigherResolution)
.read(e).get

println(resgt.rasterExtent)
println(resgd.rasterExtent)

resgd.tile.band(0) // .renderPng().write("/Users/daunnc/Downloads/test-gd1.png")

// there is a little mismatch since GDAL aligns pixels
assertEqual(resgt.tile, resgd.tile)
}
}
}
Binary file added raster/data/vlm/lc8-utm-1-re.tif
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@
package geotrellis.raster.geotiff

import geotrellis.raster._
import geotrellis.raster.io.geotiff.GeoTiffTestUtils
import geotrellis.raster.io.geotiff.{AutoHigherResolution, GeoTiffTestUtils}
import geotrellis.raster.io.geotiff.reader.GeoTiffReader
import geotrellis.raster.resample._
import geotrellis.raster.testkit._
import geotrellis.vector._

import org.scalatest._

class GeoTiffRasterSourceSpec extends FunSpec with RasterMatchers with GivenWhenThen with GeoTiffTestUtils {
Expand Down Expand Up @@ -83,4 +82,21 @@ class GeoTiffRasterSourceSpec extends FunSpec with RasterMatchers with GivenWhen
assertRastersEqual(actual, expected)
}
}

it("resampleToRegion should produce an expected raster") {
val uri = baseGeoTiffPath("vlm/lc8-utm-1.tif")
val urie = baseGeoTiffPath("vlm/lc8-utm-1-re.tif")

val expected = GeoTiffRasterSource(urie).read().get

val re = GridExtent[Long](Extent(222285.0, 4187685.0, 589815.0, 4584315.0), CellSize(657.4776386404293,658.8538205980067))
val e = Extent(222285.0, 4187685.0, 589815.0, 4584315.0)

val actual =
GeoTiffRasterSource(uri)
.resampleToRegion(re, NearestNeighbor, AutoHigherResolution)
.read(e).get

assertEqual(actual, expected)
}
}

0 comments on commit 7d6384a

Please sign in to comment.