Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: UK NTF Reader 4 : * Purpose: Implements OGRNTFFeatureClassLayer 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 : /* OGRNTFFeatureClassLayer() */ 18 : /* */ 19 : /* Note that the OGRNTFLayer assumes ownership of the passed */ 20 : /* OGRFeatureDefn object. */ 21 : /************************************************************************/ 22 : 23 0 : OGRNTFFeatureClassLayer::OGRNTFFeatureClassLayer(OGRNTFDataSource *poDSIn) 24 0 : : poFeatureDefn(new OGRFeatureDefn("FEATURE_CLASSES")), 25 0 : poFilterGeom(nullptr), poDS(poDSIn), iCurrentFC(0) 26 : { 27 : /* -------------------------------------------------------------------- */ 28 : /* Establish the schema. */ 29 : /* -------------------------------------------------------------------- */ 30 0 : SetDescription(poFeatureDefn->GetName()); 31 0 : poFeatureDefn->SetGeomType(wkbNone); 32 0 : poFeatureDefn->Reference(); 33 : 34 0 : OGRFieldDefn oFCNum("FEAT_CODE", OFTString); 35 : 36 0 : oFCNum.SetWidth(4); 37 0 : poFeatureDefn->AddFieldDefn(&oFCNum); 38 : 39 0 : OGRFieldDefn oFCName("FC_NAME", OFTString); 40 : 41 0 : oFCNum.SetWidth(80); 42 0 : poFeatureDefn->AddFieldDefn(&oFCName); 43 0 : } 44 : 45 : /************************************************************************/ 46 : /* ~OGRNTFFeatureClassLayer() */ 47 : /************************************************************************/ 48 : 49 0 : OGRNTFFeatureClassLayer::~OGRNTFFeatureClassLayer() 50 : 51 : { 52 0 : if (poFeatureDefn) 53 0 : poFeatureDefn->Release(); 54 : 55 0 : if (poFilterGeom != nullptr) 56 0 : delete poFilterGeom; 57 0 : } 58 : 59 : /************************************************************************/ 60 : /* SetSpatialFilter() */ 61 : /************************************************************************/ 62 : 63 0 : void OGRNTFFeatureClassLayer::SetSpatialFilter(OGRGeometry *poGeomIn) 64 : 65 : { 66 0 : if (poFilterGeom != nullptr) 67 : { 68 0 : delete poFilterGeom; 69 0 : poFilterGeom = nullptr; 70 : } 71 : 72 0 : if (poGeomIn != nullptr) 73 0 : poFilterGeom = poGeomIn->clone(); 74 0 : } 75 : 76 : /************************************************************************/ 77 : /* ResetReading() */ 78 : /************************************************************************/ 79 : 80 0 : void OGRNTFFeatureClassLayer::ResetReading() 81 : 82 : { 83 0 : iCurrentFC = 0; 84 0 : } 85 : 86 : /************************************************************************/ 87 : /* GetNextFeature() */ 88 : /************************************************************************/ 89 : 90 0 : OGRFeature *OGRNTFFeatureClassLayer::GetNextFeature() 91 : 92 : { 93 0 : if (iCurrentFC >= GetFeatureCount()) 94 0 : return nullptr; 95 : 96 0 : return GetFeature((long)iCurrentFC++); 97 : } 98 : 99 : /************************************************************************/ 100 : /* GetFeature() */ 101 : /************************************************************************/ 102 : 103 0 : OGRFeature *OGRNTFFeatureClassLayer::GetFeature(GIntBig nFeatureId) 104 : 105 : { 106 : char *pszFCName, *pszFCId; 107 : 108 0 : if (nFeatureId < 0 || nFeatureId >= poDS->GetFCCount()) 109 0 : return nullptr; 110 : 111 0 : poDS->GetFeatureClass((int)nFeatureId, &pszFCId, &pszFCName); 112 : 113 : /* -------------------------------------------------------------------- */ 114 : /* Create a corresponding feature. */ 115 : /* -------------------------------------------------------------------- */ 116 0 : OGRFeature *poFeature = new OGRFeature(poFeatureDefn); 117 : 118 0 : poFeature->SetField(0, pszFCId); 119 0 : poFeature->SetField(1, pszFCName); 120 0 : poFeature->SetFID(nFeatureId); 121 : 122 0 : return poFeature; 123 : } 124 : 125 : /************************************************************************/ 126 : /* GetFeatureCount() */ 127 : /* */ 128 : /* If a spatial filter is in effect, we turn control over to */ 129 : /* the generic counter. Otherwise we return the total count. */ 130 : /* Eventually we should consider implementing a more efficient */ 131 : /* way of counting features matching a spatial query. */ 132 : /************************************************************************/ 133 : 134 0 : GIntBig OGRNTFFeatureClassLayer::GetFeatureCount(CPL_UNUSED int bForce) 135 : { 136 0 : return poDS->GetFCCount(); 137 : } 138 : 139 : /************************************************************************/ 140 : /* TestCapability() */ 141 : /************************************************************************/ 142 : 143 0 : int OGRNTFFeatureClassLayer::TestCapability(const char *pszCap) 144 : 145 : { 146 0 : if (EQUAL(pszCap, OLCRandomRead)) 147 0 : return TRUE; 148 : 149 0 : else if (EQUAL(pszCap, OLCSequentialWrite) || EQUAL(pszCap, OLCRandomWrite)) 150 0 : return FALSE; 151 : 152 0 : else if (EQUAL(pszCap, OLCFastFeatureCount)) 153 0 : return TRUE; 154 : 155 0 : else if (EQUAL(pszCap, OLCFastSpatialFilter)) 156 0 : return TRUE; 157 : 158 : else 159 0 : return FALSE; 160 : }