本文整理汇总了C++中QgsVectorLayer::featureCount方法的典型用法代码示例。如果您正苦于以下问题:C++ QgsVectorLayer::featureCount方法的具体用法?C++ QgsVectorLayer::featureCount怎么用?C++ QgsVectorLayer::featureCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QgsVectorLayer
的用法示例。
在下文中一共展示了QgsVectorLayer::featureCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updateLabel
void QgsSymbolLegendNode::updateLabel()
{
if ( !mLayerNode )
return;
bool showFeatureCount = mLayerNode->customProperty( QStringLiteral( "showFeatureCount" ), 0 ).toBool();
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( mLayerNode->layer() );
if ( mEmbeddedInParent )
{
QString layerName = mLayerNode->name();
if ( !mLayerNode->customProperty( QStringLiteral( "legend/title-label" ) ).isNull() )
layerName = mLayerNode->customProperty( QStringLiteral( "legend/title-label" ) ).toString();
mLabel = mUserLabel.isEmpty() ? layerName : mUserLabel;
if ( showFeatureCount && vl && vl->featureCount() >= 0 )
mLabel += QStringLiteral( " [%1]" ).arg( vl->featureCount() );
}
else
{
mLabel = mUserLabel.isEmpty() ? mItem.label() : mUserLabel;
if ( showFeatureCount && vl )
{
qlonglong count = vl->featureCount( mItem.ruleKey() );
mLabel += QStringLiteral( " [%1]" ).arg( count != -1 ? QLocale().toString( count ) : tr( "N/A" ) );
}
}
emit dataChanged();
}
示例2: if
void QgsLegendModel::updateSymbolV2ItemText( QStandardItem* symbolItem )
{
QgsComposerSymbolV2Item* sv2Item = dynamic_cast<QgsComposerSymbolV2Item*>( symbolItem );
if ( !sv2Item ) return;
QgsComposerLayerItem* lItem = dynamic_cast<QgsComposerLayerItem*>( sv2Item->parent() );
if ( !lItem ) return;
QgsMapLayer* mapLayer = QgsMapLayerRegistry::instance()->mapLayer( lItem->layerID() );
if ( !mapLayer ) return;
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( mapLayer );
if ( !vLayer ) return;
QgsFeatureRendererV2* renderer = vLayer->rendererV2();
if ( !renderer ) return;
if ( lItem->showFeatureCount() ) vLayer->countSymbolFeatures();
QgsLegendSymbolList symbolList = renderer->legendSymbolItems();
QPair<QString, QgsSymbolV2*> symbol = symbolList.value( symbolItem->row() );
QString label = sv2Item->userText().isEmpty() ? symbol.first : sv2Item->userText();
if ( renderer->type() == "singleSymbol" )
{
if ( !sv2Item->userText().isEmpty() )
{
label = sv2Item->userText();
}
else if ( !lItem->userText().isEmpty() )
{
label = lItem->userText();
}
else if ( !vLayer->title().isEmpty() )
{
label = vLayer->title();
}
else
{
label = vLayer->name();
}
}
if ( lItem->showFeatureCount() )
{
// Add counts to multi symbols layers only or labeled single symbols,
// so that single symbol layers are still drawn on single line
if ( symbolList.size() > 1 || !label.isEmpty() )
{
label += QString( " [%1]" ).arg( vLayer->featureCount( symbol.second ) );
}
}
symbolItem->setText( label );
}
示例3: data
QVariant QgsLegendModel::data( const QModelIndex &index, int role ) const
{
// handle custom layer node labels
if ( QgsLayerTreeNode *node = index2node( index ) )
{
if ( QgsLayerTree::isLayer( node ) && ( role == Qt::DisplayRole || role == Qt::EditRole ) && !node->customProperty( QStringLiteral( "legend/title-label" ) ).isNull() )
{
QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( node );
QString name = node->customProperty( QStringLiteral( "legend/title-label" ) ).toString();
if ( nodeLayer->customProperty( QStringLiteral( "showFeatureCount" ), 0 ).toInt() && role == Qt::DisplayRole )
{
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( nodeLayer->layer() );
if ( vlayer && vlayer->featureCount() >= 0 )
name += QStringLiteral( " [%1]" ).arg( vlayer->featureCount() );
}
return name;
}
}
return QgsLayerTreeModel::data( index, role );
}
示例4: getDescriptionLayerShow
QString QgsSpatialQueryDialog::getDescriptionLayerShow( bool isTarget )
{
QgsVectorLayer* lyr = NULL;
QCheckBox * checkBox = NULL;
if ( isTarget )
{
lyr = mLayerTarget;
checkBox = ckbUsingSelectedTarget;
}
else
{
lyr = mLayerReference;
checkBox = ckbUsingSelectedReference;
}
QString sDescFeatures = checkBox->isChecked()
? tr( "%1 of %2" ).arg( lyr->selectedFeatureCount() ).arg( lyr->featureCount() )
: tr( "all = %1" ).arg( lyr->featureCount() );
return QString( "%1 (%2)" ).arg( lyr->name() ).arg( sDescFeatures );
} // QString QgsSpatialQueryDialog::getDescriptionLayerShow(bool isTarget)
示例5: QString
void QgsSymbolV2LegendNode::updateLabel()
{
bool showFeatureCount = mLayerNode->customProperty( "showFeatureCount", 0 ).toBool();
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer*>( mLayerNode->layer() );
if ( mEmbeddedInParent )
{
QString layerName = mLayerNode->layerName();
if ( !mLayerNode->customProperty( "legend/title-label" ).isNull() )
layerName = mLayerNode->customProperty( "legend/title-label" ).toString();
mLabel = mUserLabel.isEmpty() ? layerName : mUserLabel;
if ( showFeatureCount && vl && vl->featureCount() >= 0 )
mLabel += QString( " [%1]" ).arg( vl->featureCount() );
}
else
{
mLabel = mUserLabel.isEmpty() ? mItem.label() : mUserLabel;
if ( showFeatureCount && vl && mItem.legacyRuleKey() )
mLabel += QString( " [%1]" ).arg( vl->featureCount( mItem.legacyRuleKey() ) );
}
}
示例6: QgsVectorLayer
QgsVectorLayer *QgsDwgImportDialog::layer( QgsLayerTreeGroup *layerGroup, const QString &layerFilter, const QString &table )
{
QgsVectorLayer *l = new QgsVectorLayer( QStringLiteral( "%1|layername=%2" ).arg( leDatabase->text(), table ), table, QStringLiteral( "ogr" ), false );
l->setSubsetString( QStringLiteral( "%1space=0 AND block=-1" ).arg( layerFilter ) );
if ( l->featureCount() == 0 )
{
delete l;
return nullptr;
}
QgsProject::instance()->addMapLayer( l, false );
layerGroup->addLayer( l );
return l;
}
示例7: updateLayer
void QgsLegendModel::updateLayer( QStandardItem* layerItem )
{
QgsDebugMsg( "Entered." );
QgsComposerLayerItem* lItem = dynamic_cast<QgsComposerLayerItem*>( layerItem );
if ( lItem )
{
QgsMapLayer* mapLayer = QgsMapLayerRegistry::instance()->mapLayer( lItem->layerID() );
if ( mapLayer )
{
//delete all the entries under layer item
int currentRowCount = lItem->rowCount();
for ( int i = currentRowCount - 1; i >= 0; --i )
{
lItem->removeRow( i );
}
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( mapLayer );
//set layer name as item text
QString label = mapLayer->name();
if ( vLayer && lItem->showFeatureCount() )
{
label += QString( " [%1]" ).arg( vLayer->featureCount() );
}
layerItem->setText( label );
if ( vLayer )
{
if ( vLayer->isUsingRendererV2() )
{
addVectorLayerItemsV2( lItem, vLayer );
}
else
{
addVectorLayerItems( lItem, vLayer );
}
}
QgsRasterLayer* rLayer = qobject_cast<QgsRasterLayer*>( mapLayer );
if ( rLayer )
{
addRasterLayerItems( lItem, rLayer );
}
}
}
}
示例8: QgsVectorLayer
QgsVectorLayer *QgsDwgImportDialog::layer( QgsLayerTreeGroup *layerGroup, const QString &layerFilter, const QString &table )
{
QgsVectorLayer::LayerOptions options { QgsProject::instance()->transformContext() };
options.loadDefaultStyle = false;
QgsVectorLayer *l = new QgsVectorLayer( QStringLiteral( "%1|layername=%2" ).arg( mDatabaseFileWidget->filePath(), table ), table, QStringLiteral( "ogr" ), options );
l->setSubsetString( QStringLiteral( "%1space=0 AND block=-1" ).arg( layerFilter ) );
if ( l->featureCount() == 0 )
{
delete l;
return nullptr;
}
QgsProject::instance()->addMapLayer( l, false );
layerGroup->addLayer( l );
return l;
}
示例9: updateLayerItemText
void QgsLegendModel::updateLayerItemText( QStandardItem* layerItem )
{
QgsComposerLayerItem* lItem = dynamic_cast<QgsComposerLayerItem*>( layerItem );
if ( !lItem ) return;
QgsMapLayer* mapLayer = QgsMapLayerRegistry::instance()->mapLayer( lItem->layerID() );
if ( !mapLayer ) return;
QString label = lItem->userText().isEmpty() ? mapLayer->name() : lItem->userText();
QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( mapLayer );
if ( vLayer )
{
addVectorLayerItemsV2( lItem, vLayer );
if ( lItem->showFeatureCount() )
{
label += QString( " [%1]" ).arg( vLayer->featureCount() );
}
}
lItem->setText( label );
}
示例10: qgis_QgsVectorLayer_open
int qgis_QgsVectorLayer_open(void)
{
QString path = YAP_AtomName(YAP_AtomOfTerm(YAP_ARG1));
QString basename = YAP_AtomName(YAP_AtomOfTerm(YAP_ARG2));
QString provider = YAP_AtomName(YAP_AtomOfTerm(YAP_ARG3));
YAP_Term out;
QgsVectorLayer *layer =
new QgsVectorLayer(path, basename, provider);
if (layer->isValid())
{
cerr << "Layer Type: " << layer->geometryType() << endl;
cerr << "Feature Count: " << layer->featureCount() << endl;
return TRUE;
}
else
{
delete layer;
return FALSE;
}
}
示例11: getDescriptionInvalidFeaturesShow
QString QgsSpatialQueryDialog::getDescriptionInvalidFeaturesShow( bool isTarget )
{
QgsVectorLayer* lyr = NULL;
QCheckBox* checkBox = NULL;
int totalInvalid = 0;
if ( isTarget )
{
lyr = mLayerTarget;
checkBox = ckbUsingSelectedTarget;
totalInvalid = mFeatureInvalidTarget.size();
}
else
{
lyr = mLayerReference;
checkBox = ckbUsingSelectedReference;
totalInvalid = mFeatureInvalidReference.size();
}
QString sDescFeatures = checkBox->isChecked()
? tr( "%1 of %2(selected features)" ).arg( totalInvalid ).arg( lyr->selectedFeatureCount() )
: tr( "%1 of %2" ).arg( totalInvalid ).arg( lyr->featureCount() );
return QString( "%1: %2" ).arg( lyr->name() ).arg( sDescFeatures );
} // QString QgsSpatialQueryDialog::getDescriptionInvalidFeatures(bool isTarget)
示例12: makeGraph
void RgLineVectorLayerDirector::makeGraph( RgGraphBuilder *builder, const QVector< QgsPoint >& additionalPoints,
QVector< QgsPoint >& tiedPoint ) const
{
QgsVectorLayer *vl = myLayer();
if ( vl == NULL )
return;
int featureCount = ( int ) vl->featureCount() * 2;
int step = 0;
QgsCoordinateTransform ct;
QgsDistanceArea da;
ct.setSourceCrs( vl->crs() );
if ( builder->coordinateTransformEnabled() )
{
ct.setDestCRS( builder->destinationCrs() );
da.setProjectionsEnabled( true );
//
//da.setSourceCrs( builder->destinationCrs().srsid() );
//
}
else
{
ct.setDestCRS( vl->crs() );
da.setProjectionsEnabled( false );
}
tiedPoint = QVector< QgsPoint >( additionalPoints.size(), QgsPoint( 0.0, 0.0 ) );
TiePointInfo tmpInfo;
tmpInfo.mLength = infinity();
QVector< TiePointInfo > pointLengthMap( additionalPoints.size(), tmpInfo );
QVector< TiePointInfo >::iterator pointLengthIt;
// begin: tie points to the graph
QgsAttributeList la;
vl->select( la );
QgsFeature feature;
while ( vl->nextFeature( feature ) )
{
QgsMultiPolyline mpl;
if ( feature.geometry()->wkbType() == QGis::WKBLineString )
{
mpl.push_back( feature.geometry()->asPolyline() );
}else if ( feature.geometry()->wkbType() == QGis::WKBMultiLineString )
{
mpl = feature.geometry()->asMultiPolyline();
}
QgsMultiPolyline::iterator mplIt;
for ( mplIt = mpl.begin(); mplIt != mpl.end(); ++mplIt )
{
QgsPoint pt1, pt2;
bool isFirstPoint = true;
QgsPolyline::iterator pointIt;
for ( pointIt = mplIt->begin(); pointIt != mplIt->end(); ++pointIt )
{
pt2 = builder->addVertex( ct.transform( *pointIt ) );
if ( !isFirstPoint )
{
int i = 0;
for ( i = 0; i != additionalPoints.size(); ++i )
{
TiePointInfo info;
if ( pt1 == pt2 )
{
info.mLength = additionalPoints[ i ].sqrDist( pt1 );
info.mTiedPoint = pt1;
}
else
{
info.mLength = additionalPoints[ i ].sqrDistToSegment( pt1.x(), pt1.y(), pt2.x(), pt2.y(), info.mTiedPoint );
}
if ( pointLengthMap[ i ].mLength > info.mLength )
{
info.mTiedPoint = builder->addVertex( info.mTiedPoint );
info.mFirstPoint = pt1;
info.mLastPoint = pt2;
pointLengthMap[ i ] = info;
tiedPoint[ i ] = info.mTiedPoint;
}
}
}
pt1 = pt2;
isFirstPoint = false;
}
}
emit buildProgress( ++step, featureCount );
}
// end: tie points to graph
if ( mDirectionFieldId != -1 )
{
la.push_back( mDirectionFieldId );
}
if ( mSpeedFieldId != -1 )
{
//.........这里部分代码省略.........
示例13: data
QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const
{
if ( !index.isValid() || index.column() > 1 )
return QVariant();
if ( QgsLayerTreeModelLegendNode* sym = index2legendNode( index ) )
return legendNodeData( sym, role );
QgsLayerTreeNode* node = index2node( index );
if ( role == Qt::DisplayRole || role == Qt::EditRole )
{
if ( QgsLayerTree::isGroup( node ) )
return QgsLayerTree::toGroup( node )->name();
if ( QgsLayerTree::isLayer( node ) )
{
QgsLayerTreeLayer* nodeLayer = QgsLayerTree::toLayer( node );
QString name = nodeLayer->layerName();
if ( nodeLayer->customProperty( "showFeatureCount", 0 ).toInt() && role == Qt::DisplayRole )
{
QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer*>( nodeLayer->layer() );
if ( vlayer && vlayer->featureCount() >= 0 )
name += QString( " [%1]" ).arg( vlayer->featureCount() );
}
return name;
}
}
else if ( role == Qt::DecorationRole && index.column() == 0 )
{
if ( QgsLayerTree::isGroup( node ) )
return iconGroup();
if ( QgsLayerTree::isLayer( node ) )
{
QgsLayerTreeLayer *nodeLayer = QgsLayerTree::toLayer( node );
QgsMapLayer *layer = nodeLayer->layer();
if ( !layer )
return QVariant();
// icons possibly overriding default icon
if ( layer->type() == QgsMapLayer::RasterLayer )
{
if ( testFlag( ShowRasterPreviewIcon ) )
{
QgsRasterLayer* rlayer = qobject_cast<QgsRasterLayer *>( layer );
return QIcon( QPixmap::fromImage( rlayer->previewAsImage( QSize( 32, 32 ) ) ) );
}
else
{
return QgsLayerItem::iconRaster();
}
}
QgsVectorLayer *vlayer = dynamic_cast<QgsVectorLayer*>( layer );
QIcon icon;
// if there's just on legend entry that should be embedded in layer - do that!
if ( testFlag( ShowLegend ) && legendEmbeddedInParent( nodeLayer ) )
{
icon = legendIconEmbeddedInParent( nodeLayer );
}
else if ( vlayer && layer->type() == QgsMapLayer::VectorLayer )
{
if ( vlayer->geometryType() == QGis::Point )
icon = QgsLayerItem::iconPoint();
else if ( vlayer->geometryType() == QGis::Line )
icon = QgsLayerItem::iconLine();
else if ( vlayer->geometryType() == QGis::Polygon )
icon = QgsLayerItem::iconPolygon();
else if ( vlayer->geometryType() == QGis::NoGeometry )
icon = QgsLayerItem::iconTable();
else
icon = QgsLayerItem::iconDefault();
}
if ( vlayer && vlayer->isEditable() )
{
QPixmap pixmap( icon.pixmap( 16, 16 ) );
QPainter painter( &pixmap );
painter.drawPixmap( 0, 0, 16, 16, QgsApplication::getThemePixmap( vlayer->isModified() ? "/mIconEditableEdits.png" : "/mIconEditable.png" ) );
painter.end();
icon = QIcon( pixmap );
}
return icon;
}
}
else if ( role == Qt::CheckStateRole )
{
if ( !testFlag( AllowNodeChangeVisibility ) )
return QVariant();
if ( QgsLayerTree::isLayer( node ) )
{
QgsLayerTreeLayer* nodeLayer = QgsLayerTree::toLayer( node );
if ( nodeLayer->layer() && nodeLayer->layer()->type() == QgsMapLayer::VectorLayer )
{
//.........这里部分代码省略.........
示例14: getFeature
//.........这里部分代码省略.........
}
catch ( QgsMapServiceException& e )
{
Q_UNUSED( e );
filterOk = false;
}
}
bool conversionSuccess;
double minx, miny, maxx, maxy;
bool bboxOk = false;
//read BBOX
QMap<QString, QString>::const_iterator bbIt = mParameterMap.find( "BBOX" );
if ( bbIt == mParameterMap.end() )
{
minx = 0; miny = 0; maxx = 0; maxy = 0;
}
else
{
bboxOk = true;
QString bbString = bbIt.value();
minx = bbString.section( ",", 0, 0 ).toDouble( &conversionSuccess );
if ( !conversionSuccess ) {bboxOk = false;}
miny = bbString.section( ",", 1, 1 ).toDouble( &conversionSuccess );
if ( !conversionSuccess ) {bboxOk = false;}
maxx = bbString.section( ",", 2, 2 ).toDouble( &conversionSuccess );
if ( !conversionSuccess ) {bboxOk = false;}
maxy = bbString.section( ",", 3, 3 ).toDouble( &conversionSuccess );
if ( !conversionSuccess ) {bboxOk = false;}
}
//read MAXFEATURES
long maxFeat = layer->featureCount();
long featureCounter = 0;
QMap<QString, QString>::const_iterator mfIt = mParameterMap.find( "MAXFEATURES" );
if ( mfIt != mParameterMap.end() )
{
QString mfString = mfIt.value();
bool mfOk;
maxFeat = mfString.toLong( &mfOk, 10 );
if ( !mfOk ) { maxFeat = layer->featureCount(); }
}
//read PROPERTYNAME
mWithGeom = true;
QgsAttributeList attrIndexes = provider->attributeIndexes();
QMap<QString, QString>::const_iterator pnIt = mParameterMap.find( "PROPERTYNAME" );
if ( pnIt != mParameterMap.end() )
{
QStringList attrList = pnIt.value().split( "," );
if ( attrList.size() > 0 )
{
mWithGeom = false;
QStringList::const_iterator alstIt;
QList<int> idxList;
QMap<QString, int> fieldMap = provider->fieldNameMap();
QMap<QString, int>::const_iterator fieldIt;
QString fieldName;
for ( alstIt = attrList.begin(); alstIt != attrList.end(); ++alstIt )
{
fieldName = *alstIt;
fieldIt = fieldMap.find( fieldName );
if ( fieldIt != fieldMap.end() )
{
idxList.append( fieldIt.value() );
示例15: makeGraph
void QgsLineVectorLayerDirector::makeGraph( QgsGraphBuilderInterface *builder, const QVector< QgsPoint >& additionalPoints,
QVector< QgsPoint >& tiedPoint ) const
{
QgsVectorLayer *vl = mVectorLayer;
if ( vl == NULL )
return;
int featureCount = ( int ) vl->featureCount() * 2;
int step = 0;
QgsCoordinateTransform ct;
ct.setSourceCrs( vl->crs() );
if ( builder->coordinateTransformationEnabled() )
{
ct.setDestCRS( builder->destinationCrs() );
}
else
{
ct.setDestCRS( vl->crs() );
}
tiedPoint = QVector< QgsPoint >( additionalPoints.size(), QgsPoint( 0.0, 0.0 ) );
TiePointInfo tmpInfo;
tmpInfo.mLength = std::numeric_limits<double>::infinity();
QVector< TiePointInfo > pointLengthMap( additionalPoints.size(), tmpInfo );
QVector< TiePointInfo >::iterator pointLengthIt;
//Graph's points;
QVector< QgsPoint > points;
QgsFeatureIterator fit = vl->getFeatures( QgsFeatureRequest().setSubsetOfAttributes( QgsAttributeList() ) );
// begin: tie points to the graph
QgsAttributeList la;
QgsFeature feature;
while ( fit.nextFeature( feature ) )
{
QgsMultiPolyline mpl;
if ( feature.constGeometry()->wkbType() == QGis::WKBMultiLineString )
mpl = feature.constGeometry()->asMultiPolyline();
else if ( feature.constGeometry()->wkbType() == QGis::WKBLineString )
mpl.push_back( feature.constGeometry()->asPolyline() );
QgsMultiPolyline::iterator mplIt;
for ( mplIt = mpl.begin(); mplIt != mpl.end(); ++mplIt )
{
QgsPoint pt1, pt2;
bool isFirstPoint = true;
QgsPolyline::iterator pointIt;
for ( pointIt = mplIt->begin(); pointIt != mplIt->end(); ++pointIt )
{
pt2 = ct.transform( *pointIt );
points.push_back( pt2 );
if ( !isFirstPoint )
{
int i = 0;
for ( i = 0; i != additionalPoints.size(); ++i )
{
TiePointInfo info;
if ( pt1 == pt2 )
{
info.mLength = additionalPoints[ i ].sqrDist( pt1 );
info.mTiedPoint = pt1;
}
else
{
info.mLength = additionalPoints[ i ].sqrDistToSegment( pt1.x(), pt1.y(),
pt2.x(), pt2.y(), info.mTiedPoint );
}
if ( pointLengthMap[ i ].mLength > info.mLength )
{
Q_UNUSED( info.mTiedPoint );
info.mFirstPoint = pt1;
info.mLastPoint = pt2;
pointLengthMap[ i ] = info;
tiedPoint[ i ] = info.mTiedPoint;
}
}
}
pt1 = pt2;
isFirstPoint = false;
}
}
emit buildProgress( ++step, featureCount );
}
// end: tie points to graph
// add tied point to graph
int i = 0;
for ( i = 0; i < tiedPoint.size(); ++i )
{
if ( tiedPoint[ i ] != QgsPoint( 0.0, 0.0 ) )
{
points.push_back( tiedPoint [ i ] );
//.........这里部分代码省略.........