OpenCPN Partial API docs
Loading...
Searching...
No Matches
ogrs57layer.cpp
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * Project: S-57 Translator
4 * Purpose: Implements OGRS57Layer class.
5 * Author: Frank Warmerdam, warmerdam@pobox.com
6 *
7 ******************************************************************************
8 * Copyright (c) 1999, Frank Warmerdam warmerdam@pobox.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
34#include "ogr_s57.h"
35#include "gdal/cpl_conv.h"
36#include "gdal/cpl_string.h"
37
38/************************************************************************/
39/* OGRS57Layer() */
40/* */
41/* Note that the OGRS57Layer assumes ownership of the passed */
42/* OGRFeatureDefn object. */
43/************************************************************************/
44
45OGRS57Layer::OGRS57Layer(OGRS57DataSource *poDSIn, OGRFeatureDefn *poDefnIn,
46 int nFeatureCountIn, int nOBJLIn)
47
48{
49 poFilterGeom = NULL;
50
51 poDS = poDSIn;
52
53 nFeatureCount = nFeatureCountIn;
54
55 poFeatureDefn = poDefnIn;
56
57 nOBJL = nOBJLIn;
58
59 nNextFEIndex = 0;
60 nCurrentModule = -1;
61
62 if (EQUAL(poDefnIn->GetName(), OGRN_VI))
63 nRCNM = RCNM_VI;
64 else if (EQUAL(poDefnIn->GetName(), OGRN_VC))
65 nRCNM = RCNM_VC;
66 else if (EQUAL(poDefnIn->GetName(), OGRN_VE))
67 nRCNM = RCNM_VE;
68 else if (EQUAL(poDefnIn->GetName(), OGRN_VF))
69 nRCNM = RCNM_VF;
70 else
71 nRCNM = 100; /* feature */
72}
73
74/************************************************************************/
75/* ~OGRS57Layer() */
76/************************************************************************/
77
78OGRS57Layer::~OGRS57Layer()
79
80{
81 delete poFeatureDefn;
82
83 if (poFilterGeom != NULL) delete poFilterGeom;
84}
85
86/************************************************************************/
87/* SetSpatialFilter() */
88/************************************************************************/
89
90void OGRS57Layer::SetSpatialFilter(OGRGeometry *poGeomIn)
91
92{
93 if (poFilterGeom != NULL) {
94 delete poFilterGeom;
95 poFilterGeom = NULL;
96 }
97
98 if (poGeomIn != NULL) poFilterGeom = poGeomIn->clone();
99
100 if (nNextFEIndex != 0 || nCurrentModule != -1) ResetReading();
101}
102
103/************************************************************************/
104/* ResetReading() */
105/************************************************************************/
106
107void OGRS57Layer::ResetReading()
108
109{
110 nNextFEIndex = 0;
111 nCurrentModule = -1;
112}
113
114/************************************************************************/
115/* GetNextUnfilteredFeature() */
116/************************************************************************/
117
118OGRFeature *OGRS57Layer::GetNextUnfilteredFeature()
119
120{
121 OGRFeature *poFeature = NULL;
122
123 /* -------------------------------------------------------------------- */
124 /* Are we out of modules to request features from? */
125 /* -------------------------------------------------------------------- */
126 if (nCurrentModule >= poDS->GetModuleCount()) return NULL;
127
128 /* -------------------------------------------------------------------- */
129 /* Set the current position on the current module and fetch a */
130 /* feature. */
131 /* -------------------------------------------------------------------- */
132 S57Reader *poReader = poDS->GetModule(nCurrentModule);
133
134 if (poReader != NULL) {
135 poReader->SetNextFEIndex(nNextFEIndex, nRCNM);
136 poFeature = poReader->ReadNextFeature(poFeatureDefn);
137 nNextFEIndex = poReader->GetNextFEIndex(nRCNM);
138 }
139
140 /* -------------------------------------------------------------------- */
141 /* If we didn't get a feature we need to move onto the next file. */
142 /* -------------------------------------------------------------------- */
143 if (poFeature == NULL) {
144 nCurrentModule++;
145 poReader = poDS->GetModule(nCurrentModule);
146
147 if (poReader != NULL && poReader->GetModule() == NULL) {
148 if (!poReader->Open(FALSE)) return NULL;
149 }
150
151 return GetNextUnfilteredFeature();
152 } else {
153 if (poFeature->GetGeometryRef() != NULL)
154 poFeature->GetGeometryRef()->assignSpatialReference(GetSpatialRef());
155 }
156
157 return poFeature;
158}
159
160/************************************************************************/
161/* GetNextFeature() */
162/************************************************************************/
163
164OGRFeature *OGRS57Layer::GetNextFeature()
165
166{
167 OGRFeature *poFeature = NULL;
168
169 /* -------------------------------------------------------------------- */
170 /* Read features till we find one that satisfies our current */
171 /* spatial criteria. */
172 /* -------------------------------------------------------------------- */
173 while (TRUE) {
174 poFeature = GetNextUnfilteredFeature();
175 if (poFeature == NULL) break;
176 /*
177 if( (poFilterGeom == NULL
178 || poFeature->GetGeometryRef() == NULL
179 || poFilterGeom->Intersect( poFeature->GetGeometryRef() ) )
180 && (m_poAttrQuery == NULL
181 || m_poAttrQuery->Evaluate( poFeature )) )
182 break;
183 */
184 delete poFeature;
185 }
186
187 return poFeature;
188}
189
190/************************************************************************/
191/* TestCapability() */
192/************************************************************************/
193
194int OGRS57Layer::TestCapability(const char *pszCap)
195
196{
197 if (EQUAL(pszCap, OLCRandomRead))
198 return FALSE;
199
200 else if (EQUAL(pszCap, OLCSequentialWrite))
201 return TRUE;
202
203 else if (EQUAL(pszCap, OLCRandomWrite))
204 return FALSE;
205
206 else if (EQUAL(pszCap, OLCFastFeatureCount))
207 return TRUE;
208
209 else if (EQUAL(pszCap, OLCFastGetExtent)) {
210 OGREnvelope oEnvelope;
211
212 return GetExtent(&oEnvelope, FALSE) == OGRERR_NONE;
213 } else if (EQUAL(pszCap, OLCFastSpatialFilter))
214 return FALSE;
215
216 else
217 return FALSE;
218}
219
220/************************************************************************/
221/* GetSpatialRef() */
222/************************************************************************/
223
224OGRSpatialReference *OGRS57Layer::GetSpatialRef()
225
226{
227 return poDS->GetSpatialRef();
228}
229
230/************************************************************************/
231/* GetExtent() */
232/************************************************************************/
233
234OGRErr OGRS57Layer::GetExtent(OGREnvelope *psExtent, int bForce)
235
236{
237 return poDS->GetDSExtent(psExtent, bForce);
238}
239
240/************************************************************************/
241/* GetFeatureCount() */
242/************************************************************************/
243int OGRS57Layer::GetFeatureCount(int bForce) {
244 if (poFilterGeom != NULL /*|| m_poAttrQuery != NULL*/
245 || nFeatureCount == -1)
246 return OGRLayer::GetFeatureCount(bForce);
247 else
248 return nFeatureCount;
249}
250
251/************************************************************************/
252/* GetFeature() */
253/************************************************************************/
254
255OGRFeature *OGRS57Layer::GetFeature(long nFeatureId)
256
257{
258 S57Reader *poReader = poDS->GetModule(0); // not multi-reader aware
259
260 if (poReader != NULL) {
261 OGRFeature *poFeature;
262
263 poFeature = poReader->ReadFeature(nFeatureId, poFeatureDefn);
264 if (poFeature != NULL && poFeature->GetGeometryRef() != NULL)
265 poFeature->GetGeometryRef()->assignSpatialReference(GetSpatialRef());
266 return poFeature;
267 } else
268 return NULL;
269}
270
271/************************************************************************/
272/* CreateFeature() */
273/************************************************************************/
274
275OGRErr OGRS57Layer::CreateFeature(OGRFeature *poFeature)
276
277{
278 /* -------------------------------------------------------------------- */
279 /* Set RCNM if not already set. */
280 /* -------------------------------------------------------------------- */
281 int iRCNMFld = poFeature->GetFieldIndex("RCNM");
282
283 if (iRCNMFld != -1) {
284 if (!poFeature->IsFieldSet(iRCNMFld)) {
285 poFeature->SetField(iRCNMFld, nRCNM);
286 } else {
287 CPLAssert(poFeature->GetFieldAsInteger(iRCNMFld) == nRCNM);
288 }
289 }
290
291 /* -------------------------------------------------------------------- */
292 /* Set OBJL if not already set. */
293 /* -------------------------------------------------------------------- */
294 if (nOBJL != -1) {
295 int iOBJLFld = poFeature->GetFieldIndex("OBJL");
296
297 if (!poFeature->IsFieldSet(iOBJLFld)) {
298 poFeature->SetField(iOBJLFld, nOBJL);
299 } else {
300 CPLAssert(poFeature->GetFieldAsInteger(iOBJLFld) == nOBJL);
301 }
302 }
303
304 /* -------------------------------------------------------------------- */
305 /* Create the isolated node feature. */
306 /* -------------------------------------------------------------------- */
307 // if( poDS->GetWriter()->WriteCompleteFeature( poFeature ) )
308 // return OGRERR_NONE;
309 // else
310 return OGRERR_FAILURE;
311}
Declarations for classes binding S57 support onto OGRLayer, OGRDataSource and OGRDriver.