本文整理汇总了C++中QgsVectorLayer::allFeatureIds方法的典型用法代码示例。如果您正苦于以下问题:C++ QgsVectorLayer::allFeatureIds方法的具体用法?C++ QgsVectorLayer::allFeatureIds怎么用?C++ QgsVectorLayer::allFeatureIds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QgsVectorLayer
的用法示例。
在下文中一共展示了QgsVectorLayer::allFeatureIds方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: run
void QgsGeometrySnapperDialog::run()
{
/** Get layers **/
QgsVectorLayer* layer = getInputLayer();
QgsVectorLayer* referenceLayer = getReferenceLayer();
if ( layer == 0 || referenceLayer == 0 )
{
return;
}
if ( ui.radioButtonOutputNew->isChecked() &&
( layer->dataProvider()->dataSourceUri().startsWith( ui.lineEditOutput->text() ) ||
referenceLayer->dataProvider()->dataSourceUri().startsWith( ui.lineEditOutput->text() ) ) )
{
QMessageBox::critical( this, tr( "Invalid Output Layer" ), tr( "The chosen output layer is the same as an input layer." ) );
return;
}
bool selectedOnly = ui.checkBoxInputSelectedOnly->isChecked();
/** Duplicate if necessary **/
if ( ui.radioButtonOutputNew->isChecked() )
{
QString filename = ui.lineEditOutput->text();
// Remove existing layer with same uri
QStringList toRemove;
foreach ( QgsMapLayer* maplayer, QgsMapLayerRegistry::instance()->mapLayers() )
{
if ( dynamic_cast<QgsVectorLayer*>( maplayer ) &&
static_cast<QgsVectorLayer*>( maplayer )->dataProvider()->dataSourceUri().startsWith( filename ) )
{
toRemove.append( maplayer->id() );
}
}
if ( !toRemove.isEmpty() )
{
QgsMapLayerRegistry::instance()->removeMapLayers( toRemove );
}
QString errMsg;
QgsVectorFileWriter::WriterError err = QgsVectorFileWriter::writeAsVectorFormat( layer, filename, layer->dataProvider()->encoding(), &layer->crs(), mOutputDriverName, selectedOnly, &errMsg );
if ( err != QgsVectorFileWriter::NoError )
{
QMessageBox::critical( this, tr( "Layer Creation Failed" ), tr( "Failed to create the output layer: %1" ).arg( errMsg ) );
return;
}
QgsVectorLayer* newlayer = new QgsVectorLayer( filename, QFileInfo( filename ).completeBaseName(), "ogr" );
if ( selectedOnly )
{
QgsFeature feature;
// Get features to select (only selected features were written up to this point)
QgsFeatureIds selectedFeatures = newlayer->allFeatureIds();
// Write non-selected feature ids
QgsFeatureList features;
QgsFeatureIterator it = layer->getFeatures();
while ( it.nextFeature( feature ) )
{
if ( !layer->selectedFeaturesIds().contains( feature.id() ) )
{
features.append( feature );
}
}
newlayer->dataProvider()->addFeatures( features );
// Set selected features
newlayer->setSelectedFeatures( selectedFeatures );
}
layer = newlayer;
}
示例2: runChecks
void QgsGeometryCheckerSetupTab::runChecks()
{
// Get selected layer
QList<QgsVectorLayer *> layers = getSelectedLayers();
if ( layers.isEmpty() )
return;
if ( ui.radioButtonOutputNew->isChecked() )
{
for ( QgsVectorLayer *layer : layers )
{
if ( layer->dataProvider()->dataSourceUri().startsWith( ui.lineEditOutputDirectory->text() ) )
{
QMessageBox::critical( this, tr( "Invalid Output Directory" ), tr( "The chosen output directory contains one or more input layers." ) );
return;
}
}
}
QgsVectorLayer *lineLayerCheckLayer = ui.comboLineLayerIntersection->isEnabled() ? dynamic_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( ui.comboLineLayerIntersection->currentData().toString() ) ) : nullptr;
QgsVectorLayer *followBoundaryCheckLayer = ui.comboBoxFollowBoundaries->isEnabled() ? dynamic_cast<QgsVectorLayer *>( QgsProject::instance()->mapLayer( ui.comboBoxFollowBoundaries->currentData().toString() ) ) : nullptr;
if ( layers.contains( lineLayerCheckLayer ) || layers.contains( followBoundaryCheckLayer ) )
{
QMessageBox::critical( this, tr( "Error" ), tr( "The test layer set contains a layer selected for a topology check." ) );
return;
}
for ( QgsVectorLayer *layer : layers )
{
if ( layer->isEditable() )
{
QMessageBox::critical( this, tr( "Editable Input Layer" ), tr( "Input layer are not allowed to be in editing mode." ) );
return;
}
}
bool selectedOnly = ui.checkBoxInputSelectedOnly->isChecked();
// Set window busy
setCursor( Qt::WaitCursor );
mRunButton->setEnabled( false );
ui.labelStatus->setText( tr( "<b>Preparing output...</b>" ) );
ui.labelStatus->show();
QApplication::processEvents( QEventLoop::ExcludeUserInputEvents );
QList<QgsVectorLayer *> processLayers;
if ( ui.radioButtonOutputNew->isChecked() )
{
// Get output directory and file extension
QDir outputDir = QDir( ui.lineEditOutputDirectory->text() );
QString outputDriverName = ui.comboBoxOutputFormat->currentText();
QgsVectorFileWriter::MetaData metadata;
if ( !QgsVectorFileWriter::driverMetadata( outputDriverName, metadata ) )
{
QMessageBox::critical( this, tr( "Unknown Output Format" ), tr( "The specified output format cannot be recognized." ) );
mRunButton->setEnabled( true );
ui.labelStatus->hide();
unsetCursor();
return;
}
QString outputExtension = metadata.ext;
// List over input layers, check which existing project layers need to be removed and create output layers
QString filenamePrefix = ui.lineEditFilenamePrefix->text();
QSettings().setValue( "/geometry_checker/previous_values/filename_prefix", filenamePrefix );
QStringList toRemove;
QStringList createErrors;
for ( QgsVectorLayer *layer : layers )
{
QString outputPath = outputDir.absoluteFilePath( filenamePrefix + layer->name() + "." + outputExtension );
// Remove existing layer with same uri from project
for ( QgsVectorLayer *projectLayer : QgsProject::instance()->layers<QgsVectorLayer *>() )
{
if ( projectLayer->dataProvider()->dataSourceUri().startsWith( outputPath ) )
{
toRemove.append( projectLayer->id() );
}
}
// Create output layer
QString errMsg;
QgsVectorFileWriter::WriterError err = QgsVectorFileWriter::writeAsVectorFormat( layer, outputPath, layer->dataProvider()->encoding(), layer->crs(), outputDriverName, selectedOnly, &errMsg );
if ( err != QgsVectorFileWriter::NoError )
{
createErrors.append( errMsg );
continue;
}
QgsVectorLayer *newlayer = new QgsVectorLayer( outputPath, QFileInfo( outputPath ).completeBaseName(), QStringLiteral( "ogr" ) );
if ( selectedOnly )
{
QgsFeature feature;
// Get features to select (only selected features were written up to this point)
QgsFeatureIds selectedFeatures = newlayer->allFeatureIds();
// Write non-selected feature ids
QgsFeatureList features;
QgsFeatureIterator it = layer->getFeatures();
while ( it.nextFeature( feature ) )
{
//.........这里部分代码省略.........
示例3: cadCanvasReleaseEvent
void QgsMapToolReshape::cadCanvasReleaseEvent( QgsMapMouseEvent * e )
{
//check if we operate on a vector layer //todo: move this to a function in parent class to avoid duplication
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() );
if ( !vlayer )
{
notifyNotVectorLayer();
return;
}
if ( !vlayer->isEditable() )
{
notifyNotEditableLayer();
return;
}
//add point to list and to rubber band
if ( e->button() == Qt::LeftButton )
{
int error = addVertex( e->mapPoint(), e->mapPointMatch() );
if ( error == 1 )
{
//current layer is not a vector layer
return;
}
else if ( error == 2 )
{
//problem with coordinate transformation
emit messageEmitted( tr( "Cannot transform the point to the layers coordinate system" ), QgsMessageBar::WARNING );
return;
}
startCapturing();
}
else if ( e->button() == Qt::RightButton )
{
deleteTempRubberBand();
//find out bounding box of mCaptureList
if ( size() < 1 )
{
stopCapturing();
return;
}
QgsPoint firstPoint = points().at( 0 );
QgsRectangle bbox( firstPoint.x(), firstPoint.y(), firstPoint.x(), firstPoint.y() );
for ( int i = 1; i < size(); ++i )
{
bbox.combineExtentWith( points().at( i ).x(), points().at( i ).y() );
}
//query all the features that intersect bounding box of capture line
QgsFeatureIterator fit = vlayer->getFeatures( QgsFeatureRequest().setFilterRect( bbox ).setSubsetOfAttributes( QgsAttributeList() ) );
QgsFeature f;
int reshapeReturn;
bool reshapeDone = false;
vlayer->beginEditCommand( tr( "Reshape" ) );
while ( fit.nextFeature( f ) )
{
//query geometry
//call geometry->reshape(mCaptureList)
//register changed geometry in vector layer
QgsGeometry* geom = f.geometry();
if ( geom )
{
reshapeReturn = geom->reshapeGeometry( points() );
if ( reshapeReturn == 0 )
{
//avoid intersections on polygon layers
if ( vlayer->geometryType() == QGis::Polygon )
{
//ignore all current layer features as they should be reshaped too
QMap<QgsVectorLayer*, QSet<QgsFeatureId> > ignoreFeatures;
ignoreFeatures.insert( vlayer, vlayer->allFeatureIds() );
if ( geom->avoidIntersections( ignoreFeatures ) != 0 )
{
emit messageEmitted( tr( "An error was reported during intersection removal" ), QgsMessageBar::CRITICAL );
vlayer->destroyEditCommand();
stopCapturing();
return;
}
if ( geom->isGeosEmpty() ) //intersection removal might have removed the whole geometry
{
emit messageEmitted( tr( "The feature cannot be reshaped because the resulting geometry is empty" ), QgsMessageBar::CRITICAL );
vlayer->destroyEditCommand();
stopCapturing();
return;
}
}
vlayer->changeGeometry( f.id(), geom );
reshapeDone = true;
}
}
}
//.........这里部分代码省略.........