|
osgEarth 2.1.1
|
Inheritance diagram for FeatureCursorOGR:
Collaboration diagram for FeatureCursorOGR:Public Member Functions | |
| FeatureCursorOGR (OGRLayerH dsHandle, OGRLayerH layerHandle, const FeatureProfile *profile, const Symbology::Query &query, const FeatureFilterList &filters) | |
| bool | hasMore () const |
| Feature * | nextFeature () |
Protected Member Functions | |
| virtual | ~FeatureCursorOGR () |
Private Member Functions | |
| void | readChunk () |
Private Attributes | |
| OGRDataSourceH | _dsHandle |
| OGRLayerH | _layerHandle |
| OGRLayerH | _resultSetHandle |
| OGRGeometryH | _spatialFilter |
| Symbology::Query | _query |
| int | _chunkSize |
| OGRFeatureH | _nextHandleToQueue |
| osg::ref_ptr< const FeatureProfile > | _profile |
| std::queue< osg::ref_ptr < Feature > > | _queue |
| osg::ref_ptr< Feature > | _lastFeatureReturned |
| const FeatureFilterList & | _filters |
Definition at line 32 of file FeatureCursorOGR.
| FeatureCursorOGR::FeatureCursorOGR | ( | OGRLayerH | dsHandle, |
| OGRLayerH | layerHandle, | ||
| const FeatureProfile * | profile, | ||
| const Symbology::Query & | query, | ||
| const FeatureFilterList & | filters | ||
| ) |
Creates a new feature cursor that iterates over an OGR layer.
| dsHandle | Handle on the OGR data source to which the results layer belongs |
| layerHandle | Handle to the OGR layer containing the features |
| profile | Profile of the feature layer corresponding to the feature data |
| query | The the query from which this cursor was created. |
Definition at line 31 of file FeatureCursorOGR.cpp.
: _dsHandle( dsHandle ), _layerHandle( layerHandle ), _resultSetHandle( 0L ), _spatialFilter( 0L ), _query( query ), _chunkSize( 500 ), _nextHandleToQueue( 0L ), _profile( profile ), _filters( filters ) { //_resultSetHandle = _layerHandle; { OGR_SCOPED_LOCK; std::string expr; std::string from = OGR_FD_GetName( OGR_L_GetLayerDefn( _layerHandle )); from = std::string("'") + from + std::string("'"); if ( query.expression().isSet() ) { // build the SQL: allow the Query to include either a full SQL statement or // just the WHERE clause. expr = query.expression().value(); // if the expression is just a where clause, expand it into a complete SQL expression. std::string temp = expr; std::transform( temp.begin(), temp.end(), temp.begin(), ::tolower ); //bool complete = temp.find( "select" ) == 0; if ( temp.find( "select" ) != 0 ) { std::stringstream buf; buf << "SELECT * FROM " << from << " WHERE " << expr; std::string bufStr; bufStr = buf.str(); expr = bufStr; } } else { std::stringstream buf; buf << "SELECT * FROM " << from; expr = buf.str(); } // if there's a spatial extent in the query, build the spatial filter: if ( query.bounds().isSet() ) { OGRGeometryH ring = OGR_G_CreateGeometry( wkbLinearRing ); OGR_G_AddPoint(ring, query.bounds()->xMin(), query.bounds()->yMin(), 0 ); OGR_G_AddPoint(ring, query.bounds()->xMin(), query.bounds()->yMax(), 0 ); OGR_G_AddPoint(ring, query.bounds()->xMax(), query.bounds()->yMax(), 0 ); OGR_G_AddPoint(ring, query.bounds()->xMax(), query.bounds()->yMin(), 0 ); OGR_G_AddPoint(ring, query.bounds()->xMin(), query.bounds()->yMin(), 0 ); _spatialFilter = OGR_G_CreateGeometry( wkbPolygon ); OGR_G_AddGeometryDirectly( _spatialFilter, ring ); // note: "Directly" above means _spatialFilter takes ownership if ring handle } _resultSetHandle = OGR_DS_ExecuteSQL( _dsHandle, expr.c_str(), _spatialFilter, 0L ); if ( _resultSetHandle ) { OGR_L_ResetReading( _resultSetHandle ); } } readChunk(); }
Here is the call graph for this function:| FeatureCursorOGR::~FeatureCursorOGR | ( | ) | [protected, virtual] |
Definition at line 107 of file FeatureCursorOGR.cpp.
{
OGR_SCOPED_LOCK;
if ( _nextHandleToQueue )
OGR_F_Destroy( _nextHandleToQueue );
if ( _resultSetHandle != _layerHandle )
OGR_DS_ReleaseResultSet( _dsHandle, _resultSetHandle );
if ( _spatialFilter )
OGR_G_DestroyGeometry( _spatialFilter );
if ( _dsHandle )
OGRReleaseDataSource( _dsHandle );
}
| bool FeatureCursorOGR::hasMore | ( | ) | const [virtual] |
Implements osgEarth::Features::FeatureCursor.
Definition at line 125 of file FeatureCursorOGR.cpp.
{
return _resultSetHandle && ( _queue.size() > 0 || _nextHandleToQueue != 0L );
}
Here is the caller graph for this function:| Feature * FeatureCursorOGR::nextFeature | ( | ) | [virtual] |
Implements osgEarth::Features::FeatureCursor.
Definition at line 131 of file FeatureCursorOGR.cpp.
{
if ( !hasMore() )
return 0L;
if ( _queue.size() == 0 && _nextHandleToQueue )
readChunk();
// do this in order to hold a reference to the feature we return, so the caller
// doesn't have to. This lets us avoid requiring the caller to use a ref_ptr when
// simply iterating over the cursor, making the cursor move conventient to use.
_lastFeatureReturned = _queue.front();
_queue.pop();
return _lastFeatureReturned.get();
}
Here is the call graph for this function:| void FeatureCursorOGR::readChunk | ( | ) | [private] |
Definition at line 152 of file FeatureCursorOGR.cpp.
{
if ( !_resultSetHandle )
return;
FeatureList preProcessList;
OGR_SCOPED_LOCK;
if ( _nextHandleToQueue )
{
Feature* f = OgrUtils::createFeature( _nextHandleToQueue );
if ( f )
{
_queue.push( f );
if ( _filters.size() > 0 )
preProcessList.push_back( f );
}
OGR_F_Destroy( _nextHandleToQueue );
_nextHandleToQueue = 0L;
}
int handlesToQueue = _chunkSize - _queue.size();
for( int i=0; i<handlesToQueue; i++ )
{
OGRFeatureH handle = OGR_L_GetNextFeature( _resultSetHandle );
if ( handle )
{
Feature* f = OgrUtils::createFeature( handle );
if ( f )
{
_queue.push( f );
if ( _filters.size() > 0 )
preProcessList.push_back( f );
}
OGR_F_Destroy( handle );
}
else
break;
}
// preprocess the features using the filter list:
if ( preProcessList.size() > 0 )
{
FilterContext cx;
cx.profile() = _profile.get();
for( FeatureFilterList::const_iterator i = _filters.begin(); i != _filters.end(); ++i )
{
FeatureFilter* filter = i->get();
cx = filter->push( preProcessList, cx );
}
}
// read one more for "more" detection:
_nextHandleToQueue = OGR_L_GetNextFeature( _resultSetHandle );
//OE_NOTICE << "read " << _queue.size() << " features ... " << std::endl;
}
Here is the call graph for this function:
Here is the caller graph for this function:int FeatureCursorOGR::_chunkSize [private] |
Definition at line 68 of file FeatureCursorOGR.
OGRDataSourceH FeatureCursorOGR::_dsHandle [private] |
Definition at line 63 of file FeatureCursorOGR.
const FeatureFilterList& FeatureCursorOGR::_filters [private] |
Definition at line 73 of file FeatureCursorOGR.
osg::ref_ptr<Feature> FeatureCursorOGR::_lastFeatureReturned [private] |
Definition at line 72 of file FeatureCursorOGR.
OGRLayerH FeatureCursorOGR::_layerHandle [private] |
Definition at line 64 of file FeatureCursorOGR.
OGRFeatureH FeatureCursorOGR::_nextHandleToQueue [private] |
Definition at line 69 of file FeatureCursorOGR.
osg::ref_ptr<const FeatureProfile> FeatureCursorOGR::_profile [private] |
Definition at line 70 of file FeatureCursorOGR.
Symbology::Query FeatureCursorOGR::_query [private] |
Definition at line 67 of file FeatureCursorOGR.
std::queue< osg::ref_ptr<Feature> > FeatureCursorOGR::_queue [private] |
Definition at line 71 of file FeatureCursorOGR.
OGRLayerH FeatureCursorOGR::_resultSetHandle [private] |
Definition at line 65 of file FeatureCursorOGR.
OGRGeometryH FeatureCursorOGR::_spatialFilter [private] |
Definition at line 66 of file FeatureCursorOGR.
1.7.3