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