LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/plscenes - ogr_plscenes.h (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 12 12 100.0 %
Date: 2025-09-10 17:48:50 Functions: 5 5 100.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  PlanetLabs scene driver
       4             :  * Purpose:  PLScenes driver interface
       5             :  * Author:   Even Rouault, even dot rouault at spatialys.com
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2015, Planet Labs
       9             :  *
      10             :  * SPDX-License-Identifier: MIT
      11             :  ****************************************************************************/
      12             : 
      13             : #ifndef OGR_PLSCENES_H_INCLUDED
      14             : #define OGR_PLSCENES_H_INCLUDED
      15             : 
      16             : #include "gdal_priv.h"
      17             : #include "ogrsf_frmts.h"
      18             : #include "ogr_srs_api.h"
      19             : #include "cpl_http.h"
      20             : #include "ogrlibjsonutils.h"
      21             : #include "ogr_swq.h"
      22             : #include <map>
      23             : #include <set>
      24             : #include <vector>
      25             : 
      26             : class OGRPLScenesDataV1Layer;
      27             : 
      28             : class OGRPLScenesDataV1Dataset final : public GDALDataset
      29             : {
      30             :     mutable bool m_bLayerListInitialized;
      31             :     bool m_bMustCleanPersistent;
      32             :     CPLString m_osBaseURL;
      33             :     CPLString m_osAPIKey;
      34             :     CPLString m_osNextItemTypesPageURL;
      35             :     CPLString m_osFilter;
      36             : 
      37             :     int m_nLayers;
      38             :     OGRPLScenesDataV1Layer **m_papoLayers;
      39             : 
      40             :     bool m_bFollowLinks;
      41             : 
      42             :     char **GetBaseHTTPOptions();
      43             :     OGRLayer *ParseItemType(json_object *poItemType);
      44             :     bool ParseItemTypes(json_object *poObj, CPLString &osNext);
      45             :     void EstablishLayerList();
      46             :     GDALDataset *OpenRasterScene(GDALOpenInfo *poOpenInfo, CPLString osScene,
      47             :                                  char **papszOptions);
      48             :     CPLString InsertAPIKeyInURL(CPLString osURL);
      49             : 
      50             :   public:
      51             :     OGRPLScenesDataV1Dataset();
      52             :     ~OGRPLScenesDataV1Dataset() override;
      53             : 
      54             :     int GetLayerCount() const override;
      55             : 
      56             :     using GDALDataset::GetLayer;
      57             :     const OGRLayer *GetLayer(int idx) const override;
      58             :     OGRLayer *GetLayerByName(const char *pszName) override;
      59             : 
      60             :     json_object *RunRequest(const char *pszURL, int bQuiet404Error = FALSE,
      61             :                             const char *pszHTTPVerb = "GET",
      62             :                             bool bExpectJSonReturn = true,
      63             :                             const char *pszPostContent = nullptr);
      64             : 
      65          21 :     bool DoesFollowLinks() const
      66             :     {
      67          21 :         return m_bFollowLinks;
      68             :     }
      69             : 
      70          18 :     const CPLString &GetFilter() const
      71             :     {
      72          18 :         return m_osFilter;
      73             :     }
      74             : 
      75          58 :     const CPLString &GetBaseURL() const
      76             :     {
      77          58 :         return m_osBaseURL;
      78             :     }
      79             : 
      80             :     static GDALDataset *Open(GDALOpenInfo *poOpenInfo);
      81             : };
      82             : 
      83             : class OGRPLScenesDataV1FeatureDefn final : public OGRFeatureDefn
      84             : {
      85             :     OGRPLScenesDataV1Layer *m_poLayer;
      86             : 
      87             :   public:
      88          12 :     OGRPLScenesDataV1FeatureDefn(OGRPLScenesDataV1Layer *poLayer,
      89             :                                  const char *pszName)
      90          12 :         : OGRFeatureDefn(pszName), m_poLayer(poLayer)
      91             :     {
      92          12 :     }
      93             : 
      94             :     int GetFieldCount() const override;
      95             : 
      96          12 :     void DropRefToLayer()
      97             :     {
      98          12 :         m_poLayer = nullptr;
      99          12 :     }
     100             : };
     101             : 
     102             : class OGRPLScenesDataV1Layer final : public OGRLayer
     103             : {
     104             :     friend class OGRPLScenesDataV1Dataset;
     105             :     friend class OGRPLScenesDataV1FeatureDefn;
     106             : 
     107             :     OGRPLScenesDataV1Dataset *m_poDS;
     108             :     bool m_bFeatureDefnEstablished;
     109             :     OGRPLScenesDataV1FeatureDefn *m_poFeatureDefn;
     110             :     OGRSpatialReference *m_poSRS;
     111             :     GIntBig m_nTotalFeatures;
     112             :     std::map<CPLString, int> m_oMapPrefixedJSonFieldNameToFieldIdx;
     113             :     std::map<int, CPLString> m_oMapFieldIdxToQueryableJSonFieldName;
     114             : 
     115             :     GIntBig m_nNextFID;
     116             :     bool m_bEOF;
     117             :     bool m_bStillInFirstPage;
     118             :     CPLString m_osNextURL;
     119             :     CPLString m_osRequestURL;
     120             :     int m_nPageSize;
     121             :     bool m_bInFeatureCountOrGetExtent;
     122             : 
     123             :     json_object *m_poPageObj;
     124             :     json_object *m_poFeatures;
     125             :     int m_nFeatureIdx;
     126             : 
     127             :     json_object *m_poAttributeFilter;
     128             :     bool m_bFilterMustBeClientSideEvaluated;
     129             : 
     130             :     std::set<CPLString> m_oSetAssets;
     131             :     std::set<CPLString> m_oSetUnregisteredAssets;
     132             :     std::set<CPLString> m_oSetUnregisteredFields;
     133             : 
     134             :     OGRFeature *GetNextRawFeature();
     135             :     bool
     136             :     SetFieldFromPrefixedJSonFieldName(OGRFeature *poFeature,
     137             :                                       const CPLString &osPrefixedJSonFieldName,
     138             :                                       json_object *poVal);
     139             :     void EstablishLayerDefn();
     140             :     void RegisterField(OGRFieldDefn *poFieldDefn,
     141             :                        const char *pszQueryableJSonName,
     142             :                        const char *pszPrefixedJSonName);
     143             :     bool GetNextPage();
     144             :     json_object *BuildFilter(swq_expr_node *poNode);
     145             :     bool IsSimpleComparison(const swq_expr_node *poNode);
     146             : 
     147             :   public:
     148             :     OGRPLScenesDataV1Layer(OGRPLScenesDataV1Dataset *poDS, const char *pszName);
     149             :     ~OGRPLScenesDataV1Layer() override;
     150             : 
     151             :     void ResetReading() override;
     152             :     OGRFeature *GetNextFeature() override;
     153             :     int TestCapability(const char *) const override;
     154             :     const OGRFeatureDefn *GetLayerDefn() const override;
     155             :     GIntBig GetFeatureCount(int bForce = FALSE) override;
     156             : 
     157             :     char **GetMetadata(const char *pszDomain = "") override;
     158             :     virtual const char *GetMetadataItem(const char *pszName,
     159             :                                         const char *pszDomain = "") override;
     160             : 
     161             :     OGRErr ISetSpatialFilter(int iGeomField,
     162             :                              const OGRGeometry *poGeom) override;
     163             : 
     164             :     OGRErr SetAttributeFilter(const char *) override;
     165             : 
     166             :     OGRErr IGetExtent(int iGeomField, OGREnvelope *psExtent,
     167             :                       bool bForce) override;
     168             : };
     169             : 
     170             : #endif /* ndef OGR_PLSCENES_H_INCLUDED */

Generated by: LCOV version 1.14