LCOV - code coverage report
Current view: top level - frmts/stacta - stactadataset.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 14 16 87.5 %
Date: 2024-05-14 13:00:50 Functions: 5 6 83.3 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  GDAL
       4             :  * Purpose:  STACTA (Spatio-Temporal Asset Catalog Tiled Assets) driver
       5             :  * Author:   Even Rouault, <even dot rouault at spatialys.com>
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2020, Even Rouault <even dot rouault at spatialys.com>
       9             :  *
      10             :  * Permission is hereby granted, free of charge, to any person obtaining a
      11             :  * copy of this software and associated documentation files (the "Software"),
      12             :  * to deal in the Software without restriction, including without limitation
      13             :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      14             :  * and/or sell copies of the Software, and to permit persons to whom the
      15             :  * Software is furnished to do so, subject to the following conditions:
      16             :  *
      17             :  * The above copyright notice and this permission notice shall be included
      18             :  * in all copies or substantial portions of the Software.
      19             :  *
      20             :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      21             :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      22             :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      23             :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      24             :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      25             :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      26             :  * DEALINGS IN THE SOFTWARE.
      27             :  ****************************************************************************/
      28             : 
      29             : #ifndef STACTADATASET_H
      30             : #define STACTADATASET_H
      31             : 
      32             : #include "cpl_mem_cache.h"
      33             : #include "cpl_string.h"
      34             : #include "gdal_pam.h"
      35             : #include "memdataset.h"
      36             : #include "tilematrixset.hpp"
      37             : 
      38             : #include <array>
      39             : #include <map>
      40             : #include <memory>
      41             : #include <vector>
      42             : 
      43             : namespace
      44             : {
      45             : struct Limits
      46             : {
      47             :     int min_tile_col = 0;
      48             :     int max_tile_col = 0;
      49             :     int min_tile_row = 0;
      50             :     int max_tile_row = 0;
      51             : };
      52             : }  // namespace
      53             : /************************************************************************/
      54             : /* ==================================================================== */
      55             : /*                          STACTADataset                               */
      56             : /* ==================================================================== */
      57             : /************************************************************************/
      58             : 
      59             : class STACTARawDataset;
      60             : 
      61             : class STACTADataset final : public GDALPamDataset
      62             : {
      63             :     friend class STACTARasterBand;
      64             :     friend class STACTARawDataset;
      65             :     friend class STACTARawRasterBand;
      66             : 
      67             :     std::array<double, 6> m_adfGeoTransform = {{0.0, 1.0, 0, 0.0, 0.0, 1.0}};
      68             :     OGRSpatialReference m_oSRS{};
      69             :     std::unique_ptr<GDALDataset> m_poDS{};
      70             :     // Array of overview datasets, that are guaranteed to have the same
      71             :     // georeferenced extent as m_poDS (and this dataset), for compliance
      72             :     // with the GDAL data model. They are thus possibly VRT subsets of
      73             :     // the STACTARawDataset stored in m_apoIntermediaryDS
      74             :     std::vector<std::unique_ptr<GDALDataset>> m_apoOverviewDS{};
      75             :     std::vector<std::unique_ptr<GDALDataset>> m_apoIntermediaryDS{};
      76             : 
      77             :     // Cache of tile datasets
      78             :     lru11::Cache<std::string, std::unique_ptr<GDALDataset>> m_oCacheTileDS{32};
      79             : 
      80             :     bool m_bDownloadWholeMetaTile = false;
      81             :     bool m_bSkipMissingMetaTile = false;
      82             : 
      83             :     bool Open(GDALOpenInfo *poOpenInfo);
      84             : 
      85             :   public:
      86             :     static int Identify(GDALOpenInfo *poOpenInfo);
      87             :     static GDALDataset *OpenStatic(GDALOpenInfo *poOpenInfo);
      88             : 
      89             :     ~STACTADataset() override;
      90             : 
      91             :     const OGRSpatialReference *GetSpatialRef() const override;
      92             :     CPLErr GetGeoTransform(double *padfGeoTransform) override;
      93             :     CPLErr IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
      94             :                      int nYSize, void *pData, int nBufXSize, int nBufYSize,
      95             :                      GDALDataType eBufType, int nBandCount, int *panBandMap,
      96             :                      GSpacing nPixelSpace, GSpacing nLineSpace,
      97             :                      GSpacing nBandSpace,
      98             :                      GDALRasterIOExtraArg *psExtraArg) override;
      99             :     CPLErr FlushCache(bool bAtClosing) override;
     100             : };
     101             : 
     102             : /************************************************************************/
     103             : /* ==================================================================== */
     104             : /*                        STACTARasterBand                              */
     105             : /* ==================================================================== */
     106             : /************************************************************************/
     107             : 
     108             : class STACTARasterBand final : public GDALRasterBand
     109             : {
     110             :     friend class STACTADataset;
     111             :     GDALColorInterp m_eColorInterp = GCI_Undefined;
     112             :     int m_bHasNoDataValue = false;
     113             :     double m_dfNoData = 0;
     114             :     double m_dfScale = 1.0;
     115             :     double m_dfOffset = 0.0;
     116             :     std::string m_osUnit{};
     117             : 
     118             :   public:
     119             :     STACTARasterBand(STACTADataset *poDSIn, int nBandIn,
     120             :                      GDALRasterBand *poProtoBand);
     121             :     CPLErr IReadBlock(int nBlockXOff, int nBlockYOff, void *pImage) override;
     122             :     CPLErr IRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
     123             :                      GDALDataType, GSpacing, GSpacing,
     124             :                      GDALRasterIOExtraArg *psExtraArg) override;
     125             : 
     126           0 :     GDALColorInterp GetColorInterpretation() override
     127             :     {
     128           0 :         return m_eColorInterp;
     129             :     }
     130             : 
     131             :     int GetOverviewCount() override;
     132             :     GDALRasterBand *GetOverview(int nIdx) override;
     133             :     double GetNoDataValue(int *pbHasNoData = nullptr) override;
     134             : 
     135           6 :     const char *GetUnitType() override
     136             :     {
     137           6 :         return m_osUnit.c_str();
     138             :     }
     139             : 
     140           6 :     double GetScale(int *pbHasValue = nullptr) override
     141             :     {
     142           6 :         if (pbHasValue)
     143           6 :             *pbHasValue = m_dfScale != 1.0;
     144           6 :         return m_dfScale;
     145             :     }
     146             : 
     147           6 :     double GetOffset(int *pbHasValue = nullptr) override
     148             :     {
     149           6 :         if (pbHasValue)
     150           6 :             *pbHasValue = m_dfOffset != 0.0;
     151           6 :         return m_dfOffset;
     152             :     }
     153             : };
     154             : 
     155             : /************************************************************************/
     156             : /* ==================================================================== */
     157             : /*                        STACTARawDataset                              */
     158             : /* ==================================================================== */
     159             : /************************************************************************/
     160             : 
     161             : class STACTARawDataset final : public GDALDataset
     162             : {
     163             :     friend class STACTADataset;
     164             :     friend class STACTARawRasterBand;
     165             : 
     166             :     CPLString m_osURLTemplate{};
     167             :     int m_nMinMetaTileCol = 0;
     168             :     int m_nMinMetaTileRow = 0;
     169             :     int m_nMetaTileWidth = 0;
     170             :     int m_nMetaTileHeight = 0;
     171             :     STACTADataset *m_poMasterDS = nullptr;
     172             : 
     173             :     std::array<double, 6> m_adfGeoTransform = {{0.0, 1.0, 0, 0.0, 0.0, 1.0}};
     174             :     OGRSpatialReference m_oSRS{};
     175             : 
     176             :   public:
     177             :     bool InitRaster(GDALDataset *poProtoDS,
     178             :                     const std::vector<GDALDataType> &aeDT,
     179             :                     const std::vector<bool> &abSetNoData,
     180             :                     const std::vector<double> &adfNoData,
     181             :                     const gdal::TileMatrixSet *poTMS, const std::string &osTMId,
     182             :                     const gdal::TileMatrixSet::TileMatrix &oTM,
     183             :                     const std::map<CPLString, Limits> &oMapLimits);
     184             : 
     185           2 :     const OGRSpatialReference *GetSpatialRef() const override
     186             :     {
     187           2 :         return &m_oSRS;
     188             :     }
     189             : 
     190             :     CPLErr GetGeoTransform(double *padfGeoTransform) override;
     191             :     CPLErr IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
     192             :                      int nYSize, void *pData, int nBufXSize, int nBufYSize,
     193             :                      GDALDataType eBufType, int nBandCount, int *panBandMap,
     194             :                      GSpacing nPixelSpace, GSpacing nLineSpace,
     195             :                      GSpacing nBandSpace,
     196             :                      GDALRasterIOExtraArg *psExtraArg) override;
     197             : };
     198             : 
     199             : /************************************************************************/
     200             : /* ==================================================================== */
     201             : /*                        STACTARawRasterBand                           */
     202             : /* ==================================================================== */
     203             : /************************************************************************/
     204             : 
     205             : class STACTARawRasterBand final : public GDALRasterBand
     206             : {
     207             :     GDALColorInterp m_eColorInterp = GCI_Undefined;
     208             :     int m_bHasNoDataValue = false;
     209             :     double m_dfNoData = 0;
     210             : 
     211             :   public:
     212             :     STACTARawRasterBand(STACTARawDataset *poDSIn, int nBandIn,
     213             :                         GDALRasterBand *poProtoBand);
     214             : 
     215             :     STACTARawRasterBand(STACTARawDataset *poDSIn, int nBandIn, GDALDataType eDT,
     216             :                         bool bSetNoData, double dfNoData);
     217             : 
     218             :     CPLErr IReadBlock(int nBlockXOff, int nBlockYOff, void *pImage) override;
     219             :     CPLErr IRasterIO(GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize,
     220             :                      int nYSize, void *pData, int nBufXSize, int nBufYSize,
     221             :                      GDALDataType eBufType, GSpacing nPixelSpace,
     222             :                      GSpacing nLineSpace,
     223             :                      GDALRasterIOExtraArg *psExtraArg) override;
     224             : 
     225          63 :     GDALColorInterp GetColorInterpretation() override
     226             :     {
     227          63 :         return m_eColorInterp;
     228             :     }
     229             : 
     230             :     double GetNoDataValue(int *pbHasNoData = nullptr) override;
     231             : };
     232             : 
     233             : #endif  // STACTADATASET_H

Generated by: LCOV version 1.14