Skip to content

Commit 645bcf8

Browse files
committed
saveStitchedTileGrid: return items instead of files
Open-EO/openeo-geopyspark-driver#1111
1 parent bd835d2 commit 645bcf8

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

openeo-geotrellis/src/main/scala/org/openeo/geotrellis/geotiff/package.scala

+15-9
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ package object geotiff {
8585
def saveStitched(rdd: SRDD, path: String, cropBounds: Map[String, Double], compression: Compression): Item =
8686
saveStitched(rdd, path, Some(cropBounds), None, compression)
8787

88-
def saveStitchedTileGrid(rdd: SRDD, path: String, tileGrid: String, compression: Compression): JList[(String, Extent)] =
88+
def saveStitchedTileGrid(rdd: SRDD, path: String, tileGrid: String, compression: Compression): JList[Item] =
8989
saveStitchedTileGrid(rdd, path, tileGrid, None, None, compression)
9090

91-
def saveStitchedTileGrid(rdd: SRDD, path: String, tileGrid: String, cropBounds: Map[String, Double], compression: Compression): JList[(String, Extent)] =
91+
def saveStitchedTileGrid(rdd: SRDD, path: String, tileGrid: String, cropBounds: Map[String, Double], compression: Compression): JList[Item] =
9292
saveStitchedTileGrid(rdd, path, tileGrid, Some(cropBounds), None, compression)
9393

9494
def saveRDDTiled(rdd:MultibandTileLayerRDD[SpaceTimeKey], path:String,zLevel:Int=6,cropBounds:Option[Extent]=Option.empty[Extent]):Unit = {
@@ -850,7 +850,7 @@ package object geotiff {
850850
cropBounds: Option[Map[String, Double]],
851851
cropDimensions: Option[ArrayList[Int]],
852852
compression: Compression)
853-
: JList[(String, Extent)] = {
853+
: JList[Item] = {
854854
val features = TileGrid.computeFeaturesForTileGrid(tileGrid, ProjectedExtent(rdd.metadata.extent,rdd.metadata.crs))
855855

856856
def newFilePath(path: String, tileId: String) = {
@@ -879,19 +879,25 @@ package object geotiff {
879879
val executorAttemptDirectory = createExecutorAttemptDirectory(Path.of(path).getParent)
880880
val filePath = executorAttemptDirectory + "/" + newFilePath(Path.of(path).getFileName.toString, tileId)
881881

882-
(stitchAndWriteToTiff(tiles, filePath, layout, crs, extent, croppedExtent, cropDimensions, compression), extent)
882+
(stitchAndWriteToTiff(tiles, filePath, layout, crs, extent, croppedExtent, cropDimensions, compression), tileId, extent)
883883
}.collect()
884884
val res = geotiffResults.map {
885-
case (geoTiffResultObject, croppedExtent) =>
885+
case (geoTiffResultObject, tileId, croppedExtent) =>
886886
val destinationPath = moveFromExecutorAttemptDirectory(Path.of(path).getParent, geoTiffResultObject)
887-
(destinationPath.toString, croppedExtent)
888-
}.toList.asJava
889-
for ((geotiffResult, _) <- geotiffResults) {
887+
(destinationPath, tileId, croppedExtent)
888+
}
889+
890+
val items = res.map { case (path, tileId, extent) =>
891+
Item(id = s"${UUID.randomUUID()}_$tileId", datetime = null, bbox = extent,
892+
assets = Collections.singletonMap("openEO", Asset(path)))
893+
}
894+
895+
for ((geotiffResult, _, _) <- geotiffResults) {
890896
val successfulExecutorAttemptDirectory = extractExecutorAttemptDirectory(Path.of(path).getParent, geotiffResult)
891897
CreoS3Utils.assetDeleteFolders(List(successfulExecutorAttemptDirectory))
892898
}
893899

894-
res
900+
items.toList.asJava
895901
}
896902

897903
private def stitchAndWriteToTiff(tiles: Iterable[(SpatialKey, MultibandTile)], filePath: String,

openeo-geotrellis/src/test/scala/org/openeo/geotrellis/geotiff/TileGridTest.scala

+12-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ class TileGridTest {
7272
)
7373

7474
// TODO: check if extents (in the layer CRS) are 10000m wide/high (in UTM)
75-
Assert.assertEquals(expectedPaths, tiles.asScala.map { case (path, _) => path }.toSet)
75+
val actualPaths = for {
76+
item <- tiles.asScala
77+
asset <- item.assets.values().asScala
78+
} yield asset.path
79+
80+
Assert.assertEquals(expectedPaths, actualPaths.toSet)
7681

7782
val extent = bbox.reproject(spatialLayer.metadata.crs)
7883
val cropBounds = mapAsJavaMap(Map("xmin" -> extent.xmin, "xmax" -> extent.xmax, "ymin" -> extent.ymin, "ymax" -> extent.ymax))
@@ -86,7 +91,12 @@ class TileGridTest {
8691
)
8792

8893
// TODO: also check extents
89-
Assert.assertEquals(expectedCroppedPaths, croppedTiles.asScala.map { case (path, _) => path }.toSet)
94+
val actualCroppedPaths = for {
95+
item <- croppedTiles.asScala
96+
asset <- item.assets.values().asScala
97+
} yield asset.path
98+
99+
Assert.assertEquals(expectedCroppedPaths, actualCroppedPaths.toSet)
90100
}
91101

92102

0 commit comments

Comments
 (0)