Skip to content

Commit

Permalink
ReprojectRasterExtent: support single pixel input
Browse files Browse the repository at this point in the history
  • Loading branch information
jdries committed Jan 23, 2025
1 parent 7960ea1 commit 5a17e45
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,19 @@ 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,14 @@ 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)

}
}
}

0 comments on commit 5a17e45

Please sign in to comment.