OGRFeature* OGRUnionLayer::TranslateFromSrcLayer(OGRFeature* poSrcFeature) { CPLAssert(panMap != NULL); CPLAssert(iCurLayer >= 0 && iCurLayer < nSrcLayers); OGRFeature* poFeature = new OGRFeature(poFeatureDefn); poFeature->SetFrom(poSrcFeature, panMap, TRUE); if( osSourceLayerFieldName.size() && !poFeatureDefn->GetFieldDefn(0)->IsIgnored() ) { poFeature->SetField(0, papoSrcLayers[iCurLayer]->GetName()); } for(int i=0;i<poFeatureDefn->GetGeomFieldCount();i++) { if( poFeatureDefn->GetGeomFieldDefn(i)->IsIgnored() ) poFeature->SetGeomFieldDirectly(i, NULL); else { OGRGeometry* poGeom = poFeature->GetGeomFieldRef(i); if( poGeom != NULL ) { poGeom->assignSpatialReference( poFeatureDefn->GetGeomFieldDefn(i)->GetSpatialRef()); } } } if( bPreserveSrcFID ) poFeature->SetFID(poSrcFeature->GetFID()); else poFeature->SetFID(nNextFID ++); return poFeature; }
OGRFeature* GTMWaypointLayer::GetNextFeature() { if( bError ) return nullptr; while (poDS->hasNextWaypoint()) { Waypoint* poWaypoint = poDS->fetchNextWaypoint(); if (poWaypoint == nullptr) { CPLError(CE_Failure, CPLE_AppDefined, "Could not read waypoint. File probably corrupted"); bError = true; return nullptr; } OGRFeature* poFeature = new OGRFeature( poFeatureDefn ); double altitude = poWaypoint->getAltitude(); if (altitude == 0.0) poFeature->SetGeometryDirectly(new OGRPoint (poWaypoint->getLongitude(), poWaypoint->getLatitude())); else poFeature->SetGeometryDirectly(new OGRPoint (poWaypoint->getLongitude(), poWaypoint->getLatitude(), altitude)); if (poSRS) poFeature->GetGeometryRef()->assignSpatialReference(poSRS); poFeature->SetField( NAME, poWaypoint->getName()); poFeature->SetField( COMMENT, poWaypoint->getComment()); poFeature->SetField( ICON, poWaypoint->getIcon()); GIntBig wptdate = poWaypoint->getDate(); if (wptdate != 0) { struct tm brokendownTime; CPLUnixTimeToYMDHMS(wptdate, &brokendownTime); poFeature->SetField( DATE, brokendownTime.tm_year + 1900, brokendownTime.tm_mon + 1, brokendownTime.tm_mday, brokendownTime.tm_hour, brokendownTime.tm_min, static_cast<float>(brokendownTime.tm_sec)); } poFeature->SetFID( nNextFID++ ); delete poWaypoint; if( (m_poFilterGeom == nullptr || FilterGeometry( poFeature->GetGeometryRef() ) ) && (m_poAttrQuery == nullptr || m_poAttrQuery->Evaluate( poFeature )) ) return poFeature; delete poFeature; } return nullptr; }
OGRFeature *OGRFMELayerCached::ReadNextIndexFeature() { OGRFeature *poOGRFeature = NULL; FME_Boolean endOfQuery; if( poIndex == NULL ) return NULL; if( !bQueryActive ) ResetReading(); poDS->AcquireSession(); if( poIndex->fetch( *poFMEFeature, endOfQuery ) == 0 && !endOfQuery ) { poOGRFeature = poDS->ProcessFeature( this, poFMEFeature ); if( poOGRFeature != NULL ) { poOGRFeature->SetFID( ++nPreviousFeature ); m_nFeaturesRead++; } } poDS->ReleaseSession(); return poOGRFeature; }
OGRFeature *OGRLIBKMLLayer::GetNextRawFeature ( ) { FeaturePtr poKmlFeature; OGRFeature *poOgrFeature = NULL; do { if ( iFeature >= nFeatures ) break; poKmlFeature = m_poKmlLayer->get_feature_array_at ( iFeature++ ); } while ( poKmlFeature->Type ( ) != kmldom::Type_Placemark ); if ( iFeature <= nFeatures && poKmlFeature && poKmlFeature->Type ( ) == kmldom::Type_Placemark ) { poOgrFeature = kml2feat ( AsPlacemark ( poKmlFeature ), m_poOgrDS, this, m_poOgrFeatureDefn, m_poOgrSRS ); poOgrFeature->SetFID(nFID ++); } return poOgrFeature; }
void OGRGeoJSONLayer::AddFeature( OGRFeature* poFeature ) { CPLAssert( NULL != poFeature ); // NOTE - mloskot: // Features may not be sorted according to FID values. // TODO: Should we check if feature already exists? // TODO: Think about sync operation, upload, etc. OGRFeature* poNewFeature = NULL; poNewFeature = poFeature->Clone(); if( -1 == poNewFeature->GetFID() ) { int nFID = static_cast<int>(seqFeatures_.size()); poNewFeature->SetFID( nFID ); // TODO - mlokot: We need to redesign creation of FID column int nField = poNewFeature->GetFieldIndex( DefaultFIDColumn ); if( -1 != nField && GetLayerDefn()->GetFieldDefn(nField)->GetType() == OFTInteger ) { poNewFeature->SetField( nField, nFID ); } } seqFeatures_.push_back( poNewFeature ); }
OGRFeature *OGROpenAirLabelLayer::GetNextRawFeature() { const char* pszLine; double dfLat = 0, dfLon = 0; int bHasCoord = FALSE; while(TRUE) { pszLine = CPLReadLine2L(fpOpenAir, 1024, NULL); if (pszLine == NULL) return NULL; if (pszLine[0] == '*' || pszLine[0] == '\0') continue; if (EQUALN(pszLine, "AC ", 3)) { if (osCLASS.size() != 0) { osNAME = ""; osCEILING = ""; osFLOOR = ""; } osCLASS = pszLine + 3; } else if (EQUALN(pszLine, "AN ", 3)) osNAME = pszLine + 3; else if (EQUALN(pszLine, "AH ", 3)) osCEILING = pszLine + 3; else if (EQUALN(pszLine, "AL ", 3)) osFLOOR = pszLine + 3; else if (EQUALN(pszLine, "AT ", 3)) { bHasCoord = OGROpenAirGetLatLon(pszLine + 3, dfLat, dfLon); break; } } OGRFeature* poFeature = new OGRFeature(poFeatureDefn); poFeature->SetField(0, osCLASS.c_str()); poFeature->SetField(1, osNAME.c_str()); poFeature->SetField(2, osFLOOR.c_str()); poFeature->SetField(3, osCEILING.c_str()); CPLString osStyle; osStyle.Printf("LABEL(t:\"%s\")", osNAME.c_str()); poFeature->SetStyleString(osStyle.c_str()); if (bHasCoord) { OGRPoint* poPoint = new OGRPoint(dfLon, dfLat); poPoint->assignSpatialReference(poSRS); poFeature->SetGeometryDirectly(poPoint); } poFeature->SetFID(nNextFID++); return poFeature; }
OGRFeature *OGRKMLLayer::GetNextFeature() { #ifndef HAVE_EXPAT return NULL; #else /* -------------------------------------------------------------------- */ /* Loop till we find a feature matching our criteria. */ /* -------------------------------------------------------------------- */ KML *poKMLFile = poDS_->GetKMLFile(); if( poKMLFile == NULL ) return NULL; poKMLFile->selectLayer(nLayerNumber_); while( true ) { Feature *poFeatureKML = NULL; poFeatureKML = poKMLFile->getFeature(iNextKMLId_++, nLastAsked, nLastCount); if(poFeatureKML == NULL) return NULL; CPLAssert( poFeatureKML != NULL ); OGRFeature *poFeature = new OGRFeature( poFeatureDefn_ ); if(poFeatureKML->poGeom) { poFeature->SetGeometryDirectly(poFeatureKML->poGeom); poFeatureKML->poGeom = NULL; } // Add fields poFeature->SetField( poFeatureDefn_->GetFieldIndex("Name"), poFeatureKML->sName.c_str() ); poFeature->SetField( poFeatureDefn_->GetFieldIndex("Description"), poFeatureKML->sDescription.c_str() ); poFeature->SetFID( iNextKMLId_ - 1 ); // Clean up delete poFeatureKML; if( poFeature->GetGeometryRef() != NULL && poSRS_ != NULL) { poFeature->GetGeometryRef()->assignSpatialReference( poSRS_ ); } /* Check spatial/attribute filters */ if ((m_poFilterGeom == NULL || FilterGeometry( poFeature->GetGeometryRef() ) ) && (m_poAttrQuery == NULL || m_poAttrQuery->Evaluate( poFeature )) ) { // Return the feature return poFeature; } else { delete poFeature; } } #endif /* HAVE_EXPAT */ }
OGRFeature *OGRSEGUKOOALineLayer::GetNextRawFeature() { if( bEOF ) return nullptr; /* Merge points of base layer that have same value for attribute(0) */ /* into a single linestring */ OGRFeature* poFeature = nullptr; OGRLineString* poLS = nullptr; if (poNextBaseFeature == nullptr) poNextBaseFeature = poBaseLayer->GetNextFeature(); while(poNextBaseFeature != nullptr) { if (poNextBaseFeature->IsFieldSetAndNotNull(0) && poNextBaseFeature->GetFieldAsString(0)[0] != '\0') { if (poFeature != nullptr && strcmp(poFeature->GetFieldAsString(0), poNextBaseFeature->GetFieldAsString(0)) != 0) { poFeature->SetGeometryDirectly(poLS); return poFeature; } OGRGeometry* poGeom = poNextBaseFeature->GetGeometryRef(); OGRPoint* poPoint = poGeom ? poGeom->toPoint(): nullptr; if (poPoint != nullptr) { if (poFeature == nullptr) { poFeature = new OGRFeature(poFeatureDefn); poFeature->SetFID(nNextFID ++); poFeature->SetField(0, poNextBaseFeature->GetFieldAsString(0)); poLS = new OGRLineString(); if (poBaseLayer->GetSpatialRef()) poLS->assignSpatialReference( poBaseLayer->GetSpatialRef()); } poLS->addPoint(poPoint); } } delete poNextBaseFeature; poNextBaseFeature = poBaseLayer->GetNextFeature(); } bEOF = true; if( poFeature ) poFeature->SetGeometryDirectly(poLS); return poFeature; }
OGRErr OGRLayerWithTransaction::ISetFeature( OGRFeature *poFeature ) { if( !m_poDecoratedLayer ) return OGRERR_FAILURE; OGRFeature* poSrcFeature = new OGRFeature(m_poDecoratedLayer->GetLayerDefn()); poSrcFeature->SetFrom(poFeature); poSrcFeature->SetFID(poFeature->GetFID()); OGRErr eErr = m_poDecoratedLayer->SetFeature(poSrcFeature); delete poSrcFeature; return eErr; }
OGRFeature *OGRSEGUKOOALineLayer::GetNextRawFeature() { if (bEOF) return NULL; /* Merge points of base layer that have same value for attribute(0) */ /* into a single linestring */ OGRFeature* poFeature = NULL; OGRLineString* poLS = NULL; if (poNextBaseFeature == NULL) poNextBaseFeature = poBaseLayer->GetNextFeature(); while(poNextBaseFeature != NULL) { if (poNextBaseFeature->IsFieldSet(0) && poNextBaseFeature->GetFieldAsString(0)[0] != '\0') { if (poFeature != NULL && strcmp(poFeature->GetFieldAsString(0), poNextBaseFeature->GetFieldAsString(0)) != 0) { return poFeature; } OGRPoint* poPoint = (OGRPoint*) poNextBaseFeature->GetGeometryRef(); if (poPoint != NULL) { if (poFeature == NULL) { poFeature = new OGRFeature(poFeatureDefn); poFeature->SetFID(nNextFID ++); poFeature->SetField(0, poNextBaseFeature->GetFieldAsString(0)); poLS = new OGRLineString(); if (poBaseLayer->GetSpatialRef()) poLS->assignSpatialReference( poBaseLayer->GetSpatialRef()); poFeature->SetGeometryDirectly(poLS); } poLS->addPoint(poPoint); } } delete poNextBaseFeature; poNextBaseFeature = poBaseLayer->GetNextFeature(); } bEOF = TRUE; return poFeature; }
OGRFeature * OGRFGdbSingleFeatureLayer::GetNextFeature() { if (iNextShapeId != 0) return NULL; OGRFeature* poFeature = new OGRFeature(poFeatureDefn); if (pszVal) poFeature->SetField(0, pszVal); poFeature->SetFID(iNextShapeId ++); return poFeature; }
OGRFeature* OGRESRIFeatureServiceLayer::GetNextFeature() { while( TRUE ) { int bWasInFirstPage = !bOtherPage; OGRFeature* poSrcFeat = poDS->GetUnderlyingLayer()->GetNextFeature(); if( poSrcFeat == NULL ) { if( !poDS->LoadNextPage() ) return NULL; poSrcFeat = poDS->GetUnderlyingLayer()->GetNextFeature(); if( poSrcFeat == NULL ) return NULL; bOtherPage = TRUE; } if( bOtherPage && bWasInFirstPage && poSrcFeat->GetFID() == 0 && nLastFID == nFeaturesRead - 1 ) { bUseSequentialFID = TRUE; } OGRFeature* poFeature = new OGRFeature(poFeatureDefn); poFeature->SetFrom(poSrcFeat); if( bUseSequentialFID ) poFeature->SetFID(nFeaturesRead); else poFeature->SetFID(poSrcFeat->GetFID()); nLastFID = poFeature->GetFID(); nFeaturesRead ++; delete poSrcFeat; if((m_poFilterGeom == NULL || FilterGeometry( poFeature->GetGeometryRef() ) ) && (m_poAttrQuery == NULL || m_poAttrQuery->Evaluate( poFeature )) ) { return poFeature; } delete poFeature; } }
OGRFeature *OGRLIBKMLLayer::GetNextRawFeature ( ) { FeaturePtr poKmlFeature; OGRFeature *poOgrFeature = NULL; if( m_poKmlLayer == NULL ) return NULL; /***** loop over the kml features to find the next placemark *****/ do { if ( iFeature >= nFeatures ) break; /***** get the next kml feature in the container *****/ poKmlFeature = m_poKmlLayer->get_feature_array_at ( iFeature++ ); /***** what type of kml feature in the container? *****/ switch (poKmlFeature->Type ( )) { case kmldom::Type_Placemark: poOgrFeature = kml2feat ( AsPlacemark ( poKmlFeature ), m_poOgrDS, this, m_poOgrFeatureDefn, m_poOgrSRS ); break; case kmldom::Type_GroundOverlay: if (m_bReadGroundOverlay) { poOgrFeature = kmlgroundoverlay2feat ( AsGroundOverlay ( poKmlFeature ), m_poOgrDS, this, m_poOgrFeatureDefn, m_poOgrSRS ); } break; default: break; } } while ( !poOgrFeature ); /***** set the FID on the ogr feature *****/ if (poOgrFeature) poOgrFeature->SetFID(nFID ++); return poOgrFeature; }
OGRFeature * OGRLayerWithTransaction::GetFeature( GIntBig nFID ) { if( !m_poDecoratedLayer ) return NULL; OGRFeature* poSrcFeature = m_poDecoratedLayer->GetFeature(nFID); if( !poSrcFeature ) return NULL; OGRFeature* poFeature = new OGRFeature(GetLayerDefn()); poFeature->SetFrom(poSrcFeature); poFeature->SetFID(poSrcFeature->GetFID()); delete poSrcFeature; return poFeature; }
OGRErr OGRUnionLayer::ISetFeature( OGRFeature* poFeature ) { if( !bPreserveSrcFID ) { CPLError(CE_Failure, CPLE_NotSupported, "SetFeature() not supported when PreserveSrcFID is OFF"); return OGRERR_FAILURE; } if( osSourceLayerFieldName.size() == 0 ) { CPLError(CE_Failure, CPLE_NotSupported, "SetFeature() not supported when SourceLayerFieldName is not set"); return OGRERR_FAILURE; } if( poFeature->GetFID() == OGRNullFID ) { CPLError(CE_Failure, CPLE_NotSupported, "SetFeature() not supported when FID is not set"); return OGRERR_FAILURE; } if( !poFeature->IsFieldSet(0) ) { CPLError(CE_Failure, CPLE_NotSupported, "SetFeature() not supported when '%s' field is not set", osSourceLayerFieldName.c_str()); return OGRERR_FAILURE; } const char* pszSrcLayerName = poFeature->GetFieldAsString(0); for(int i=0;i<nSrcLayers;i++) { if( strcmp(pszSrcLayerName, papoSrcLayers[i]->GetName()) == 0) { pabModifiedLayers[i] = TRUE; OGRFeature* poSrcFeature = new OGRFeature(papoSrcLayers[i]->GetLayerDefn()); poSrcFeature->SetFrom(poFeature, TRUE); poSrcFeature->SetFID(poFeature->GetFID()); OGRErr eErr = papoSrcLayers[i]->SetFeature(poSrcFeature); delete poSrcFeature; return eErr; } } CPLError(CE_Failure, CPLE_NotSupported, "SetFeature() not supported : '%s' source layer does not exist", pszSrcLayerName); return OGRERR_FAILURE; }
OGRFeature *OGRAeronavFAANAVAIDLayer::GetNextRawFeature() { char szBuffer[134]; while( true ) { const char* pszLine = CPLReadLine2L(fpAeronavFAA, 134, nullptr); if (pszLine == nullptr) { bEOF = true; return nullptr; } if (strlen(pszLine) != 132) continue; if ( !(pszLine[psRecordDesc->nLatStartCol-1] == 'N' || pszLine[psRecordDesc->nLatStartCol-1] == 'S') ) continue; if ( !(pszLine[psRecordDesc->nLonStartCol-1] == 'E' || pszLine[psRecordDesc->nLonStartCol-1] == 'W') ) continue; OGRFeature* poFeature = new OGRFeature(poFeatureDefn); poFeature->SetFID(nNextFID ++); for( int i=0; i < psRecordDesc->nFields; i++ ) { int nWidth = psRecordDesc->pasFields[i].nLastCol - psRecordDesc->pasFields[i].nStartCol + 1; strncpy(szBuffer, pszLine + psRecordDesc->pasFields[i].nStartCol - 1, nWidth); szBuffer[nWidth] = 0; while(nWidth > 0 && szBuffer[nWidth - 1] == ' ') { szBuffer[nWidth - 1] = 0; nWidth --; } if (nWidth != 0) poFeature->SetField(i, szBuffer); } double dfLat = 0.0; double dfLon = 0.0; GetLatLon(pszLine + psRecordDesc->nLatStartCol - 1, pszLine + psRecordDesc->nLonStartCol - 1, dfLat, dfLon); OGRGeometry* poGeom = new OGRPoint(dfLon, dfLat); poGeom->assignSpatialReference(poSRS); poFeature->SetGeometryDirectly( poGeom ); return poFeature; } }
OGRFeature *OGRNASRelationLayer::GetNextFeature() { if( !bPopulated ) poDS->PopulateRelations(); /* ==================================================================== */ /* Loop till we find and translate a feature meeting all our */ /* requirements. */ /* ==================================================================== */ while( TRUE ) { // out of features? if( iNextFeature >= (int) aoRelationCollection.size() ) return NULL; /* -------------------------------------------------------------------- */ /* The from/type/to values are stored in a packed string with */ /* \0 separators for compactness. Split out components. */ /* -------------------------------------------------------------------- */ const char *pszFromID, *pszType, *pszToID; pszFromID = aoRelationCollection[iNextFeature].c_str(); pszType = pszFromID + strlen(pszFromID) + 1; pszToID = pszType + strlen(pszType) + 1; m_nFeaturesRead++; /* -------------------------------------------------------------------- */ /* Translate values into an OGRFeature. */ /* -------------------------------------------------------------------- */ OGRFeature *poFeature = new OGRFeature( poFeatureDefn ); poFeature->SetField( 0, pszFromID ); poFeature->SetField( 1, pszType ); poFeature->SetField( 2, pszToID ); poFeature->SetFID( iNextFeature++ ); /* -------------------------------------------------------------------- */ /* Test against the attribute query. */ /* -------------------------------------------------------------------- */ if( m_poAttrQuery != NULL && !m_poAttrQuery->Evaluate( poFeature ) ) delete poFeature; else return poFeature; } return NULL; }
/*! \brief Get feature (private) \return pointer to OGRFeature \return NULL not found */ OGRFeature *OGRVFKLayer::GetFeature(VFKFeature *poVFKFeature) { OGRGeometry *poGeom; /* skip feature with unknown geometry type */ if (poVFKFeature->GetGeometryType() == wkbUnknown) return NULL; /* get features geometry */ poGeom = CreateGeometry(poVFKFeature); if (poGeom != NULL) poGeom->assignSpatialReference(poSRS); /* does it satisfy the spatial query, if there is one? */ if (m_poFilterGeom != NULL && poGeom && !FilterGeometry(poGeom)) { return NULL; } /* convert the whole feature into an OGRFeature */ OGRFeature *poOGRFeature = new OGRFeature(GetLayerDefn()); poOGRFeature->SetFID(poVFKFeature->GetFID()); // poOGRFeature->SetFID(++m_iNextFeature); for (int iField = 0; iField < poDataBlock->GetPropertyCount(); iField++) { if (poVFKFeature->GetProperty(iField)->IsNull()) continue; OGRFieldType fType = poOGRFeature->GetDefnRef()->GetFieldDefn(iField)->GetType(); if (fType == OFTInteger) poOGRFeature->SetField(iField, poVFKFeature->GetProperty(iField)->GetValueI()); else if (fType == OFTReal) poOGRFeature->SetField(iField, poVFKFeature->GetProperty(iField)->GetValueD()); else poOGRFeature->SetField(iField, poVFKFeature->GetProperty(iField)->GetValueS()); } /* test against the attribute query */ if (m_poAttrQuery != NULL && !m_poAttrQuery->Evaluate(poOGRFeature)) { delete poOGRFeature; return NULL; } if (poGeom) poOGRFeature->SetGeometryDirectly(poGeom->clone()); return poOGRFeature; }
OGRFeature *OGRXLSLayer::GetNextRawFeature() { if (nNextFID == nRows) return nullptr; const void* xlshandle = poDS->GetXLSHandle(); if (xlshandle == nullptr) return nullptr; freexl_select_active_worksheet(xlshandle, (unsigned short)iSheet); OGRFeature* poFeature = new OGRFeature(poFeatureDefn); FreeXL_CellValue sCellValue; for(unsigned short i=0;i<(unsigned short )poFeatureDefn->GetFieldCount(); i++) { if (freexl_get_cell_value(xlshandle, nNextFID, i, &sCellValue) == FREEXL_OK) { switch (sCellValue.type) { case FREEXL_CELL_INT: poFeature->SetField(i, sCellValue.value.int_value); break; case FREEXL_CELL_DOUBLE: poFeature->SetField(i, sCellValue.value.double_value); break; case FREEXL_CELL_TEXT: case FREEXL_CELL_SST_TEXT: poFeature->SetField(i, sCellValue.value.text_value); break; case FREEXL_CELL_DATE: case FREEXL_CELL_DATETIME: case FREEXL_CELL_TIME: poFeature->SetField(i, sCellValue.value.text_value); break; case FREEXL_CELL_NULL: break; default: CPLDebug("XLS", "Unknown cell type = %d", sCellValue.type); break; } } } poFeature->SetFID(nNextFID + 1); nNextFID ++; return poFeature; }
OGRFeature* OGRGeoJSONSeqLayer::GetNextFeature() { while( true ) { auto poObject = GetNextObject(); if( !poObject ) return nullptr; OGRFeature* poFeature; auto type = OGRGeoJSONGetType(poObject); if( type == GeoJSONObject::eFeature ) { poFeature = m_oReader.ReadFeature( this, poObject, m_osFeatureBuffer.c_str() ); json_object_put(poObject); } else if( type == GeoJSONObject::eFeatureCollection || type == GeoJSONObject::eUnknown ) { json_object_put(poObject); continue; } else { OGRGeometry* poGeom = m_oReader.ReadGeometry(poObject, GetSpatialRef()); json_object_put(poObject); if( !poGeom ) { continue; } poFeature = new OGRFeature(m_poFeatureDefn); poFeature->SetGeometryDirectly(poGeom); } if( poFeature->GetFID() == OGRNullFID ) { poFeature->SetFID(m_nNextFID); m_nNextFID ++; } if( (m_poFilterGeom == nullptr || FilterGeometry(poFeature->GetGeomFieldRef(m_iGeomFieldFilter)) ) && (m_poAttrQuery == nullptr || m_poAttrQuery->Evaluate(poFeature)) ) { return poFeature; } delete poFeature; } }
OGRFeature *OGRTigerLayer::GetFeature( GIntBig nFeatureId ) { if( nFeatureId < 1 || nFeatureId > nFeatureCount ) return NULL; /* -------------------------------------------------------------------- */ /* If we don't have the current module open for the requested */ /* data, then open it now. */ /* -------------------------------------------------------------------- */ if( iLastModule == -1 || nFeatureId <= panModuleOffset[iLastModule] || nFeatureId > panModuleOffset[iLastModule+1] ) { for( iLastModule = 0; iLastModule < poDS->GetModuleCount() && nFeatureId > panModuleOffset[iLastModule+1]; iLastModule++ ) {} if( !poReader->SetModule( poDS->GetModule(iLastModule) ) ) { return NULL; } } /* -------------------------------------------------------------------- */ /* Fetch the feature associated with the record. */ /* -------------------------------------------------------------------- */ OGRFeature *poFeature; poFeature = poReader->GetFeature( (int)nFeatureId-panModuleOffset[iLastModule]-1 ); if( poFeature != NULL ) { poFeature->SetFID( nFeatureId ); if( poFeature->GetGeometryRef() != NULL ) poFeature->GetGeometryRef()->assignSpatialReference( poDS->GetSpatialRef() ); poFeature->SetField( 0, poReader->GetShortModule() ); m_nFeaturesRead++; } return poFeature; }
OGRFeature *OGRFMELayerDB::GetNextFeature() { OGRFeature *poFeature; FME_Boolean eEndOfSchema; FME_MsgNum err; poDS->AcquireSession(); if( poReader == NULL ) { if( !CreateReader() ) { return NULL; poDS->ReleaseSession(); } } err = poReader->read( *poFMEFeature, eEndOfSchema ); if( err ) { CPLFMEError( poDS->GetFMESession(), "Error while reading feature." ); poDS->ReleaseSession(); return NULL; } if( eEndOfSchema == FME_TRUE ) { poDS->ReleaseSession(); return NULL; } poFeature = poDS->ProcessFeature( this, poFMEFeature ); if( nPreviousFeature == -1 ) CPLDebug( "FMEOLEDB", "Fetching first feature from layer `%s'.", GetLayerDefn()->GetName() ); poFeature->SetFID( ++nPreviousFeature ); m_nFeaturesRead++; poDS->ReleaseSession(); return poFeature; }
OGRFeature *OGRWarpedLayer::SrcFeatureToWarpedFeature(OGRFeature* poSrcFeature) { OGRFeature* poFeature = new OGRFeature(GetLayerDefn()); poFeature->SetFrom(poSrcFeature); poFeature->SetFID(poSrcFeature->GetFID()); OGRGeometry* poGeom = poFeature->GetGeomFieldRef(m_iGeomField); if( poGeom == NULL ) return poFeature; if( poGeom->transform(m_poCT) != OGRERR_NONE ) { delete poFeature->StealGeometry(m_iGeomField); } return poFeature; }
OGRFeature* OGROpenFileGDBSimpleSQLLayer::GetFeature( GIntBig nFeatureId ) { OGRFeature* poSrcFeature = poBaseLayer->GetFeature(nFeatureId); if( poSrcFeature == NULL ) return NULL; if( poFeatureDefn == poBaseLayer->GetLayerDefn() ) return poSrcFeature; else { OGRFeature* poFeature = new OGRFeature(poFeatureDefn); poFeature->SetFrom(poSrcFeature); poFeature->SetFID(poSrcFeature->GetFID()); delete poSrcFeature; return poFeature; } }
OGRFeature *OGRNTFRasterLayer::GetFeature( long nFeatureId ) { int iReqColumn, iReqRow; /* -------------------------------------------------------------------- */ /* Is this in the range of legal feature ids (pixels)? */ /* -------------------------------------------------------------------- */ if( nFeatureId < 1 || nFeatureId > poReader->GetRasterXSize()*poReader->GetRasterYSize() ) { return NULL; } /* -------------------------------------------------------------------- */ /* Do we need to load a different column. */ /* -------------------------------------------------------------------- */ iReqColumn = (nFeatureId - 1) / poReader->GetRasterYSize(); iReqRow = nFeatureId - iReqColumn * poReader->GetRasterXSize() - 1; if( iReqColumn != iColumnOffset ) { iColumnOffset = iReqColumn; if( poReader->ReadRasterColumn( iReqColumn, pafColumn ) != CE_None ) return NULL; } /* -------------------------------------------------------------------- */ /* Create a corresponding feature. */ /* -------------------------------------------------------------------- */ OGRFeature *poFeature = new OGRFeature( poFeatureDefn ); double *padfGeoTransform = poReader->GetGeoTransform(); poFeature->SetFID( nFeatureId ); // NOTE: unusual use of GeoTransform - the pixel origin is the // bottom left corner! poFeature->SetGeometryDirectly( new OGRPoint( padfGeoTransform[0] + padfGeoTransform[1] * iReqColumn, padfGeoTransform[3] + padfGeoTransform[5] * iReqRow, pafColumn[iReqRow] ) ); poFeature->SetField( 0, pafColumn[iReqRow] ); return poFeature; }
OGRFeature* GTMTrackLayer::GetNextFeature() { if( bError ) return nullptr; while (poDS->hasNextTrack()) { Track* poTrack = poDS->fetchNextTrack(); if (poTrack == nullptr) { CPLError(CE_Failure, CPLE_AppDefined, "Could not read track. File probably corrupted"); bError = true; return nullptr; } OGRFeature* poFeature = new OGRFeature( poFeatureDefn ); OGRLineString* lineString = new OGRLineString (); for (int i = 0; i < poTrack->getNumPoints(); ++i) { const TrackPoint* psTrackPoint = poTrack->getPoint(i); lineString->addPoint(psTrackPoint->x, psTrackPoint->y); } if (poSRS) lineString->assignSpatialReference(poSRS); poFeature->SetField( NAME, poTrack->getName()); poFeature->SetField( TYPE, poTrack->getType()); poFeature->SetField( COLOR, poTrack->getColor()); poFeature->SetFID( nNextFID++ ); delete poTrack; poFeature->SetGeometryDirectly(lineString); if( (m_poFilterGeom == nullptr || FilterGeometry( poFeature->GetGeometryRef() ) ) && (m_poAttrQuery == nullptr || m_poAttrQuery->Evaluate( poFeature )) ) return poFeature; delete poFeature; } return nullptr; }
OGRFeature *OGRNTFFeatureClassLayer::GetFeature( long nFeatureId ) { char *pszFCName, *pszFCId; if( nFeatureId < 0 || nFeatureId >= poDS->GetFCCount() ) return NULL; poDS->GetFeatureClass( nFeatureId, &pszFCId, &pszFCName ); /* -------------------------------------------------------------------- */ /* Create a corresponding feature. */ /* -------------------------------------------------------------------- */ OGRFeature *poFeature = new OGRFeature( poFeatureDefn ); poFeature->SetField( 0, pszFCId ); poFeature->SetField( 1, pszFCName ); poFeature->SetFID( nFeatureId ); return poFeature; }
/*! \brief Get feature (private) \return pointer to OGRFeature or NULL not found */ OGRFeature *OGRVFKLayer::GetFeature(IVFKFeature *poVFKFeature) { OGRGeometry *poGeom; /* skip feature with unknown geometry type */ if (poVFKFeature->GetGeometryType() == wkbUnknown) return NULL; /* get features geometry */ poGeom = CreateGeometry(poVFKFeature); if (poGeom != NULL) poGeom->assignSpatialReference(poSRS); /* does it satisfy the spatial query, if there is one? */ if (m_poFilterGeom != NULL && poGeom && !FilterGeometry(poGeom)) { return NULL; } /* convert the whole feature into an OGRFeature */ OGRFeature *poOGRFeature = new OGRFeature(GetLayerDefn()); poOGRFeature->SetFID(poVFKFeature->GetFID()); // poOGRFeature->SetFID(++m_iNextFeature); poVFKFeature->LoadProperties(poOGRFeature); /* test against the attribute query */ if (m_poAttrQuery != NULL && !m_poAttrQuery->Evaluate(poOGRFeature)) { delete poOGRFeature; return NULL; } if (poGeom) poOGRFeature->SetGeometryDirectly(poGeom->clone()); return poOGRFeature; }
OGRFeature *OGRWarpedLayer::WarpedFeatureToSrcFeature(OGRFeature* poFeature) { OGRFeature* poSrcFeature = new OGRFeature(m_poDecoratedLayer->GetLayerDefn()); poSrcFeature->SetFrom(poFeature); poSrcFeature->SetFID(poFeature->GetFID()); OGRGeometry* poGeom = poSrcFeature->GetGeomFieldRef(m_iGeomField); if( poGeom != NULL ) { if( m_poReversedCT == NULL ) { delete poSrcFeature; return NULL; } if( poGeom->transform(m_poReversedCT) != OGRERR_NONE ) { delete poSrcFeature; return NULL; } } return poSrcFeature; }
OGRFeature *OGROGDILayer::GetNextRawFeature() { ecs_Result *psResult; int i; OGRFeature *poFeature; /* -------------------------------------------------------------------- */ /* Retrieve object from OGDI server and create new feature */ /* -------------------------------------------------------------------- */ psResult = cln_GetNextObject(m_nClientID); if (! ECSSUCCESS(psResult)) { // We probably reached EOF... keep track of shape count. m_nTotalShapeCount = m_iNextShapeId - m_nFilteredOutShapes; return NULL; } poFeature = new OGRFeature(m_poFeatureDefn); poFeature->SetFID( m_iNextShapeId++ ); m_nFeaturesRead++; /* -------------------------------------------------------------------- */ /* Process geometry */ /* -------------------------------------------------------------------- */ if (m_eFamily == Point) { ecs_Point *psPoint = &(ECSGEOM(psResult).point); OGRPoint *poOGRPoint = new OGRPoint(psPoint->c.x, psPoint->c.y); poOGRPoint->assignSpatialReference(m_poSpatialRef); poFeature->SetGeometryDirectly(poOGRPoint); } else if (m_eFamily == Line) { ecs_Line *psLine = &(ECSGEOM(psResult).line); OGRLineString *poOGRLine = new OGRLineString(); poOGRLine->setNumPoints( psLine->c.c_len ); for( i=0; i < (int) psLine->c.c_len; i++ ) { poOGRLine->setPoint(i, psLine->c.c_val[i].x, psLine->c.c_val[i].y); } poOGRLine->assignSpatialReference(m_poSpatialRef); poFeature->SetGeometryDirectly(poOGRLine); } else if (m_eFamily == Area) { ecs_Area *psArea = &(ECSGEOM(psResult).area); OGRPolygon *poOGRPolygon = new OGRPolygon(); for(int iRing=0; iRing < (int) psArea->ring.ring_len; iRing++) { ecs_FeatureRing *psRing = &(psArea->ring.ring_val[iRing]); OGRLinearRing *poOGRRing = new OGRLinearRing(); poOGRRing->setNumPoints( psRing->c.c_len ); for( i=0; i < (int) psRing->c.c_len; i++ ) { poOGRRing->setPoint(i, psRing->c.c_val[i].x, psRing->c.c_val[i].y); } poOGRPolygon->addRingDirectly(poOGRRing); } // __TODO__ // When OGR supports polygon centroids then we should carry them here poOGRPolygon->assignSpatialReference(m_poSpatialRef); poFeature->SetGeometryDirectly(poOGRPolygon); } else if (m_eFamily == Text) { // __TODO__ // For now text is treated as a point and string is lost // ecs_Text *psText = &(ECSGEOM(psResult).text); OGRPoint *poOGRPoint = new OGRPoint(psText->c.x, psText->c.y); poOGRPoint->assignSpatialReference(m_poSpatialRef); poFeature->SetGeometryDirectly(poOGRPoint); } else { CPLAssert(FALSE); } /* -------------------------------------------------------------------- */ /* Set attributes */ /* -------------------------------------------------------------------- */ char *pszAttrList = ECSOBJECTATTR(psResult); for( int iField = 0; iField < m_poFeatureDefn->GetFieldCount(); iField++ ) { char *pszFieldStart; int nNameLen; char chSavedChar; /* parse out the next attribute value */ if( !ecs_FindElement( pszAttrList, &pszFieldStart, &pszAttrList, &nNameLen, NULL ) ) { nNameLen = 0; pszFieldStart = pszAttrList; } /* Skip any trailing white space (for string constants). */ if( nNameLen > 0 && pszFieldStart[nNameLen-1] == ' ' ) nNameLen--; /* skip leading white space */ while( pszFieldStart[0] == ' ' && nNameLen > 0 ) { pszFieldStart++; nNameLen--; } /* zero terminate the single field value, but save the */ /* character we overwrote, so we can restore it when done. */ chSavedChar = pszFieldStart[nNameLen]; pszFieldStart[nNameLen] = '\0'; /* OGR takes care of all field type conversions for us! */ poFeature->SetField(iField, pszFieldStart); pszFieldStart[nNameLen] = chSavedChar; } /* -------------------------------------------------------------------- */ /* Apply the text associated with text features if appropriate. */ /* -------------------------------------------------------------------- */ if( m_eFamily == Text ) { poFeature->SetField( "text", ECSGEOM(psResult).text.desc ); } return poFeature; }