Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: Interlis 2 Translator 4 : * Purpose: Implements OGRILI2Layer class. 5 : * Author: Markus Schnider, Sourcepole AG 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2004, Pirmin Kalberer, Sourcepole AG 9 : * Copyright (c) 2008-2012, Even Rouault <even dot rouault at spatialys.com> 10 : * 11 : * SPDX-License-Identifier: MIT 12 : ****************************************************************************/ 13 : 14 : #include "cpl_conv.h" 15 : #include "cpl_string.h" 16 : #include "ogr_ili2.h" 17 : 18 : /************************************************************************/ 19 : /* OGRILI2Layer() */ 20 : /************************************************************************/ 21 : 22 38 : OGRILI2Layer::OGRILI2Layer(OGRFeatureDefn *poFeatureDefnIn, 23 : const GeomFieldInfos &oGeomFieldInfosIn, 24 38 : OGRILI2DataSource *poDSIn) 25 : : poFeatureDefn(poFeatureDefnIn), oGeomFieldInfos(oGeomFieldInfosIn), 26 38 : poDS(poDSIn) 27 : { 28 38 : SetDescription(poFeatureDefn->GetName()); 29 38 : poFeatureDefn->Reference(); 30 : 31 38 : listFeatureIt = listFeature.begin(); 32 38 : } 33 : 34 : /************************************************************************/ 35 : /* ~OGRILI2Layer() */ 36 : /************************************************************************/ 37 : 38 76 : OGRILI2Layer::~OGRILI2Layer() 39 : { 40 38 : if (poFeatureDefn) 41 38 : poFeatureDefn->Release(); 42 : 43 38 : listFeatureIt = listFeature.begin(); 44 529 : while (listFeatureIt != listFeature.end()) 45 : { 46 491 : OGRFeature *poFeature = *(listFeatureIt++); 47 491 : delete poFeature; 48 : } 49 76 : } 50 : 51 : /************************************************************************/ 52 : /* AddFeature() */ 53 : /************************************************************************/ 54 : 55 491 : void OGRILI2Layer::AddFeature(OGRFeature *poFeature) 56 : { 57 491 : poFeature->SetFID(static_cast<GIntBig>(1 + listFeature.size())); 58 491 : listFeature.push_back(poFeature); 59 491 : } 60 : 61 : /************************************************************************/ 62 : /* ResetReading() */ 63 : /************************************************************************/ 64 : 65 38 : void OGRILI2Layer::ResetReading() 66 : { 67 38 : listFeatureIt = listFeature.begin(); 68 38 : } 69 : 70 : /************************************************************************/ 71 : /* GetNextFeature() */ 72 : /************************************************************************/ 73 : 74 4 : OGRFeature *OGRILI2Layer::GetNextFeature() 75 : { 76 4 : while (listFeatureIt != listFeature.end()) 77 : { 78 4 : OGRFeature *poFeature = *(listFeatureIt++); 79 : // apply filters 80 8 : if ((m_poFilterGeom == nullptr || 81 8 : FilterGeometry(poFeature->GetGeometryRef())) && 82 4 : (m_poAttrQuery == nullptr || m_poAttrQuery->Evaluate(poFeature))) 83 4 : return poFeature->Clone(); 84 : } 85 0 : return nullptr; 86 : } 87 : 88 : /************************************************************************/ 89 : /* GetFeatureCount() */ 90 : /************************************************************************/ 91 : 92 4 : GIntBig OGRILI2Layer::GetFeatureCount(int bForce) 93 : { 94 4 : if (m_poFilterGeom == nullptr && m_poAttrQuery == nullptr) 95 : { 96 4 : return listFeature.size(); 97 : } 98 : else 99 : { 100 0 : return OGRLayer::GetFeatureCount(bForce); 101 : } 102 : } 103 : 104 : /************************************************************************/ 105 : /* TestCapability() */ 106 : /************************************************************************/ 107 : 108 0 : int OGRILI2Layer::TestCapability(CPL_UNUSED const char *pszCap) 109 : { 110 0 : if (EQUAL(pszCap, OLCCurveGeometries)) 111 0 : return TRUE; 112 0 : else if (EQUAL(pszCap, OLCZGeometries)) 113 0 : return TRUE; 114 : 115 0 : return FALSE; 116 : } 117 : 118 : /************************************************************************/ 119 : /* GetDataset() */ 120 : /************************************************************************/ 121 : 122 1 : GDALDataset *OGRILI2Layer::GetDataset() 123 : { 124 1 : return poDS; 125 : }