Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buffer for resample by only half a pixel #3302

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ metastore_db/

spark/src/test/resources/vlm/*catalog*


# vscode
.vscode
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
- Fix `Encoder[GeometryCollection]` including subclasses of GeometryCollection twice in the json
(MultiPolygon, Multipoint,MultiLinestring) [#3167](https://github.com/locationtech/geotrellis/issues/3167)
-Fix `LayoutTileSource` buffer should only be 1/2 a cellsize to avoid going out of bounds and creating `NODATA` values [#3302](https://github.com/locationtech/geotrellis/pull/3302)
- Remove unused allocation from CroppedTile [#3297](https://github.com/locationtech/geotrellis/pull/3297)

## [3.5.0] - 2020-08-18
Expand Down
Binary file added layer/src/test/resources/vlm/nodata-row.tif
Binary file not shown.
32 changes: 32 additions & 0 deletions layer/src/test/scala/geotrellis/layer/LayoutTileSourceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -244,5 +244,37 @@ class LayoutTileSourceSpec extends AnyFunSpec with RasterMatchers {
t.dimensions shouldBe Dimensions(256, 256)
}
}

it("should read reprojected and tiled to layout source without nodata stripe // see issue-3299") {
val path = Resource.path("vlm/nodata-row.tif")
val testZoomLevel = 19
val rs = GeoTiffRasterSource(path)

val scheme = ZoomedLayoutScheme(WebMercator)
val layout = scheme.levelForZoom(testZoomLevel).layout

val extent: Extent = rs.extent.reproject(rs.crs, WebMercator)
val SpatialKey(x, y) = layout.mapTransform(extent.center)

val neighborhood = for {
col <- ((x - 2) until (x + 2)).toList
row <- ((y - 2) until (y + 2)).toList
} yield (col, row)

def checkExtent(col: Int, row: Int, rs: RasterSource): Unit = {
val tile = rs
.tileToLayout(layout)
.read(SpatialKey(col, row), List(0))
.get
.band(0)
val arr = tile.toArray
val ones = tile.mapIfSet(i => 1).toArray()
ones.sum shouldBe(arr.size)
}

neighborhood map {
case (x, y) => checkExtent(x, y, rs)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ class GeoTiffResampleRasterSource(
targetPixelBounds <- queryPixelBounds.intersection(this.dimensions)
} yield {
val targetExtent = gridExtent.extentFor(targetPixelBounds)
// buffer the targetExtent to read a buffered area from the source tiff
// Buffer the targetExtent to read a buffered area from the source tiff
// so the resample would behave properly on borders
val bufferedTargetExtent = targetExtent.buffer(cellSize.width, cellSize.height)
// Buffer by half of CS to avoid resampling out of bounds
val bufferedTargetExtent = targetExtent.buffer(cellSize.width / 2, cellSize.height / 2)
val sourcePixelBounds = closestTiffOverview.rasterExtent.gridBoundsFor(bufferedTargetExtent)
val targetRasterExtent = RasterExtent(targetExtent, targetPixelBounds.width.toInt, targetPixelBounds.height.toInt)
(sourcePixelBounds, targetRasterExtent)
Expand Down