Processes the getDownloadId parameters and returns the built image. Given transformation parameters (crs, crs_transform, dimensions, scale, and region), constructs an image per band. Band level parameters override the parameters specified in the top level. If dimensions and scale parame
(self, params: dict[str, Any])
| 381 | return image, request |
| 382 | |
| 383 | def _build_download_id_image(self, params: dict[str, Any]) -> Any: |
| 384 | """Processes the getDownloadId parameters and returns the built image. |
| 385 | |
| 386 | Given transformation parameters (crs, crs_transform, dimensions, scale, and |
| 387 | region), constructs an image per band. Band level parameters override the |
| 388 | parameters specified in the top level. If dimensions and scale parameters |
| 389 | are both specified, the scale parameter is ignored. |
| 390 | |
| 391 | Image transformations will be applied on a per band basis if the |
| 392 | format parameter is ZIPPED_GEO_TIFF_PER_BAND and there are bands in the |
| 393 | bands list. Otherwise, the transformations will be applied on the entire |
| 394 | image. |
| 395 | |
| 396 | Args: |
| 397 | params: The getDownloadId parameters. |
| 398 | |
| 399 | Returns: |
| 400 | The image filtered to the given bands and the associated transformations |
| 401 | applied. |
| 402 | """ |
| 403 | params = params.copy() |
| 404 | |
| 405 | def _extract_and_validate_transforms(obj: dict[str, Any]) -> dict[str, Any]: |
| 406 | """Takes a parameter dictionary and extracts the transformation keys.""" |
| 407 | extracted = {} |
| 408 | for key in ['crs', 'crs_transform', 'dimensions', 'region']: |
| 409 | if key in obj: |
| 410 | extracted[key] = obj[key] |
| 411 | # Since dimensions and scale are mutually exclusive, we ignore scale |
| 412 | # if dimensions are specified. |
| 413 | if 'scale' in obj and 'dimensions' not in obj: |
| 414 | extracted['scale'] = obj['scale'] |
| 415 | return extracted |
| 416 | |
| 417 | def _build_image_per_band(band_params: dict[str, Any]) -> Any: |
| 418 | """Takes a band dictionary and builds an image for it.""" |
| 419 | if 'id' not in band_params: |
| 420 | raise ee_exception.EEException('Each band dictionary must have an id.') |
| 421 | band_id = band_params['id'] |
| 422 | band_image = self.select(band_id) |
| 423 | # Override the existing top level params with the band level params. |
| 424 | copy_params = _extract_and_validate_transforms(params) |
| 425 | band_params = _extract_and_validate_transforms(band_params) |
| 426 | copy_params.update(band_params) |
| 427 | band_params = _extract_and_validate_transforms(copy_params) |
| 428 | # pylint: disable=protected-access |
| 429 | band_image, _ = band_image._apply_spatial_transformations(band_params) |
| 430 | # pylint: enable=protected-access |
| 431 | return band_image |
| 432 | |
| 433 | if params['format'] == 'ZIPPED_GEO_TIFF_PER_BAND' and params.get('bands'): |
| 434 | # Build a new image based on the constituent band images. |
| 435 | image = Image.combine_( |
| 436 | [_build_image_per_band(band) for band in params['bands']]) |
| 437 | else: |
| 438 | # Apply transformations directly onto the image, ignoring any band params. |
| 439 | copy_params = _extract_and_validate_transforms(params) |
| 440 | image, copy_params = self._apply_spatial_transformations(copy_params) |