LCOV - code coverage report
Current view: top level - ogr/ogrsf_frmts/ntf - ogrntflayer.cpp (source / functions) Hit Total Coverage
Test: gdal_filtered.info Lines: 0 62 0.0 %
Date: 2024-11-25 13:07:18 Functions: 0 7 0.0 %

          Line data    Source code
       1             : /******************************************************************************
       2             :  *
       3             :  * Project:  UK NTF Reader
       4             :  * Purpose:  Implements OGRNTFLayer class.
       5             :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       6             :  *
       7             :  ******************************************************************************
       8             :  * Copyright (c) 1999, Frank Warmerdam
       9             :  *
      10             :  * SPDX-License-Identifier: MIT
      11             :  ****************************************************************************/
      12             : 
      13             : #include "ntf.h"
      14             : #include "cpl_conv.h"
      15             : 
      16             : /************************************************************************/
      17             : /*                            OGRNTFLayer()                             */
      18             : /*                                                                      */
      19             : /*      Note that the OGRNTFLayer assumes ownership of the passed       */
      20             : /*      OGRFeatureDefn object.                                          */
      21             : /************************************************************************/
      22             : 
      23           0 : OGRNTFLayer::OGRNTFLayer(OGRNTFDataSource *poDSIn,
      24             :                          OGRFeatureDefn *poFeatureDefine,
      25           0 :                          NTFFeatureTranslator pfnTranslatorIn)
      26             :     : poFeatureDefn(poFeatureDefine), pfnTranslator(pfnTranslatorIn),
      27             :       poDS(poDSIn), iCurrentReader(-1), nCurrentPos((vsi_l_offset)-1),
      28           0 :       nCurrentFID(1)
      29             : {
      30           0 :     SetDescription(poFeatureDefn->GetName());
      31           0 : }
      32             : 
      33             : /************************************************************************/
      34             : /*                           ~OGRNTFLayer()                           */
      35             : /************************************************************************/
      36             : 
      37           0 : OGRNTFLayer::~OGRNTFLayer()
      38             : 
      39             : {
      40           0 :     if (m_nFeaturesRead > 0 && poFeatureDefn != nullptr)
      41             :     {
      42           0 :         CPLDebug("Mem", "%d features read on layer '%s'.", (int)m_nFeaturesRead,
      43           0 :                  poFeatureDefn->GetName());
      44             :     }
      45             : 
      46           0 :     if (poFeatureDefn)
      47           0 :         poFeatureDefn->Release();
      48           0 : }
      49             : 
      50             : /************************************************************************/
      51             : /*                            ResetReading()                            */
      52             : /************************************************************************/
      53             : 
      54           0 : void OGRNTFLayer::ResetReading()
      55             : 
      56             : {
      57           0 :     iCurrentReader = -1;
      58           0 :     nCurrentPos = (vsi_l_offset)-1;
      59           0 :     nCurrentFID = 1;
      60           0 : }
      61             : 
      62             : /************************************************************************/
      63             : /*                           GetNextFeature()                           */
      64             : /************************************************************************/
      65             : 
      66           0 : OGRFeature *OGRNTFLayer::GetNextFeature()
      67             : 
      68             : {
      69           0 :     OGRFeature *poFeature = nullptr;
      70             : 
      71             :     /* -------------------------------------------------------------------- */
      72             :     /*      Have we processed all features already?                         */
      73             :     /* -------------------------------------------------------------------- */
      74           0 :     if (iCurrentReader == poDS->GetFileCount())
      75           0 :         return nullptr;
      76             : 
      77             :     /* -------------------------------------------------------------------- */
      78             :     /*      Do we need to open a file?                                      */
      79             :     /* -------------------------------------------------------------------- */
      80           0 :     if (iCurrentReader == -1)
      81             :     {
      82           0 :         iCurrentReader++;
      83           0 :         nCurrentPos = (vsi_l_offset)-1;
      84             :     }
      85             : 
      86           0 :     NTFFileReader *poCurrentReader = poDS->GetFileReader(iCurrentReader);
      87           0 :     if (poCurrentReader->GetFP() == nullptr)
      88             :     {
      89           0 :         poCurrentReader->Open();
      90             :     }
      91             : 
      92             :     /* -------------------------------------------------------------------- */
      93             :     /*      Ensure we are reading on from the same point we were reading    */
      94             :     /*      from for the last feature, even if some other access            */
      95             :     /*      mechanism has moved the file pointer.                           */
      96             :     /* -------------------------------------------------------------------- */
      97           0 :     if (nCurrentPos != (vsi_l_offset)-1)
      98           0 :         poCurrentReader->SetFPPos(nCurrentPos, nCurrentFID);
      99             :     else
     100           0 :         poCurrentReader->Reset();
     101             : 
     102             :     /* -------------------------------------------------------------------- */
     103             :     /*      Read features till we find one that satisfies our current       */
     104             :     /*      spatial criteria.                                               */
     105             :     /* -------------------------------------------------------------------- */
     106             :     while (true)
     107             :     {
     108           0 :         poFeature = poCurrentReader->ReadOGRFeature(this);
     109           0 :         if (poFeature == nullptr)
     110           0 :             break;
     111             : 
     112           0 :         m_nFeaturesRead++;
     113             : 
     114           0 :         if ((m_poFilterGeom == nullptr ||
     115           0 :              poFeature->GetGeometryRef() == nullptr ||
     116           0 :              FilterGeometry(poFeature->GetGeometryRef())) &&
     117           0 :             (m_poAttrQuery == nullptr || m_poAttrQuery->Evaluate(poFeature)))
     118           0 :             break;
     119             : 
     120           0 :         delete poFeature;
     121             :     }
     122             : 
     123             :     /* -------------------------------------------------------------------- */
     124             :     /*      If we get NULL the file must be all consumed, advance to the    */
     125             :     /*      next file that contains features for this layer.                */
     126             :     /* -------------------------------------------------------------------- */
     127           0 :     if (poFeature == nullptr)
     128             :     {
     129           0 :         poCurrentReader->Close();
     130             : 
     131           0 :         if (poDS->GetOption("CACHING") != nullptr &&
     132           0 :             EQUAL(poDS->GetOption("CACHING"), "OFF"))
     133             :         {
     134           0 :             poCurrentReader->DestroyIndex();
     135             :         }
     136             : 
     137           0 :         do
     138             :         {
     139           0 :             iCurrentReader++;
     140           0 :         } while (iCurrentReader < poDS->GetFileCount() &&
     141           0 :                  !poDS->GetFileReader(iCurrentReader)->TestForLayer(this));
     142             : 
     143           0 :         nCurrentPos = (vsi_l_offset)-1;
     144           0 :         nCurrentFID = 1;
     145             : 
     146           0 :         poFeature = GetNextFeature();
     147             :     }
     148             :     else
     149             :     {
     150           0 :         poCurrentReader->GetFPPos(&nCurrentPos, &nCurrentFID);
     151             :     }
     152             : 
     153           0 :     return poFeature;
     154             : }
     155             : 
     156             : /************************************************************************/
     157             : /*                           TestCapability()                           */
     158             : /************************************************************************/
     159             : 
     160           0 : int OGRNTFLayer::TestCapability(const char *pszCap)
     161             : 
     162             : {
     163           0 :     if (EQUAL(pszCap, OLCZGeometries))
     164           0 :         return TRUE;
     165             : 
     166           0 :     return FALSE;
     167             : }
     168             : 
     169             : /************************************************************************/
     170             : /*                          FeatureTranslate()                          */
     171             : /************************************************************************/
     172             : 
     173           0 : OGRFeature *OGRNTFLayer::FeatureTranslate(NTFFileReader *poReader,
     174             :                                           NTFRecord **papoGroup)
     175             : 
     176             : {
     177           0 :     if (pfnTranslator == nullptr)
     178           0 :         return nullptr;
     179             : 
     180           0 :     return pfnTranslator(poReader, this, papoGroup);
     181             : }

Generated by: LCOV version 1.14