Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: EDIGEO Translator 4 : * Purpose: Implements OGREDIGEOLayer class. 5 : * Author: Even Rouault, <even dot rouault at spatialys.com> 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2011-2013, Even Rouault <even dot rouault at spatialys.com> 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 "ogr_edigeo.h" 30 : #include "cpl_conv.h" 31 : #include "cpl_string.h" 32 : #include "ogr_p.h" 33 : #include "ogr_srs_api.h" 34 : 35 : /************************************************************************/ 36 : /* OGREDIGEOLayer() */ 37 : /************************************************************************/ 38 : 39 0 : OGREDIGEOLayer::OGREDIGEOLayer(OGREDIGEODataSource *poDSIn, const char *pszName, 40 : OGRwkbGeometryType eType, 41 0 : OGRSpatialReference *poSRSIn) 42 0 : : poDS(poDSIn), poFeatureDefn(new OGRFeatureDefn(pszName)), poSRS(poSRSIn), 43 0 : nNextFID(0) 44 : { 45 0 : if (poSRS) 46 0 : poSRS->Reference(); 47 : 48 0 : poFeatureDefn->Reference(); 49 0 : poFeatureDefn->SetGeomType(eType); 50 0 : if (poFeatureDefn->GetGeomFieldCount() != 0) 51 0 : poFeatureDefn->GetGeomFieldDefn(0)->SetSpatialRef(poSRS); 52 0 : SetDescription(poFeatureDefn->GetName()); 53 0 : } 54 : 55 : /************************************************************************/ 56 : /* ~OGREDIGEOLayer() */ 57 : /************************************************************************/ 58 : 59 0 : OGREDIGEOLayer::~OGREDIGEOLayer() 60 : 61 : { 62 0 : for (int i = 0; i < (int)aosFeatures.size(); i++) 63 0 : delete aosFeatures[i]; 64 : 65 0 : poFeatureDefn->Release(); 66 : 67 0 : if (poSRS) 68 0 : poSRS->Release(); 69 0 : } 70 : 71 : /************************************************************************/ 72 : /* ResetReading() */ 73 : /************************************************************************/ 74 : 75 0 : void OGREDIGEOLayer::ResetReading() 76 : 77 : { 78 0 : nNextFID = 0; 79 0 : } 80 : 81 : /************************************************************************/ 82 : /* GetNextRawFeature() */ 83 : /************************************************************************/ 84 : 85 0 : OGRFeature *OGREDIGEOLayer::GetNextRawFeature() 86 : { 87 0 : if (nNextFID < (int)aosFeatures.size()) 88 : { 89 0 : OGRFeature *poFeature = aosFeatures[nNextFID]->Clone(); 90 0 : nNextFID++; 91 0 : return poFeature; 92 : } 93 : else 94 0 : return nullptr; 95 : } 96 : 97 : /************************************************************************/ 98 : /* GetFeature() */ 99 : /************************************************************************/ 100 : 101 0 : OGRFeature *OGREDIGEOLayer::GetFeature(GIntBig nFID) 102 : { 103 0 : if (nFID >= 0 && nFID < (int)aosFeatures.size()) 104 0 : return aosFeatures[(int)nFID]->Clone(); 105 : else 106 0 : return nullptr; 107 : } 108 : 109 : /************************************************************************/ 110 : /* TestCapability() */ 111 : /************************************************************************/ 112 : 113 0 : int OGREDIGEOLayer::TestCapability(const char *pszCap) 114 : 115 : { 116 0 : if (EQUAL(pszCap, OLCFastFeatureCount)) 117 0 : return m_poFilterGeom == nullptr && m_poAttrQuery == nullptr; 118 : 119 0 : else if (EQUAL(pszCap, OLCRandomRead)) 120 0 : return TRUE; 121 : 122 0 : else if (EQUAL(pszCap, OLCStringsAsUTF8)) 123 0 : return poDS->HasUTF8ContentOnly(); 124 : 125 0 : return FALSE; 126 : } 127 : 128 : /************************************************************************/ 129 : /* GetExtent() */ 130 : /************************************************************************/ 131 : 132 0 : OGRErr OGREDIGEOLayer::GetExtent(OGREnvelope *psExtent, int bForce) 133 : { 134 : /*if (poDS->bExtentValid) 135 : { 136 : psExtent->MinX = poDS->dfMinX; 137 : psExtent->MinY = poDS->dfMinY; 138 : psExtent->MaxX = poDS->dfMaxX; 139 : psExtent->MaxY = poDS->dfMaxY; 140 : return OGRERR_NONE; 141 : }*/ 142 : 143 0 : return OGRLayer::GetExtent(psExtent, bForce); 144 : } 145 : 146 : /************************************************************************/ 147 : /* GetFeatureCount() */ 148 : /************************************************************************/ 149 : 150 0 : GIntBig OGREDIGEOLayer::GetFeatureCount(int bForce) 151 : { 152 0 : if (m_poFilterGeom != nullptr || m_poAttrQuery != nullptr) 153 0 : return OGRLayer::GetFeatureCount(bForce); 154 : 155 0 : return (int)aosFeatures.size(); 156 : } 157 : 158 : /************************************************************************/ 159 : /* AddFeature() */ 160 : /************************************************************************/ 161 : 162 0 : void OGREDIGEOLayer::AddFeature(OGRFeature *poFeature) 163 : { 164 0 : poFeature->SetFID(aosFeatures.size()); 165 0 : aosFeatures.push_back(poFeature); 166 0 : } 167 : 168 : /************************************************************************/ 169 : /* GetAttributeIndex() */ 170 : /************************************************************************/ 171 : 172 0 : int OGREDIGEOLayer::GetAttributeIndex(const CPLString &osRID) 173 : { 174 : std::map<CPLString, int>::iterator itAttrIndex = 175 0 : mapAttributeToIndex.find(osRID); 176 0 : if (itAttrIndex != mapAttributeToIndex.end()) 177 0 : return itAttrIndex->second; 178 : else 179 0 : return -1; 180 : } 181 : 182 : /************************************************************************/ 183 : /* AddFieldDefn() */ 184 : /************************************************************************/ 185 : 186 0 : void OGREDIGEOLayer::AddFieldDefn(const CPLString &osName, OGRFieldType eType, 187 : const CPLString &osRID) 188 : { 189 0 : if (!osRID.empty()) 190 0 : mapAttributeToIndex[osRID] = poFeatureDefn->GetFieldCount(); 191 : 192 0 : OGRFieldDefn oFieldDefn(osName, eType); 193 0 : poFeatureDefn->AddFieldDefn(&oFieldDefn); 194 0 : }