LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/carto - ogrcartoresultlayer.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 24 40 60.0 %
Date: 2024-11-21 22:18:42 Functions: 6 7 85.7 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  Carto Translator
       4             :  * Purpose:  Implements OGRCARTOResultLayer class.
       5             :  * Author:   Even Rouault, <even dot rouault at spatialys.com>
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 2013, Even Rouault <even dot rouault at spatialys.com>
       9             :  *
      10             :  * SPDX-License-Identifier: MIT
      11             :  ****************************************************************************/
      12             : 
      13             : #include "ogr_carto.h"
      14             : 
      15             : /************************************************************************/
      16             : /*                          OGRCARTOResultLayer()                     */
      17             : /************************************************************************/
      18             : 
      19          80 : OGRCARTOResultLayer::OGRCARTOResultLayer(OGRCARTODataSource *poDSIn,
      20          80 :                                          const char *pszRawQueryIn)
      21          80 :     : OGRCARTOLayer(poDSIn), poFirstFeature(nullptr)
      22             : {
      23          80 :     osBaseSQL = pszRawQueryIn;
      24          80 :     SetDescription("result");
      25          80 : }
      26             : 
      27             : /************************************************************************/
      28             : /*                       ~OGRCARTOResultLayer()                       */
      29             : /************************************************************************/
      30             : 
      31         160 : OGRCARTOResultLayer::~OGRCARTOResultLayer()
      32             : 
      33             : {
      34          80 :     delete poFirstFeature;
      35         160 : }
      36             : 
      37             : /************************************************************************/
      38             : /*                          GetLayerDefnInternal()                      */
      39             : /************************************************************************/
      40             : 
      41         168 : OGRFeatureDefn *OGRCARTOResultLayer::GetLayerDefnInternal(json_object *poObjIn)
      42             : {
      43         168 :     if (poFeatureDefn != nullptr)
      44         100 :         return poFeatureDefn;
      45             : 
      46          68 :     EstablishLayerDefn("result", poObjIn);
      47             : 
      48          68 :     return poFeatureDefn;
      49             : }
      50             : 
      51             : /************************************************************************/
      52             : /*                           GetNextRawFeature()                        */
      53             : /************************************************************************/
      54             : 
      55         260 : OGRFeature *OGRCARTOResultLayer::GetNextRawFeature()
      56             : {
      57         260 :     if (poFirstFeature)
      58             :     {
      59          58 :         OGRFeature *poRet = poFirstFeature;
      60          58 :         poFirstFeature = nullptr;
      61          58 :         return poRet;
      62             :     }
      63             :     else
      64         202 :         return OGRCARTOLayer::GetNextRawFeature();
      65             : }
      66             : 
      67             : /************************************************************************/
      68             : /*                                IsOK()                                */
      69             : /************************************************************************/
      70             : 
      71          80 : bool OGRCARTOResultLayer::IsOK()
      72             : {
      73          80 :     CPLErrorReset();
      74          80 :     poFirstFeature = GetNextFeature();
      75          80 :     return CPLGetLastErrorType() == 0;
      76             : }
      77             : 
      78             : /************************************************************************/
      79             : /*                             GetSRS_SQL()                             */
      80             : /************************************************************************/
      81             : 
      82           0 : CPLString OGRCARTOResultLayer::GetSRS_SQL(const char *pszGeomCol)
      83             : {
      84           0 :     CPLString osSQL;
      85           0 :     CPLString osLimitedSQL;
      86             : 
      87           0 :     size_t nPos = osBaseSQL.ifind(" LIMIT ");
      88           0 :     if (nPos != std::string::npos)
      89             :     {
      90           0 :         osLimitedSQL = osBaseSQL;
      91           0 :         size_t nSize = osLimitedSQL.size();
      92           0 :         for (size_t i = nPos + strlen(" LIMIT "); i < nSize; i++)
      93             :         {
      94           0 :             if (osLimitedSQL[i] == ' ' && osLimitedSQL[i - 1] == '0')
      95             :             {
      96           0 :                 osLimitedSQL[i - 1] = '1';
      97           0 :                 break;
      98             :             }
      99           0 :             osLimitedSQL[i] = '0';
     100             :         }
     101             :     }
     102             :     else
     103           0 :         osLimitedSQL.Printf("%s LIMIT 1", osBaseSQL.c_str());
     104             : 
     105             :     /* Assuming that the SRID of the first non-NULL geometry applies */
     106             :     /* to geometries of all rows. */
     107             :     osSQL.Printf("SELECT srid, srtext FROM spatial_ref_sys WHERE srid IN "
     108             :                  "(SELECT ST_SRID(%s) FROM (%s) ogr_subselect)",
     109           0 :                  OGRCARTOEscapeIdentifier(pszGeomCol).c_str(),
     110           0 :                  osLimitedSQL.c_str());
     111             : 
     112           0 :     return osSQL;
     113             : }

Generated by: LCOV version 1.14