32#include "gdal/cpl_conv.h"
33#include "gdal/cpl_string.h"
43 int nFeatureCountIn,
int nOBJLIn)
50 nFeatureCount = nFeatureCountIn;
52 poFeatureDefn = poDefnIn;
59 if (EQUAL(poDefnIn->GetName(), OGRN_VI))
61 else if (EQUAL(poDefnIn->GetName(), OGRN_VC))
63 else if (EQUAL(poDefnIn->GetName(), OGRN_VE))
65 else if (EQUAL(poDefnIn->GetName(), OGRN_VF))
75OGRS57Layer::~OGRS57Layer()
80 if (poFilterGeom != NULL)
delete poFilterGeom;
87void OGRS57Layer::SetSpatialFilter(OGRGeometry *poGeomIn)
90 if (poFilterGeom != NULL) {
95 if (poGeomIn != NULL) poFilterGeom = poGeomIn->clone();
97 if (nNextFEIndex != 0 || nCurrentModule != -1) ResetReading();
104void OGRS57Layer::ResetReading()
115OGRFeature *OGRS57Layer::GetNextUnfilteredFeature()
118 OGRFeature *poFeature = NULL;
123 if (nCurrentModule >= poDS->GetModuleCount())
return NULL;
129 S57Reader *poReader = poDS->GetModule(nCurrentModule);
131 if (poReader != NULL) {
132 poReader->SetNextFEIndex(nNextFEIndex, nRCNM);
133 poFeature = poReader->ReadNextFeature(poFeatureDefn);
134 nNextFEIndex = poReader->GetNextFEIndex(nRCNM);
140 if (poFeature == NULL) {
142 poReader = poDS->GetModule(nCurrentModule);
144 if (poReader != NULL && poReader->GetModule() == NULL) {
145 if (!poReader->Open(FALSE))
return NULL;
148 return GetNextUnfilteredFeature();
150 if (poFeature->GetGeometryRef() != NULL)
151 poFeature->GetGeometryRef()->assignSpatialReference(GetSpatialRef());
161OGRFeature *OGRS57Layer::GetNextFeature()
164 OGRFeature *poFeature = NULL;
171 poFeature = GetNextUnfilteredFeature();
172 if (poFeature == NULL)
break;
191int OGRS57Layer::TestCapability(
const char *pszCap)
194 if (EQUAL(pszCap, OLCRandomRead))
197 else if (EQUAL(pszCap, OLCSequentialWrite))
200 else if (EQUAL(pszCap, OLCRandomWrite))
203 else if (EQUAL(pszCap, OLCFastFeatureCount))
206 else if (EQUAL(pszCap, OLCFastGetExtent)) {
207 OGREnvelope oEnvelope;
209 return GetExtent(&oEnvelope, FALSE) == OGRERR_NONE;
210 }
else if (EQUAL(pszCap, OLCFastSpatialFilter))
221OGRSpatialReference *OGRS57Layer::GetSpatialRef()
224 return poDS->GetSpatialRef();
231OGRErr OGRS57Layer::GetExtent(OGREnvelope *psExtent,
int bForce)
234 return poDS->GetDSExtent(psExtent, bForce);
240int OGRS57Layer::GetFeatureCount(
int bForce) {
241 if (poFilterGeom != NULL
242 || nFeatureCount == -1)
243 return OGRLayer::GetFeatureCount(bForce);
245 return nFeatureCount;
252OGRFeature *OGRS57Layer::GetFeature(
long nFeatureId)
255 S57Reader *poReader = poDS->GetModule(0);
257 if (poReader != NULL) {
258 OGRFeature *poFeature;
260 poFeature = poReader->ReadFeature(nFeatureId, poFeatureDefn);
261 if (poFeature != NULL && poFeature->GetGeometryRef() != NULL)
262 poFeature->GetGeometryRef()->assignSpatialReference(GetSpatialRef());
272OGRErr OGRS57Layer::CreateFeature(OGRFeature *poFeature)
278 int iRCNMFld = poFeature->GetFieldIndex(
"RCNM");
280 if (iRCNMFld != -1) {
281 if (!poFeature->IsFieldSet(iRCNMFld)) {
282 poFeature->SetField(iRCNMFld, nRCNM);
284 CPLAssert(poFeature->GetFieldAsInteger(iRCNMFld) == nRCNM);
292 int iOBJLFld = poFeature->GetFieldIndex(
"OBJL");
294 if (!poFeature->IsFieldSet(iOBJLFld)) {
295 poFeature->SetField(iOBJLFld, nOBJL);
297 CPLAssert(poFeature->GetFieldAsInteger(iOBJLFld) == nOBJL);
307 return OGRERR_FAILURE;