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 : * Permission is hereby granted, free of charge, to any person obtaining a 11 : * copy of this software and associated documentation files (the "Software"), 12 : * to deal in the Software without restriction, including without limitation 13 : * the rights to use, copy, modify, merge, publish, distribute, sublicense, 14 : * and/or sell copies of the Software, and to permit persons to whom the 15 : * Software is furnished to do so, subject to the following conditions: 16 : * 17 : * The above copyright notice and this permission notice shall be included 18 : * in all copies or substantial portions of the Software. 19 : * 20 : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 21 : * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 22 : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 23 : * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 24 : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 : * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 26 : * DEALINGS IN THE SOFTWARE. 27 : ****************************************************************************/ 28 : 29 : #include "ntf.h" 30 : #include "cpl_conv.h" 31 : 32 : /************************************************************************/ 33 : /* OGRNTFFeatureClassLayer() */ 34 : /* */ 35 : /* Note that the OGRNTFLayer assumes ownership of the passed */ 36 : /* OGRFeatureDefn object. */ 37 : /************************************************************************/ 38 : 39 0 : OGRNTFFeatureClassLayer::OGRNTFFeatureClassLayer(OGRNTFDataSource *poDSIn) 40 0 : : poFeatureDefn(new OGRFeatureDefn("FEATURE_CLASSES")), 41 0 : poFilterGeom(nullptr), poDS(poDSIn), iCurrentFC(0) 42 : { 43 : /* -------------------------------------------------------------------- */ 44 : /* Establish the schema. */ 45 : /* -------------------------------------------------------------------- */ 46 0 : SetDescription(poFeatureDefn->GetName()); 47 0 : poFeatureDefn->SetGeomType(wkbNone); 48 0 : poFeatureDefn->Reference(); 49 : 50 0 : OGRFieldDefn oFCNum("FEAT_CODE", OFTString); 51 : 52 0 : oFCNum.SetWidth(4); 53 0 : poFeatureDefn->AddFieldDefn(&oFCNum); 54 : 55 0 : OGRFieldDefn oFCName("FC_NAME", OFTString); 56 : 57 0 : oFCNum.SetWidth(80); 58 0 : poFeatureDefn->AddFieldDefn(&oFCName); 59 0 : } 60 : 61 : /************************************************************************/ 62 : /* ~OGRNTFFeatureClassLayer() */ 63 : /************************************************************************/ 64 : 65 0 : OGRNTFFeatureClassLayer::~OGRNTFFeatureClassLayer() 66 : 67 : { 68 0 : if (poFeatureDefn) 69 0 : poFeatureDefn->Release(); 70 : 71 0 : if (poFilterGeom != nullptr) 72 0 : delete poFilterGeom; 73 0 : } 74 : 75 : /************************************************************************/ 76 : /* SetSpatialFilter() */ 77 : /************************************************************************/ 78 : 79 0 : void OGRNTFFeatureClassLayer::SetSpatialFilter(OGRGeometry *poGeomIn) 80 : 81 : { 82 0 : if (poFilterGeom != nullptr) 83 : { 84 0 : delete poFilterGeom; 85 0 : poFilterGeom = nullptr; 86 : } 87 : 88 0 : if (poGeomIn != nullptr) 89 0 : poFilterGeom = poGeomIn->clone(); 90 0 : } 91 : 92 : /************************************************************************/ 93 : /* ResetReading() */ 94 : /************************************************************************/ 95 : 96 0 : void OGRNTFFeatureClassLayer::ResetReading() 97 : 98 : { 99 0 : iCurrentFC = 0; 100 0 : } 101 : 102 : /************************************************************************/ 103 : /* GetNextFeature() */ 104 : /************************************************************************/ 105 : 106 0 : OGRFeature *OGRNTFFeatureClassLayer::GetNextFeature() 107 : 108 : { 109 0 : if (iCurrentFC >= GetFeatureCount()) 110 0 : return nullptr; 111 : 112 0 : return GetFeature((long)iCurrentFC++); 113 : } 114 : 115 : /************************************************************************/ 116 : /* GetFeature() */ 117 : /************************************************************************/ 118 : 119 0 : OGRFeature *OGRNTFFeatureClassLayer::GetFeature(GIntBig nFeatureId) 120 : 121 : { 122 : char *pszFCName, *pszFCId; 123 : 124 0 : if (nFeatureId < 0 || nFeatureId >= poDS->GetFCCount()) 125 0 : return nullptr; 126 : 127 0 : poDS->GetFeatureClass((int)nFeatureId, &pszFCId, &pszFCName); 128 : 129 : /* -------------------------------------------------------------------- */ 130 : /* Create a corresponding feature. */ 131 : /* -------------------------------------------------------------------- */ 132 0 : OGRFeature *poFeature = new OGRFeature(poFeatureDefn); 133 : 134 0 : poFeature->SetField(0, pszFCId); 135 0 : poFeature->SetField(1, pszFCName); 136 0 : poFeature->SetFID(nFeatureId); 137 : 138 0 : return poFeature; 139 : } 140 : 141 : /************************************************************************/ 142 : /* GetFeatureCount() */ 143 : /* */ 144 : /* If a spatial filter is in effect, we turn control over to */ 145 : /* the generic counter. Otherwise we return the total count. */ 146 : /* Eventually we should consider implementing a more efficient */ 147 : /* way of counting features matching a spatial query. */ 148 : /************************************************************************/ 149 : 150 0 : GIntBig OGRNTFFeatureClassLayer::GetFeatureCount(CPL_UNUSED int bForce) 151 : { 152 0 : return poDS->GetFCCount(); 153 : } 154 : 155 : /************************************************************************/ 156 : /* TestCapability() */ 157 : /************************************************************************/ 158 : 159 0 : int OGRNTFFeatureClassLayer::TestCapability(const char *pszCap) 160 : 161 : { 162 0 : if (EQUAL(pszCap, OLCRandomRead)) 163 0 : return TRUE; 164 : 165 0 : else if (EQUAL(pszCap, OLCSequentialWrite) || EQUAL(pszCap, OLCRandomWrite)) 166 0 : return FALSE; 167 : 168 0 : else if (EQUAL(pszCap, OLCFastFeatureCount)) 169 0 : return TRUE; 170 : 171 0 : else if (EQUAL(pszCap, OLCFastSpatialFilter)) 172 0 : return TRUE; 173 : 174 : else 175 0 : return FALSE; 176 : }