LCOV - code coverage report
Current view: top level - frmts/wcs - wcsdataset.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 8 10 80.0 %
Date: 2024-11-21 22:18:42 Functions: 3 4 75.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  WCS Client Driver
       4             :  * Purpose:  Implementation of Dataset class for WCS.
       5             :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2006, Frank Warmerdam
       9             :  * Copyright (c) 2008-2013, Even Rouault <even dot rouault at spatialys.com>
      10             :  * Copyright (c) 2017, Ari Jolma
      11             :  * Copyright (c) 2017, Finnish Environment Institute
      12             :  *
      13             :  * SPDX-License-Identifier: MIT
      14             :  ****************************************************************************/
      15             : 
      16             : #ifndef WCSDATASET_H_INCLUDED
      17             : #define WCSDATASET_H_INCLUDED
      18             : 
      19             : /************************************************************************/
      20             : /* ==================================================================== */
      21             : /*                              WCSDataset                              */
      22             : /* ==================================================================== */
      23             : /************************************************************************/
      24             : 
      25             : #include "cpl_string.h"
      26             : #include "gdal_pam.h"
      27             : 
      28             : class WCSRasterBand;
      29             : 
      30             : class WCSDataset CPL_NON_FINAL : public GDALPamDataset
      31             : {
      32             :     friend class WCSRasterBand;
      33             :     friend class WCSDataset100;
      34             :     friend class WCSDataset110;
      35             :     friend class WCSDataset201;
      36             : 
      37             :     std::string m_cache_dir;
      38             :     bool bServiceDirty;
      39             :     CPLXMLNode *psService;
      40             : 
      41             :     char *apszCoverageOfferingMD[2];
      42             : 
      43             :     char **papszSDSModifiers;
      44             : 
      45             :     int m_Version;  // eg 100 for 1.0.0, 110 for 1.1.0
      46             :     const char *Version() const;
      47             : 
      48             :     std::string osCRS;  // name of the CRS
      49             :     OGRSpatialReference m_oSRS{};
      50             :     bool native_crs;       // the CRS is the native CRS of the server
      51             :     bool axis_order_swap;  // the CRS requires x and y coordinates to be swapped
      52             :                            // for requests
      53             :     double adfGeoTransform[6];
      54             :     bool SetCRS(const std::string &crs, bool native);
      55             :     void SetGeometry(const std::vector<int> &size,
      56             :                      const std::vector<double> &origin,
      57             :                      const std::vector<std::vector<double>> &offsets);
      58             : 
      59             :     std::string osBandIdentifier;
      60             : 
      61             :     std::string osDefaultTime;
      62             :     std::vector<std::string> aosTimePositions;
      63             : 
      64             :     int TestUseBlockIO(int, int, int, int, int, int) const;
      65             :     CPLErr DirectRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
      66             :                           GDALDataType, int, const int *, GSpacing nPixelSpace,
      67             :                           GSpacing nLineSpace, GSpacing nBandSpace,
      68             :                           GDALRasterIOExtraArg *psExtraArg);
      69             : 
      70             :     virtual CPLErr IRasterIO(GDALRWFlag, int, int, int, int, void *, int, int,
      71             :                              GDALDataType, int, BANDMAP_TYPE,
      72             :                              GSpacing nPixelSpace, GSpacing nLineSpace,
      73             :                              GSpacing nBandSpace,
      74             :                              GDALRasterIOExtraArg *psExtraArg) override;
      75             : 
      76             :     virtual std::vector<double> GetExtent(int nXOff, int nYOff, int nXSize,
      77             :                                           int nYSize, int nBufXSize,
      78             :                                           int nBufYSize) = 0;
      79             : 
      80             :     virtual std::string GetCoverageRequest(bool scaled, int nBufXSize,
      81             :                                            int nBufYSize,
      82             :                                            const std::vector<double> &extent,
      83             :                                            const std::string &osBandList) = 0;
      84             : 
      85             :     CPLErr GetCoverage(int nXOff, int nYOff, int nXSize, int nYSize,
      86             :                        int nBufXSize, int nBufYSize, int nBandCount,
      87             :                        const int *panBandList, GDALRasterIOExtraArg *psExtraArg,
      88             :                        CPLHTTPResult **ppsResult);
      89             : 
      90           0 :     virtual std::string DescribeCoverageRequest()
      91             :     {
      92           0 :         return "";
      93             :     }
      94             : 
      95             :     virtual CPLXMLNode *CoverageOffering(CPLXMLNode *psDC) = 0;
      96             : 
      97             :     int DescribeCoverage();
      98             : 
      99             :     virtual bool ExtractGridInfo() = 0;
     100             : 
     101             :     int EstablishRasterDetails();
     102             : 
     103             :     virtual CPLErr ParseCapabilities(CPLXMLNode *, const std::string &) = 0;
     104             :     virtual void ParseCoverageCapabilities(CPLXMLNode *, const std::string &,
     105             :                                            CPLXMLNode *) = 0;
     106             : 
     107             :     GDALDataset *GDALOpenResult(CPLHTTPResult *psResult);
     108             : 
     109             :     void FlushMemoryResult();
     110             : 
     111             :     std::string osResultFilename;
     112             : 
     113             :     GByte *pabySavedDataBuffer;
     114             : 
     115             :     char **papszHttpOptions;
     116             : 
     117             :     int nMaxCols;
     118             :     int nMaxRows;
     119             : 
     120             :   public:
     121             :     WCSDataset(int version, const char *cache_dir);
     122             :     virtual ~WCSDataset();
     123             : 
     124             :     static WCSDataset *CreateFromMetadata(const std::string &,
     125             :                                           const std::string &);
     126             :     static WCSDataset *CreateFromCapabilities(const std::string &,
     127             :                                               const std::string &,
     128             :                                               const std::string &);
     129             : 
     130             :     static GDALDataset *Open(GDALOpenInfo *);
     131             :     static int Identify(GDALOpenInfo *);
     132             : 
     133             :     virtual CPLErr GetGeoTransform(double *) override;
     134             :     const OGRSpatialReference *GetSpatialRef() const override;
     135             :     virtual char **GetFileList(void) override;
     136             : 
     137             :     virtual char **GetMetadataDomainList() override;
     138             :     virtual char **GetMetadata(const char *pszDomain) override;
     139             : };
     140             : 
     141             : class WCSDataset100 final : public WCSDataset
     142             : {
     143             :     std::vector<double> GetExtent(int nXOff, int nYOff, int nXSize, int nYSize,
     144             :                                   int nBufXSize, int nBufYSize) override;
     145             :     std::string GetCoverageRequest(bool scaled, int nBufXSize, int nBufYSize,
     146             :                                    const std::vector<double> &extent,
     147             :                                    const std::string &osBandList) override;
     148             :     std::string DescribeCoverageRequest() override;
     149             :     CPLXMLNode *CoverageOffering(CPLXMLNode *psDC) override;
     150             :     bool ExtractGridInfo() override;
     151             :     CPLErr ParseCapabilities(CPLXMLNode *, const std::string &) override;
     152             :     void ParseCoverageCapabilities(CPLXMLNode *, const std::string &,
     153             :                                    CPLXMLNode *) override;
     154             : 
     155             :   public:
     156          26 :     explicit WCSDataset100(const char *cache_dir) : WCSDataset(100, cache_dir)
     157             :     {
     158          26 :     }
     159             : };
     160             : 
     161             : class WCSDataset110 CPL_NON_FINAL : public WCSDataset
     162             : {
     163             :     std::vector<double> GetExtent(int nXOff, int nYOff, int nXSize, int nYSize,
     164             :                                   int nBufXSize, int nBufYSize) override;
     165             :     std::string GetCoverageRequest(bool scaled, int nBufXSize, int nBufYSize,
     166             :                                    const std::vector<double> &extent,
     167             :                                    const std::string &) override;
     168             :     std::string DescribeCoverageRequest() override;
     169             :     CPLXMLNode *CoverageOffering(CPLXMLNode *psDC) override;
     170             :     bool ExtractGridInfo() override;
     171             :     CPLErr ParseCapabilities(CPLXMLNode *, const std::string &) override;
     172             :     void ParseCoverageCapabilities(CPLXMLNode *, const std::string &,
     173             :                                    CPLXMLNode *) override;
     174             : 
     175             :   public:
     176          95 :     WCSDataset110(int version, const char *cache_dir)
     177          95 :         : WCSDataset(version, cache_dir)
     178             :     {
     179          95 :     }
     180             : };
     181             : 
     182             : class WCSDataset201 final : public WCSDataset110
     183             : {
     184             :     std::vector<double> GetExtent(int nXOff, int nYOff, int nXSize, int nYSize,
     185             :                                   int nBufXSize, int nBufYSize) override;
     186             :     std::string GetSubdataset(const std::string &coverage);
     187             :     bool SetFormat(CPLXMLNode *coverage);
     188             :     static bool ParseGridFunction(CPLXMLNode *coverage,
     189             :                                   std::vector<int> &axisOrder);
     190             :     int ParseRange(CPLXMLNode *coverage, const std::string &range_subset,
     191             :                    char ***metadata);
     192             :     std::string GetCoverageRequest(bool scaled, int nBufXSize, int nBufYSize,
     193             :                                    const std::vector<double> &extent,
     194             :                                    const std::string &osBandList) override;
     195             :     std::string DescribeCoverageRequest() override;
     196             :     bool GridOffsets(CPLXMLNode *grid, const std::string &subtype,
     197             :                      bool swap_grid_axis, std::vector<double> &origin,
     198             :                      std::vector<std::vector<double>> &offset,
     199             :                      std::vector<std::string> labels, char ***metadata);
     200             :     bool Offset2GeoTransform(const std::vector<double> &origin,
     201             :                              const std::vector<std::vector<double>> &offset);
     202             :     bool ExtractGridInfo() override;
     203             : 
     204             :   public:
     205          35 :     explicit WCSDataset201(const char *cache_dir)
     206          35 :         : WCSDataset110(201, cache_dir)
     207             :     {
     208          35 :     }
     209             : };
     210             : 
     211             : #define DIGIT_ZERO '0'
     212             : 
     213             : // The WCS URL parameters that can be set
     214             : // - through options to the service file
     215             : // - to the URL
     216             : // These are also inherited from template service file.
     217             : // Fundamental URL parameters (service, version, request, coverage)
     218             : // and parameters that require more work from the driver's part, such
     219             : // as subsetting parameters (subset, rangesubset) are not in this
     220             : // list.
     221             : 
     222             : #define WCS_URL_PARAMETERS                                                     \
     223             :     "Format", "Interpolation", "MediaType", "UpdateSequence",                  \
     224             :         "GEOTIFF:COMPRESSION", "GEOTIFF:JPEG_QUALITY", "GEOTIFF:PREDICTOR",    \
     225             :         "GEOTIFF:INTERLEAVE", "GEOTIFF:TILING", "GEOTIFF:TILEWIDTH"
     226             : 
     227             : #endif /* WCSDATASET_H_INCLUDED */

Generated by: LCOV version 1.14