LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/amigocloud - ogramigocloudresultlayer.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 0 41 0.0 %
Date: 2024-11-21 22:18:42 Functions: 0 7 0.0 %

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

Generated by: LCOV version 1.14