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

Tile combine should union cellTypes #3284

Merged
merged 2 commits into from
Aug 17, 2020
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix combineDouble of ArrayTile and ConstantTile with non-commutative operator [#3257](https://github.com/locationtech/geotrellis/issues/3257)
- Update GDAL up to 3.1 [#3279](https://github.com/locationtech/geotrellis/pull/3279)
- Fix GeoTiff writer does not currently support WebMercator projection with no EPSG code set [#3281](https://github.com/locationtech/geotrellis/issues/3281)
- Fix Tile combine should union cellTypes [#3284](https://github.com/locationtech/geotrellis/pull/3284)

## [3.4.1] - 2020-07-16

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ case class CompositeTile(tiles: Seq[Tile],
def combine(other: Tile)(f: (Int, Int) => Int): Tile = {
(this, other).assertEqualDimensions

val result = ArrayTile.alloc(cellType, cols, rows)
val result = ArrayTile.alloc(cellType.union(other.cellType), cols, rows)
val layoutCols = tileLayout.layoutCols
val layoutRows = tileLayout.layoutRows
val tileCols = tileLayout.tileCols
Expand Down
2 changes: 1 addition & 1 deletion raster/src/main/scala/geotrellis/raster/CroppedTile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ case class CroppedTile(
def combine(other: Tile)(f: (Int, Int) => Int): Tile = {
(this, other).assertEqualDimensions

val tile = ArrayTile.alloc(cellType, cols, rows)
val tile = ArrayTile.alloc(cellType.union(other.cellType), cols, rows)
cfor(0)(_ < rows, _ + 1) { row =>
cfor(0)(_ < cols, _ + 1) { col =>
tile.set(col, row, f(get(col, row), other.get(col, row)))
Expand Down
2 changes: 1 addition & 1 deletion raster/src/main/scala/geotrellis/raster/PaddedTile.scala
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ case class PaddedTile(chunk: Tile, colOffset: Int, rowOffset: Int, cols: Int, ro
def combine(other: Tile)(f: (Int, Int) => Int): Tile = {
(this, other).assertEqualDimensions

val tile = ArrayTile.alloc(cellType, cols, rows)
val tile = ArrayTile.alloc(cellType.union(other.cellType), cols, rows)
cfor(0)(_ < rows, _ + 1) { row =>
cfor(0)(_ < cols, _ + 1) { col =>
tile.set(col, row, f(get(col, row), other.get(col, row)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ abstract class GeoTiffTile(
compressor.createDecompressor(),
segmentLayout,
compression,
cellType,
cellType.union(other.cellType),
overviews = overviews
)
case _ =>
Expand Down
9 changes: 9 additions & 0 deletions raster/src/test/scala/geotrellis/raster/ArrayTileSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,15 @@ class ArrayTileSpec extends AnyFunSpec with Matchers with RasterMatchers with Ti
assert(tile1 != tile2)
}
}

describe("ArrayTile cellType combine") {
it("should union cellTypes") {
val int = IntArrayTile(Array.ofDim[Int](2).fill(0), 1, 1)
val dt = DoubleArrayTile(Array.ofDim[Double](2).fill(0), 1, 1)

int.combine(dt)(_ + _).cellType shouldBe int.cellType.union(dt.cellType)
}
}
}

object ArrayTileSpec {
Expand Down
25 changes: 23 additions & 2 deletions raster/src/test/scala/geotrellis/raster/CompositeTileSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import org.scalatest.funspec.AnyFunSpec
import spire.syntax.cfor._

class CompositeTileSpec extends AnyFunSpec with TileBuilders with RasterMatchers with TestFiles {
describe("wrap") {
describe("CompositeTileSpec wrap") {
it("wraps a literal raster") {
val r =
createTile(
Expand All @@ -49,7 +49,7 @@ class CompositeTileSpec extends AnyFunSpec with TileBuilders with RasterMatchers
arr.toSet.size should be (1)
values += arr(0)
}
values.toSeq.sorted.toSeq should be (Seq(1, 2, 3, 4, 5, 6))
values.toSeq.sorted should be (Seq(1, 2, 3, 4, 5, 6))

assertEqual(r, tiled)
}
Expand Down Expand Up @@ -152,4 +152,25 @@ class CompositeTileSpec extends AnyFunSpec with TileBuilders with RasterMatchers

}
}

describe("CompositeTile cellType combine") {
it("should union cellTypes") {
val int = {
val r =
createTile(
Array(1, 1, 1, 2, 2, 2, 3, 3, 3,
1, 1, 1, 2, 2, 2, 3, 3, 3,

4, 4, 4, 5, 5, 5, 6, 6, 6,
4, 4, 4, 5, 5, 5, 6, 6, 6),
9, 4)

val tl = TileLayout(3, 2, 3, 2)
CompositeTile.wrap(r, tl)
}
val dt = int.convert(DoubleCellType)

int.combine(dt)(_ + _).cellType shouldBe int.cellType.union(dt.cellType)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ class ConstantTileSpec extends AnyFunSpec with Matchers with RasterMatchers with
val r1 = ConstantTile.fromBytes(t1.toBytes(), t1.cellType, cols, rows)
assert(t1 === r1)
}
}

describe("ConstantTile cellType combine") {
it("should union cellTypes") {
val int = IntConstantTile(-65536, 1, 1)
val dt = DoubleConstantTile(-Math.E, 1, 1)

int.combine(dt)(_ + _).cellType shouldBe int.cellType.union(dt.cellType)
}
}
}
22 changes: 21 additions & 1 deletion raster/src/test/scala/geotrellis/raster/CroppedTileSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import geotrellis.vector.Extent
import org.scalatest.funspec.AnyFunSpec

class CroppedTileSpec extends AnyFunSpec with TileBuilders with RasterMatchers with TestFiles {

describe("CroppedTileSpec") {
it("should combine cropped tile") {
val r = createTile(
Expand All @@ -43,4 +42,25 @@ class CroppedTileSpec extends AnyFunSpec with TileBuilders with RasterMatchers w
4, 4, 4))
}
}

describe("CroppedTile cellType combine") {
it("should union cellTypes") {
val int = {
val r = createTile(
Array[Int](
1, 1, 1, 1, 1,
1, 2, 2, 2, 1,
1, 2, 2, 2, 1,
1, 2, 2, 2, 1,
1, 1, 1, 1, 1))

val sourceExtent = Extent(0, 0, 5, 5)
val targetExtent = Extent(1, 1, 4, 4)
CroppedTile(r, sourceExtent, targetExtent).toArrayTile
}
val dt = int.convert(DoubleCellType)

int.combine(dt)(_ + _).cellType shouldBe int.cellType.union(dt.cellType)
}
}
}
9 changes: 9 additions & 0 deletions raster/src/test/scala/geotrellis/raster/PaddedTileSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,13 @@ class PaddedTileSpec extends AnyFunSpec with Matchers with RasterMatchers {

assertEqual(copy, expected)
}

describe("PaddedTile cellType combine") {
it("should union cellTypes") {
val int = padded
val dt = padded.convert(DoubleCellType)

int.combine(dt)(_ + _).cellType shouldBe int.cellType.union(dt.cellType)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,13 @@ class GeoTiffTileSpec extends AnyFunSpec with RasterMatchers with TileBuilders w
assertEqual(actual, expected)
}
}

describe("GeoTiffTile cellType combine") {
it("should union cellTypes") {
val int = IntArrayTile(Array.ofDim[Int](2).fill(0), 1, 1).toGeoTiffTile()
val dt = DoubleArrayTile(Array.ofDim[Double](2).fill(0), 1, 1).toGeoTiffTile()

int.combine(dt)(_ + _).cellType shouldBe int.cellType.union(dt.cellType)
}
}
}