@@ -320,12 +320,17 @@ package object geotiff {
320
320
formatOptions : GTiffOptions = new GTiffOptions
321
321
): JList [String ] = {
322
322
rdd.sparkContext.setCallSite(s " save_result(GTiff, spatial, $bandCount) " )
323
- val tmp = saveRDDAllowAssetPerBand(rdd, bandCount, path, zLevel, cropBounds, formatOptions).asScala
323
+ val tmp = saveRDDAllowAssetPerBand(rdd, bandCount, path, zLevel, cropBounds, formatOptions)
324
324
logger.warn(" Calling backwards compatibility version for saveRDDAllowAssetPerBand" )
325
325
// if (tmp.size() > 1) {
326
326
// throw new Exception("Multiple returned files, probably meant to call saveRDDAllowAssetPerBand")
327
327
// }
328
- tmp.map(_._1).asJava
328
+ tmp.stream()
329
+ .flatMap { item =>
330
+ item.assets.values().stream()
331
+ .map[String ] { asset => asset.path }
332
+ }
333
+ .collect(Collectors .toList())
329
334
}
330
335
331
336
// noinspection ScalaWeakerAccess
@@ -335,7 +340,7 @@ package object geotiff {
335
340
zLevel : Int = 6 ,
336
341
cropBounds : Option [Extent ] = Option .empty[Extent ],
337
342
formatOptions : GTiffOptions = new GTiffOptions
338
- ): JList [( String , Extent , JList [ Int ]) ] = {
343
+ ): JList [Item ] = {
339
344
formatOptions.assertNoConflicts()
340
345
if (formatOptions.separateAssetPerBand) {
341
346
val bandLabels = formatOptions.tags.bandTags.map(_(" DESCRIPTION" ))
@@ -395,7 +400,7 @@ package object geotiff {
395
400
} else {
396
401
(geoTiffResultObject.correctPath, extent, bandIndices)
397
402
}
398
- }.toList.sortBy(_._1).asJava
403
+ }
399
404
400
405
if (path.endsWith(" out" )) {
401
406
val beforeOut = path.substring(0 , path.length - " out" .length)
@@ -405,12 +410,18 @@ package object geotiff {
405
410
}
406
411
}
407
412
408
- res
413
+ val assets = res.map { case (path, _, bandIndices) =>
414
+ val bandNames = bandIndices.asScala.map(bandLabels.apply)
415
+ s " openEO_ ${bandNames mkString " _" }" -> Asset (path, bandIndices)
416
+ }.toMap.asJava
417
+
418
+ Collections .singletonList(Item (id = UUID .randomUUID().toString, datetime = null , bbox = extent, assets))
419
+ // TODO: restore asset ordering?
409
420
} else {
410
- val tiffPaths = saveRDDGeneric(rdd, bandCount, path, zLevel, cropBounds, formatOptions).asScala
411
- tiffPaths.map { case ( tiffPath, extent) =>
412
- (tiffPath, extent, ( 0 until bandCount).toList.asJava)
413
- }.asJava
421
+ val (tiffPath, extent) = saveRDDGeneric(rdd, bandCount, path, zLevel, cropBounds, formatOptions)
422
+ val assets = Collections .singletonMap( " openEO " , Asset ( tiffPath, ( 0 until bandCount).asJava))
423
+
424
+ Collections .singletonList( Item (id = UUID .randomUUID().toString, datetime = null , bbox = extent, assets))
414
425
}
415
426
}
416
427
@@ -503,7 +514,7 @@ package object geotiff {
503
514
def levelFor (extent : Extent , cellSize : CellSize ): LayoutLevel = ???
504
515
}
505
516
506
- def saveRDDGeneric [K : SpatialComponent : Boundable : ClassTag ](rdd : MultibandTileLayerRDD [K ], bandCount : Int , path : String , zLevel : Int = 6 , cropBounds : Option [Extent ] = None , formatOptions : GTiffOptions = new GTiffOptions ): JList [ (String , Extent )] = {
517
+ private def saveRDDGeneric [K : SpatialComponent : Boundable : ClassTag ](rdd : MultibandTileLayerRDD [K ], bandCount : Int , path : String , zLevel : Int = 6 , cropBounds : Option [Extent ] = None , formatOptions : GTiffOptions = new GTiffOptions ): (String , Extent ) = {
507
518
val preProcessResult : (GridBounds [Int ], Extent , RDD [(K , MultibandTile )] with Metadata [TileLayerMetadata [K ]]) = preProcess(rdd,cropBounds)
508
519
val gridBounds : GridBounds [Int ] = preProcessResult._1
509
520
val croppedExtent : Extent = preProcessResult._2
@@ -577,13 +588,10 @@ package object geotiff {
577
588
case None => // do nothing
578
589
}
579
590
580
- Collections .singletonList(( geoTiffResultObject.correctPath, croppedExtent) )
581
- }finally {
591
+ ( geoTiffResultObject.correctPath, croppedExtent)
592
+ } finally {
582
593
preprocessedRdd.unpersist()
583
594
}
584
-
585
-
586
-
587
595
}
588
596
589
597
private def getCompressedTiles [K : SpatialComponent : Boundable : ClassTag ](preprocessedRdd : RDD [(K , MultibandTile )] with Metadata [TileLayerMetadata [K ]],gridBounds : GridBounds [Int ], compression : Compression ): (collection.Map [Int , Array [Byte ]], CellType , Double , Int ) = {
0 commit comments