Skip to content

Commit

Permalink
Pass desired resolution to SentinelXMLMetadataRasterSource. #177
Browse files Browse the repository at this point in the history
  • Loading branch information
EmileSonneveld committed Sep 28, 2023
1 parent 613e427 commit 815bf5e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ class FileLayerProvider(openSearch: OpenSearchClient, openSearchCollectionId: St
}else if(dataPath.endsWith("MTD_TL.xml")) {
//TODO EP-3611 parse angles
val te = featureExtentInLayout.map(_.extent) // Can be bigger then original tile.
SentinelXMLMetadataRasterSource(dataPath, bands, te)
SentinelXMLMetadataRasterSource(dataPath, bands, te, Some(theResolution))
}
else {
def alignmentFromDataPath(dataPath: String, projectedExtent: ProjectedExtent): TargetRegion = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ object SentinelXMLMetadataRasterSource {
/**
* Returns SAA,SZA,VAA,VZA selected by the bands argument.
*/
def apply(path:String, bands:Seq[Int]=Seq(0,1,2,3), te:Option[Extent] = None): Seq[SentinelXMLMetadataRasterSource] = {
def apply(path: String,
bands: Seq[Int] = Seq(0, 1, 2, 3),
te: Option[Extent] = None,
cellSize: Option[CellSize] = None
): Seq[SentinelXMLMetadataRasterSource] = {
val theResolution = cellSize.getOrElse(CellSize(10, 10))

val xmlDoc = XML.load(CreoFeatureCollection.loadMetadata(path))
val angles = xmlDoc \\ "Tile_Angles"
val meanSun = angles \ "Mean_Sun_Angle"
Expand All @@ -29,10 +35,10 @@ object SentinelXMLMetadataRasterSource {
val ulx = (position \ "ULX").text.toDouble
val uly = (position \ "ULY").text.toDouble
// TODO: Looking at the cloud locations in the accompanying cloud mask file
val maxExtent = Extent(ulx, uly - (10 * 10980), ulx + (10 * 10980), uly)
val maxExtent = Extent(ulx, uly - (theResolution.width * 10980), ulx + (theResolution.height * 10980), uly)
val targetExtent = te.getOrElse(maxExtent)
val gridExtent = GridExtent[Long](targetExtent, CellSize(10, 10))
val allBands = Seq(mSAA,mSZA,mVAA,mVZA)
val gridExtent = GridExtent[Long](targetExtent, theResolution)
val allBands = Seq(mSAA, mSZA, mVAA, mVZA)
bands.map(b => allBands(b)).map(new SentinelXMLMetadataRasterSource(_, crs, gridExtent, OpenEoSourcePath(path)))

}
Expand All @@ -55,7 +61,11 @@ class SentinelXMLMetadataRasterSource(value: Float,
override def resample(resampleTarget: ResampleTarget, method: ResampleMethod, strategy: OverviewStrategy): RasterSource = ???

override def read(extent: Extent, bands: Seq[Int]): Option[Raster[MultibandTile]] = {
Some(Raster(MultibandTile(FloatConstantTile(value,extent.width.intValue()/10,extent.height.intValue()/10)),extent))
Some(Raster(MultibandTile(FloatConstantTile(
value,
math.floor(extent.width.intValue() / theGridExtent.cellSize.width).toInt,
math.floor(extent.height.intValue() / theGridExtent.cellSize.height).toInt,
)), extent))
}

override def read(bounds: GridBounds[Long], bands: Seq[Int]): Option[Raster[MultibandTile]] = {
Expand Down

0 comments on commit 815bf5e

Please sign in to comment.