本文整理汇总了C++中QgsFeatureRequest函数的典型用法代码示例。如果您正苦于以下问题:C++ QgsFeatureRequest函数的具体用法?C++ QgsFeatureRequest怎么用?C++ QgsFeatureRequest使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了QgsFeatureRequest函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QgsFeature
const QgsFeature* QgsActionMenu::feature()
{
if ( !mFeature || !mFeature->isValid() )
{
QgsFeature* feat = new QgsFeature();
if ( mActions->layer()->getFeatures( QgsFeatureRequest( mFeatureId ) ).nextFeature( *feat ) )
{
mFeature = feat;
mOwnsFeature = true;
}
else
{
delete feat;
}
}
return mFeature;
}
示例2: QgsFeatureRequest
QgsFeature QgsRelationReferenceWidget::referencedFeature()
{
QgsFeature f;
if ( mReferencedLayer )
{
QgsFeatureId fid;
if ( mReadOnlySelector )
{
fid = mFeatureId;
}
else
{
fid = mComboBox->itemData( mComboBox->currentIndex() ).value<QgsFeatureId>();
}
mReferencedLayer->getFeatures( QgsFeatureRequest().setFilterFid( fid ) ).nextFeature( f );
}
return f;
}
示例3: QgsFeatureRequest
void QgsSelectedFeature::updateGeometry( const QgsGeometry *geom )
{
delete mGeometry;
if ( !geom )
{
QgsFeature f;
mVlayer->getFeatures( QgsFeatureRequest().setFilterFid( mFeatureId ) ).nextFeature( f );
if ( f.hasGeometry() )
mGeometry = new QgsGeometry( f.geometry() );
else
mGeometry = new QgsGeometry();
}
else
{
mGeometry = new QgsGeometry( *geom );
}
}
示例4: QgsFeatureRequest
QgsFeature QgsRelationReferenceWidget::referencedFeature() const
{
QgsFeature f;
if ( mReferencedLayer )
{
QgsFeatureId fid;
if ( mReadOnlySelector )
{
fid = mFeature.id();
}
else
{
fid = mComboBox->currentData( QgsAttributeTableModel::FeatureIdRole ).value<QgsFeatureId>();
}
mReferencedLayer->getFeatures( QgsFeatureRequest().setFilterFid( fid ) ).nextFeature( f );
}
return f;
}
示例5: QgsFeatureRequest
QgsFeature QgsRelationReferenceWidget::referencedFeature() const
{
QgsFeature f;
if ( mReferencedLayer )
{
QgsFeatureRequest request;
if ( mReadOnlySelector )
{
request = QgsFeatureRequest().setFilterFid( mFeature.id() );
}
else
{
request = mComboBox->currentFeatureRequest();
}
mReferencedLayer->getFeatures( request ).nextFeature( f );
}
return f;
}
示例6: translateFeature
int QgsVectorLayerEditUtils::translateFeature( QgsFeatureId featureId, double dx, double dy )
{
if ( !mLayer->isSpatial() )
return 1;
QgsFeature f;
if ( !mLayer->getFeatures( QgsFeatureRequest().setFilterFid( featureId ).setSubsetOfAttributes( QgsAttributeList() ) ).nextFeature( f ) || !f.hasGeometry() )
return 1; //geometry not found
QgsGeometry geometry = f.geometry();
int errorCode = geometry.translate( dx, dy );
if ( errorCode == 0 )
{
mLayer->editBuffer()->changeGeometry( featureId, geometry );
}
return errorCode;
}
示例7: messagePushed
bool QgsLayoutAtlas::prepareForFeature( const int featureI )
{
if ( !mCoverageLayer )
{
return false;
}
if ( mFeatureIds.isEmpty() )
{
emit messagePushed( tr( "No matching atlas features" ) );
return false;
}
if ( featureI >= mFeatureIds.size() )
{
return false;
}
mCurrentFeatureNo = featureI;
// retrieve the next feature, based on its id
if ( !mCoverageLayer->getFeatures( QgsFeatureRequest().setFilterFid( mFeatureIds[ featureI ].first ) ).nextFeature( mCurrentFeature ) )
return false;
mLayout->reportContext().blockSignals( true ); // setFeature emits changed, we don't want 2 signals
mLayout->reportContext().setLayer( mCoverageLayer.get() );
mLayout->reportContext().blockSignals( false );
mLayout->reportContext().setFeature( mCurrentFeature );
// must come after we've set the report context feature, or the expression context will have an outdated atlas feature
QgsExpressionContext expressionContext = createExpressionContext();
// generate filename for current feature
if ( !evalFeatureFilename( expressionContext ) )
{
//error evaluating filename
return false;
}
emit featureChanged( mCurrentFeature );
emit messagePushed( QString( tr( "Atlas feature %1 of %2" ) ).arg( featureI + 1 ).arg( mFeatureIds.size() ) );
return mCurrentFeature.isValid();
}
示例8: QgsFeatureRequest
QgsGeometry* QgsTransectSample::findBaselineGeometry( QVariant strataId )
{
if ( !mBaselineLayer )
{
return 0;
}
QgsFeatureIterator baseLineIt = mBaselineLayer->getFeatures( QgsFeatureRequest().setSubsetOfAttributes( QStringList( mBaselineStrataId ), mBaselineLayer->pendingFields() ) );
QgsFeature fet;
while ( baseLineIt.nextFeature( fet ) ) //todo: cache this in case there are many baslines
{
if ( strataId == fet.attribute( mBaselineStrataId ) || mShareBaseline )
{
Q_NOWARN_DEPRECATED_PUSH
return fet.geometryAndOwnership();
Q_NOWARN_DEPRECATED_POP
}
}
示例9: expression
void QgsSizeScaleWidget::computeFromLayerTriggered()
{
if ( !mLayer )
return;
QgsExpression expression( mExpressionWidget->currentField() );
QgsExpressionContext context;
context << QgsExpressionContextUtils::globalScope()
<< QgsExpressionContextUtils::projectScope()
<< QgsExpressionContextUtils::atlasScope( 0 )
<< QgsExpressionContextUtils::layerScope( mLayer );
if ( ! expression.prepare( &context ) )
return;
QStringList lst( expression.referencedColumns() );
QgsFeatureIterator fit = mLayer->getFeatures(
QgsFeatureRequest().setFlags( expression.needsGeometry()
? QgsFeatureRequest::NoFlags
: QgsFeatureRequest::NoGeometry )
.setSubsetOfAttributes( lst, mLayer->fields() ) );
// create list of non-null attribute values
double min = DBL_MAX;
double max = -DBL_MAX;
QgsFeature f;
while ( fit.nextFeature( f ) )
{
bool ok;
context.setFeature( f );
const double value = expression.evaluate( &context ).toDouble( &ok );
if ( ok )
{
max = qMax( max, value );
min = qMin( min, value );
}
}
minValueSpinBox->setValue( min );
maxValueSpinBox->setValue( max );
updatePreview();
}
示例10: QgsGeometry
QgsGeometry QgsTransectSample::findBaselineGeometry( const QVariant& strataId )
{
if ( !mBaselineLayer )
{
return QgsGeometry();
}
QgsFeatureIterator baseLineIt = mBaselineLayer->getFeatures( QgsFeatureRequest().setSubsetOfAttributes( QStringList( mBaselineStrataId ), mBaselineLayer->fields() ) );
QgsFeature fet;
while ( baseLineIt.nextFeature( fet ) ) //todo: cache this in case there are many baslines
{
if ( strataId == fet.attribute( mBaselineStrataId ) || mShareBaseline )
{
return fet.geometry();
}
}
return QgsGeometry();
}
示例11: lock
bool QgsFeaturePool::get( const QgsFeatureId& id , QgsFeature& feature )
{
QMutexLocker lock( &mLayerMutex );
QgsFeature* pfeature = mFeatureCache.object( id );
if ( pfeature == 0 )
{
// Get new feature
pfeature = new QgsFeature();
// TODO: avoid always querying all attributes (attribute values are needed when merging by attribute)
if ( !mLayer->getFeatures( QgsFeatureRequest( id ) ).nextFeature( *pfeature ) )
{
delete pfeature;
return false;
}
mFeatureCache.insert( id, pfeature );
}
feature = *pfeature;
return true;
}
示例12: QString
void QgsAttributeTypeDialog::defaultExpressionChanged()
{
QString expression = mExpressionWidget->expression();
if ( expression.isEmpty() )
{
mDefaultPreviewLabel->setText( QString() );
return;
}
QgsExpressionContext context = mLayer->createExpressionContext();
if ( !mPreviewFeature.isValid() )
{
// get first feature
QgsFeatureIterator it = mLayer->getFeatures( QgsFeatureRequest().setLimit( 1 ) );
it.nextFeature( mPreviewFeature );
}
context.setFeature( mPreviewFeature );
QgsExpression exp = QgsExpression( expression );
exp.prepare( &context );
if ( exp.hasParserError() )
{
mDefaultPreviewLabel->setText( "<i>" + exp.parserErrorString() + "</i>" );
return;
}
QVariant val = exp.evaluate( &context );
if ( exp.hasEvalError() )
{
mDefaultPreviewLabel->setText( "<i>" + exp.evalErrorString() + "</i>" );
return;
}
QgsFieldFormatter *fieldFormatter = QgsApplication::fieldFormatterRegistry()->fieldFormatter( editorWidgetType() );
QString previewText = fieldFormatter->representValue( mLayer, mFieldIdx, editorWidgetConfig(), QVariant(), val );
mDefaultPreviewLabel->setText( "<i>" + previewText + "</i>" );
}
示例13: reset
void QgsRubberSelectId::addFeature( QgsVectorLayer* lyr, QgsFeatureId fid )
{
if ( mGeometryType != lyr->geometryType() )
{
reset();
mGeometryType = lyr->geometryType();
mRubberBand->reset( lyr->geometryType() );
setStyle();
}
QgsFeature feat;
if ( !lyr->getFeatures( QgsFeatureRequest().setFilterFid( fid ).setSubsetOfAttributes( QgsAttributeList() ) ).nextFeature( feat ) )
{
return;
}
if ( !feat.hasGeometry() )
{
return;
}
mRubberBand->setToGeometry( feat.geometry(), lyr );
} // void QgsRubberSelectId::addFeature( QgsVectorLayer* mLayer, int Id )
示例14: QString
void QgsOfflineEditing::applyFeaturesAdded( QgsVectorLayer* offlineLayer, QgsVectorLayer* remoteLayer, sqlite3* db, int layerId )
{
QString sql = QString( "SELECT \"fid\" FROM 'log_added_features' WHERE \"layer_id\" = %1" ).arg( layerId );
QList<int> newFeatureIds = sqlQueryInts( db, sql );
// get new features from offline layer
QgsFeatureList features;
for ( int i = 0; i < newFeatureIds.size(); i++ )
{
QgsFeature feature;
if ( offlineLayer->getFeatures( QgsFeatureRequest().setFilterFid( newFeatureIds.at( i ) ) ).nextFeature( feature ) )
{
features << feature;
}
}
// copy features to remote layer
emit progressModeSet( QgsOfflineEditing::AddFeatures, features.size() );
int i = 1;
int newAttrsCount = remoteLayer->pendingFields().count();
for ( QgsFeatureList::iterator it = features.begin(); it != features.end(); ++it )
{
QgsFeature f = *it;
// NOTE: Spatialite provider ignores position of geometry column
// restore gap in QgsAttributeMap if geometry column is not last (WORKAROUND)
QMap<int, int> attrLookup = attributeLookup( offlineLayer, remoteLayer );
QgsAttributes newAttrs( newAttrsCount );
QgsAttributes attrs = f.attributes();
for ( int it = 0; it < attrs.count(); ++it )
{
newAttrs[ attrLookup[ it ] ] = attrs[ it ];
}
f.setAttributes( newAttrs );
remoteLayer->addFeature( f, false );
emit progressUpdated( i++ );
}
}
示例15: QgsExpression
QgsFeatureIterator QgsVectorLayerUtils::getValuesIterator( const QgsVectorLayer *layer, const QString &fieldOrExpression, bool &ok, bool selectedOnly )
{
std::unique_ptr<QgsExpression> expression;
QgsExpressionContext context;
int attrNum = layer->fields().lookupField( fieldOrExpression );
if ( attrNum == -1 )
{
// try to use expression
expression.reset( new QgsExpression( fieldOrExpression ) );
context.appendScopes( QgsExpressionContextUtils::globalProjectLayerScopes( layer ) );
if ( expression->hasParserError() || !expression->prepare( &context ) )
{
ok = false;
return QgsFeatureIterator();
}
}
QSet<QString> lst;
if ( !expression )
lst.insert( fieldOrExpression );
else
lst = expression->referencedColumns();
QgsFeatureRequest request = QgsFeatureRequest()
.setFlags( ( expression && expression->needsGeometry() ) ?
QgsFeatureRequest::NoFlags :
QgsFeatureRequest::NoGeometry )
.setSubsetOfAttributes( lst, layer->fields() );
ok = true;
if ( !selectedOnly )
{
return layer->getFeatures( request );
}
else
{
return layer->getSelectedFeatures( request );
}
}