Skip to content

Commit

Permalink
clean up implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
bossie committed May 28, 2024
1 parent d8246e4 commit 50c60f3
Showing 1 changed file with 22 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ object PyramidFactory {
new PyramidFactory(collectionId, datasetId, new DefaultCatalogApi(endpoint), new DefaultProcessApi(endpoint),
new MemoizedAuthApiAccessTokenAuthorizer(clientId, clientSecret, authApiUrl),
processingOptions, sampleType, maxSpatialResolution = maxSpatialResolution, maxSoftErrorsRatio = maxSoftErrorsRatio)

private def byTileId(productId: String, tileIdCriteria: util.Map[String, Any]): Boolean = {
lazy val actualTileId = Sentinel2L2a.extractTileId(productId)

val matchesSingleTileId = tileIdCriteria.get("eq") match {
case tileId: String => actualTileId contains tileId
case _ => true
}

val matchesMultipleTileIds = tileIdCriteria.get("in") match {
case tileIds: util.List[String] => tileIds.asScala.exists(actualTileId.contains)
case _ => true
}

matchesSingleTileId && matchesMultipleTileIds
}
}

class PyramidFactory(collectionId: String, datasetId: String, catalogApi: CatalogApi, processApi: ProcessApi,
Expand Down Expand Up @@ -353,47 +369,21 @@ class PyramidFactory(collectionId: String, datasetId: String, catalogApi: Catalo
}
}

def byTileId(productId: String): Boolean = {
val expectedTileId = Option(metadata_properties
.getOrDefault("tileId", util.Collections.emptyMap())
.get("eq"))
.map(_.asInstanceOf[String])

val expectedTileIds = metadata_properties
.getOrDefault("tileId", util.Collections.emptyMap())
.get("in") match {
case ids: util.List[String] => Some(ids.asScala)
case _ => None
}

lazy val actualTileId = Sentinel2L2a.extractTileId(productId)

val matchesSingleTileId = expectedTileId match {
case None => true
case tileId => tileId == actualTileId
}

val matchesMultipleTileIds = expectedTileIds match {
case None => true
case Some(tileIds) => tileIds.exists(actualTileId.contains)
val features = Option(metadata_properties.get("tileId"))
.foldLeft(authorized { accessToken =>
_catalogApi.search(collectionId, multiPolygon, polygons_crs,
from, to, accessToken, Criteria.toQueryProperties(metadata_properties, collectionId))
}) { (acc, tileIdCriteria) =>
acc.filterKeys(byTileId(_, tileIdCriteria))
}

matchesSingleTileId && matchesMultipleTileIds
}

val features = authorized { accessToken =>
_catalogApi.search(collectionId, multiPolygon, polygons_crs,
from, to, accessToken, Criteria.toQueryProperties(metadata_properties, collectionId))
}.filterKeys(byTileId)

tracker.addInputProductsWithUrls(
collectionId,
features.map {
case (id, Feature(_, FeatureData(_, selfUrl))) => new ProductIdAndUrl(id, selfUrl.orNull)
}.toList.asJava
)


// In test over England, there where up to 0.003 deviations on long line segments due to curvature
// change between CRS. Here we convert that distance to the value in the polygon specific CRS.
//TODO we introduced densifier below, which may solve this problem without requiring this buffer
Expand Down

0 comments on commit 50c60f3

Please sign in to comment.