/
RDDStitchMethodsSpec.scala
138 lines (113 loc) · 3.9 KB
/
RDDStitchMethodsSpec.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
* Copyright 2016 Azavea
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package geotrellis.spark.stitch
import geotrellis.proj4.LatLng
import geotrellis.raster._
import geotrellis.raster.testkit._
import geotrellis.spark._
import geotrellis.spark.testkit._
import geotrellis.spark.tiling.LayoutDefinition
import geotrellis.vector.Extent
import org.scalatest.FunSpec
class RDDStitchMethodsSpec extends FunSpec
with TileBuilders
with TileLayerRDDBuilders
with TestEnvironment {
describe("Stitching spatial rdds") {
it("should correctly stitch back together single band tile rdd") {
val tile =
createTile(
Array(
1, 1, 2, 2, 3, 3, 4, 4,
1, 1, 2, 2, 3, 3, 4, 4,
5, 5, 6, 6, 7, 7, 8, 8,
5, 5, 6, 6, 7, 7, 8, 8,
9, 9, 10, 10, 11, 11, 12, 12,
9, 9, 10, 10, 11, 11, 12, 12,
13, 13, 13, 13, 14, 14, 15, 15,
13, 13, 13, 13, 14, 14, 15, 15
), 8, 8)
val layer =
createTileLayerRDD(
tile,
TileLayout(2, 2, 4, 4)
)
assertEqual(tile, layer.stitch.tile)
}
it("should correctly stitch back together multi band tile rdd") {
val tile1 =
createTile(
Array(
1, 1, 2, 2, 3, 3, 4, 4,
1, 1, 2, 2, 3, 3, 4, 4,
5, 5, 6, 6, 7, 7, 8, 8,
5, 5, 6, 6, 7, 7, 8, 8,
9, 9, 10, 10, 11, 11, 12, 12,
9, 9, 10, 10, 11, 11, 12, 12,
13, 13, 13, 13, 14, 14, 15, 15,
13, 13, 13, 13, 14, 14, 15, 15
), 8, 8)
val tile2 =
createTile(
Array(
1, 1, 2, 2, 3, 3, 4, 4,
1, 1, 2, 2, 3, 3, 4, 4,
5, 5, 6, 6, 7, 7, 8, 8,
5, 5, 6, 6, 7, 7, 8, 8,
9, 9, 10, 10, 11, 11, 12, 12,
9, 9, 10, 10, 11, 11, 12, 12,
13, 13, 13, 13, 14, 14, 15, 15,
13, 13, 13, 13, 14, 14, 15, 15
).map(_ * 10), 8, 8)
val tile = ArrayMultibandTile(tile1, tile2)
val layer =
createMultibandTileLayerRDD(
tile,
TileLayout(2, 2, 4, 4)
)
assertEqual(tile, layer.stitch.tile)
}
it("should reconstitute a tiled raster to its original size") {
import geotrellis.spark.stitch.Implicits.withSpatialTileRDDMethods
val tile: Tile = byteRaster
val offset = 10
val scale = 10
val size = 5
val extent = Extent(
offset, offset, offset + tile.cols * scale, offset + tile.rows * scale
)
val raster = ProjectedRaster(tile, extent, LatLng)
assert(raster.cellSize == CellSize(scale, scale))
val layout = LayoutDefinition(raster.rasterExtent, size, size)
val kb = KeyBounds(
SpatialKey(0, 0), SpatialKey(layout.layoutCols, layout.layoutRows)
)
val tlm = TileLayerMetadata(
raster.tile.cellType, layout, raster.extent, raster.crs, kb)
val rdd = sc.makeRDD(Seq((raster.projectedExtent, raster.tile)))
val tiled = rdd.tileToLayout(tlm)
val restitched: Tile = withSpatialTileRDDMethods(tiled).stitch()
assert(restitched.dimensions === raster.tile.dimensions,
s"""Expected:
|${raster.asciiDraw()}
|
|Stitched:
|${restitched.asciiDraw()}
""".stripMargin
)
}
}
}