diff --git a/CHANGELOG.md b/CHANGELOG.md index f5d7b37a7b..ac0737b474 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix implicitNotFound error and rename RGBAMethods implicit class [#3563](https://github.com/locationtech/geotrellis/pull/3563) - Set 'role' attribute in GDALMetadata tag written to tiff header, to match GDAL behaviour. [#3496](https://github.com/locationtech/geotrellis/issues/3496) - Avoid GeoAttrsError by using more robust target extent calculation [#3572](https://github.com/locationtech/geotrellis/pull/3572) +- ReprojectRasterExtent: support single pixel input [#3573](https://github.com/locationtech/geotrellis/pull/3573) ## [3.7.1] - 2024-01-08 diff --git a/raster/src/main/scala/geotrellis/raster/reproject/ReprojectRasterExtent.scala b/raster/src/main/scala/geotrellis/raster/reproject/ReprojectRasterExtent.scala index 5188d19322..9aa127a643 100644 --- a/raster/src/main/scala/geotrellis/raster/reproject/ReprojectRasterExtent.scala +++ b/raster/src/main/scala/geotrellis/raster/reproject/ReprojectRasterExtent.scala @@ -57,7 +57,9 @@ object ReprojectRasterExtent { val cols = ge.extent.width / ge.cellwidth val rows = ge.extent.height / ge.cellheight val pixelSize = distance / math.sqrt(cols * cols + rows * rows) - (pixelSize, pixelSize) + val pixelWidth = if(newExtent.width < 0.5 * pixelSize) newExtent.width else pixelSize + val pixelHeight = if(newExtent.height < 0.5*pixelSize) newExtent.height else pixelSize + (pixelWidth, pixelHeight) } val newCols = (newExtent.width / pixelSizeX + 0.5).toLong diff --git a/raster/src/test/scala/geotrellis/raster/reproject/ReprojectRasterExtentSpec.scala b/raster/src/test/scala/geotrellis/raster/reproject/ReprojectRasterExtentSpec.scala index 52fda2c7f2..a077403db8 100644 --- a/raster/src/test/scala/geotrellis/raster/reproject/ReprojectRasterExtentSpec.scala +++ b/raster/src/test/scala/geotrellis/raster/reproject/ReprojectRasterExtentSpec.scala @@ -109,5 +109,13 @@ class ReprojectRasterExtentSpec extends AnyFunSpec assert(destinationRE.extent covers region) assert(destinationRE.extent.toPolygon() intersects region) } + + it("should reproject single pixel extents") { + val inputExtent = GridExtent[Long](Extent(429180.0, 7652390.0, 429190.0, 7652400.0), CellSize(10.0, 10.0)) + val destinationRE = ReprojectRasterExtent(inputExtent, CRS.fromEpsgCode(32639), LatLng) + + assert(destinationRE.cols == 1) + assert(destinationRE.rows == 1) + } } }