本文整理汇总了C++中QgsVectorDataProvider::fieldNameIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ QgsVectorDataProvider::fieldNameIndex方法的具体用法?C++ QgsVectorDataProvider::fieldNameIndex怎么用?C++ QgsVectorDataProvider::fieldNameIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QgsVectorDataProvider
的用法示例。
在下文中一共展示了QgsVectorDataProvider::fieldNameIndex方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: director
const RgGraphDirector* RoadGraphPlugin::director() const
{
QString layerId;
QgsVectorLayer *layer = NULL;
QMap< QString, QgsMapLayer* > mapLayers = QgsMapLayerRegistry::instance()->mapLayers();
QMap< QString, QgsMapLayer* >::const_iterator it;
for ( it = mapLayers.begin(); it != mapLayers.end(); ++it )
{
if ( it.value()->name() != mSettings->mLayer )
continue;
layerId = it.key();
layer = dynamic_cast< QgsVectorLayer* >( it.value() );
break;
}
if ( layer == NULL )
return NULL;
QgsVectorDataProvider *provider = dynamic_cast< QgsVectorDataProvider* >( layer->dataProvider() );
if ( provider == NULL )
return NULL;
RgLineVectorLayerDirector * director =
new RgLineVectorLayerDirector( layerId,
provider->fieldNameIndex( mSettings->mDirection ),
mSettings->mFirstPointToLastPointDirectionVal,
mSettings->mLastPointToFirstPointDirectionVal,
mSettings->mBothDirectionVal,
mSettings->mDefaultDirection,
mSettings->mSpeedUnitName,
provider->fieldNameIndex( mSettings->mSpeed ),
mSettings->mDefaultSpeed );
return director;
}
示例2: readXML
int QgsUniqueValueRenderer::readXML( const QDomNode& rnode, QgsVectorLayer& vl )
{
mGeometryType = vl.geometryType();
QDomNode classnode = rnode.namedItem( "classificationfield" );
QString classificationField = classnode.toElement().text();
QgsVectorDataProvider* theProvider = vl.dataProvider();
if ( !theProvider )
{
return 1;
}
int classificationId = theProvider->fieldNameIndex( classificationField );
if ( classificationId == -1 )
{
//go on. Because with joins, it might be the joined layer is not loaded yet
}
setClassificationField( classificationId );
QDomNode symbolnode = rnode.namedItem( "symbol" );
while ( !symbolnode.isNull() )
{
QgsSymbol* msy = new QgsSymbol( mGeometryType );
msy->readXML( symbolnode, &vl );
insertValue( msy->lowerValue(), msy );
symbolnode = symbolnode.nextSibling();
}
updateSymbolAttributes();
vl.setRenderer( this );
return 0;
}
示例3: director
const QgsGraphDirector* RoadGraphPlugin::director() const
{
QgsVectorLayer *layer = nullptr;
QMap< QString, QgsMapLayer* > mapLayers = QgsMapLayerRegistry::instance()->mapLayers();
QMap< QString, QgsMapLayer* >::const_iterator it;
for ( it = mapLayers.begin(); it != mapLayers.end(); ++it )
{
if ( it.value()->name() != mSettings->mLayer )
continue;
layer = dynamic_cast< QgsVectorLayer* >( it.value() );
break;
}
if ( !layer )
return nullptr;
if ( layer->wkbType() == QGis::WKBLineString
|| layer->wkbType() == QGis::WKBMultiLineString )
{
QgsVectorDataProvider *provider = layer->dataProvider();
if ( !provider )
return nullptr;
SpeedUnit speedUnit = SpeedUnit::byName( mSettings->mSpeedUnitName );
QgsLineVectorLayerDirector * director =
new QgsLineVectorLayerDirector( layer,
provider->fieldNameIndex( mSettings->mDirection ),
mSettings->mFirstPointToLastPointDirectionVal,
mSettings->mLastPointToFirstPointDirectionVal,
mSettings->mBothDirectionVal,
mSettings->mDefaultDirection
);
director->addProperter( new QgsDistanceArcProperter() );
director->addProperter( new RgSpeedProperter( provider->fieldNameIndex( mSettings->mSpeed ),
mSettings->mDefaultSpeed, speedUnit.multipler() ) );
return director;
}
return nullptr;
}
示例4: readXML
int QgsGraduatedSymbolRenderer::readXML( const QDomNode& rnode, QgsVectorLayer& vl )
{
mGeometryType = vl.geometryType();
QDomNode modeNode = rnode.namedItem( "mode" );
QString modeValue = modeNode.toElement().text();
QDomNode classnode = rnode.namedItem( "classificationfield" );
QString classificationField = classnode.toElement().text();
QgsVectorDataProvider* theProvider = vl.dataProvider();
if ( !theProvider )
{
return 1;
}
if ( modeValue == "Empty" )
{
mMode = QgsGraduatedSymbolRenderer::Empty;
}
else if ( modeValue == "Quantile" )
{
mMode = QgsGraduatedSymbolRenderer::Quantile;
}
else //default
{
mMode = QgsGraduatedSymbolRenderer::EqualInterval;
}
int classificationId = theProvider->fieldNameIndex( classificationField );
if ( classificationId == -1 )
{
return 2; //@todo: handle gracefully in gui situation where user needs to nominate field
}
setClassificationField( classificationId );
QDomNode symbolnode = rnode.namedItem( "symbol" );
while ( !symbolnode.isNull() )
{
QgsSymbol* sy = new QgsSymbol( mGeometryType );
sy->readXML( symbolnode, &vl );
addSymbol( sy );
symbolnode = symbolnode.nextSibling();
}
updateSymbolAttributes();
vl.setRenderer( this );
return 0;
}
示例5: calculateStatistics
//.........这里部分代码省略.........
newFieldList.push_back( rangeField );
}
QString minorityFieldName;
if ( mStatistics & QgsZonalStatistics::Minority )
{
minorityFieldName = getUniqueFieldName( mAttributePrefix + "minority", newFieldList );
QgsField minorityField( minorityFieldName, QVariant::Double, QStringLiteral( "double precision" ) );
newFieldList.push_back( minorityField );
}
QString majorityFieldName;
if ( mStatistics & QgsZonalStatistics::Majority )
{
majorityFieldName = getUniqueFieldName( mAttributePrefix + "majority", newFieldList );
QgsField majField( majorityFieldName, QVariant::Double, QStringLiteral( "double precision" ) );
newFieldList.push_back( majField );
}
QString varietyFieldName;
if ( mStatistics & QgsZonalStatistics::Variety )
{
varietyFieldName = getUniqueFieldName( mAttributePrefix + "variety", newFieldList );
QgsField varietyField( varietyFieldName, QVariant::Int, QStringLiteral( "int" ) );
newFieldList.push_back( varietyField );
}
QString varianceFieldName;
if ( mStatistics & QgsZonalStatistics::Variance )
{
varianceFieldName = getUniqueFieldName( mAttributePrefix + "variance", newFieldList );
QgsField varianceField( varianceFieldName, QVariant::Double, QStringLiteral( "double precision" ) );
newFieldList.push_back( varianceField );
}
vectorProvider->addAttributes( newFieldList );
//index of the new fields
int countIndex = mStatistics & QgsZonalStatistics::Count ? vectorProvider->fieldNameIndex( countFieldName ) : -1;
int sumIndex = mStatistics & QgsZonalStatistics::Sum ? vectorProvider->fieldNameIndex( sumFieldName ) : -1;
int meanIndex = mStatistics & QgsZonalStatistics::Mean ? vectorProvider->fieldNameIndex( meanFieldName ) : -1;
int medianIndex = mStatistics & QgsZonalStatistics::Median ? vectorProvider->fieldNameIndex( medianFieldName ) : -1;
int stdevIndex = mStatistics & QgsZonalStatistics::StDev ? vectorProvider->fieldNameIndex( stdevFieldName ) : -1;
int minIndex = mStatistics & QgsZonalStatistics::Min ? vectorProvider->fieldNameIndex( minFieldName ) : -1;
int maxIndex = mStatistics & QgsZonalStatistics::Max ? vectorProvider->fieldNameIndex( maxFieldName ) : -1;
int rangeIndex = mStatistics & QgsZonalStatistics::Range ? vectorProvider->fieldNameIndex( rangeFieldName ) : -1;
int minorityIndex = mStatistics & QgsZonalStatistics::Minority ? vectorProvider->fieldNameIndex( minorityFieldName ) : -1;
int majorityIndex = mStatistics & QgsZonalStatistics::Majority ? vectorProvider->fieldNameIndex( majorityFieldName ) : -1;
int varietyIndex = mStatistics & QgsZonalStatistics::Variety ? vectorProvider->fieldNameIndex( varietyFieldName ) : -1;
int varianceIndex = mStatistics & QgsZonalStatistics::Variance ? vectorProvider->fieldNameIndex( varianceFieldName ) : -1;
if ( ( mStatistics & QgsZonalStatistics::Count && countIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Sum && sumIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Mean && meanIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Median && medianIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::StDev && stdevIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Min && minIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Max && maxIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Range && rangeIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Minority && minorityIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Majority && majorityIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Variety && varietyIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Variance && varianceIndex == -1 )
)
{
//failed to create a required field
return 8;
}
//progress dialog
long featureCount = vectorProvider->featureCount();
示例6: calculateStatistics
int QgsZonalStatistics::calculateStatistics( QProgressDialog* p )
{
if ( !mPolygonLayer || mPolygonLayer->geometryType() != QGis::Polygon )
{
return 1;
}
QgsVectorDataProvider* vectorProvider = mPolygonLayer->dataProvider();
if ( !vectorProvider )
{
return 2;
}
//open the raster layer and the raster band
GDALAllRegister();
GDALDatasetH inputDataset = GDALOpen( mRasterFilePath.toLocal8Bit().data(), GA_ReadOnly );
if ( inputDataset == NULL )
{
return 3;
}
if ( GDALGetRasterCount( inputDataset ) < ( mRasterBand - 1 ) )
{
GDALClose( inputDataset );
return 4;
}
GDALRasterBandH rasterBand = GDALGetRasterBand( inputDataset, mRasterBand );
if ( rasterBand == NULL )
{
GDALClose( inputDataset );
return 5;
}
mInputNodataValue = GDALGetRasterNoDataValue( rasterBand, NULL );
//get geometry info about raster layer
int nCellsX = GDALGetRasterXSize( inputDataset );
int nCellsY = GDALGetRasterYSize( inputDataset );
double geoTransform[6];
if ( GDALGetGeoTransform( inputDataset, geoTransform ) != CE_None )
{
GDALClose( inputDataset );
return 6;
}
double cellsizeX = geoTransform[1];
if ( cellsizeX < 0 )
{
cellsizeX = -cellsizeX;
}
double cellsizeY = geoTransform[5];
if ( cellsizeY < 0 )
{
cellsizeY = -cellsizeY;
}
QgsRectangle rasterBBox( geoTransform[0], geoTransform[3] - ( nCellsY * cellsizeY ), geoTransform[0] + ( nCellsX * cellsizeX ), geoTransform[3] );
//add the new count, sum, mean fields to the provider
QList<QgsField> newFieldList;
QgsField countField( mAttributePrefix + "count", QVariant::Double );
QgsField sumField( mAttributePrefix + "sum", QVariant::Double );
QgsField meanField( mAttributePrefix + "mean", QVariant::Double );
newFieldList.push_back( countField );
newFieldList.push_back( sumField );
newFieldList.push_back( meanField );
if ( !vectorProvider->addAttributes( newFieldList ) )
{
return 7;
}
//index of the new fields
int countIndex = vectorProvider->fieldNameIndex( mAttributePrefix + "count" );
int sumIndex = vectorProvider->fieldNameIndex( mAttributePrefix + "sum" );
int meanIndex = vectorProvider->fieldNameIndex( mAttributePrefix + "mean" );
if ( countIndex == -1 || sumIndex == -1 || meanIndex == -1 )
{
return 8;
}
//progress dialog
long featureCount = vectorProvider->featureCount();
if ( p )
{
p->setMaximum( featureCount );
}
//iterate over each polygon
vectorProvider->select( QgsAttributeList(), QgsRectangle(), true, false );
vectorProvider->rewind();
QgsFeature f;
double count = 0;
double sum = 0;
double mean = 0;
int featureCounter = 0;
while ( vectorProvider->nextFeature( f ) )
{
qWarning( "%d", featureCounter );
if ( p )
//.........这里部分代码省略.........
示例7: createMapLayer
QgsMapLayer* QgsInterpolationLayerBuilder::createMapLayer( const QDomElement& elem, const QString& layerName, QList<QTemporaryFile*>& filesToRemove, QList<QgsMapLayer*>& layersToRemove, bool allowCaching ) const
{
if ( !mVectorLayer )
{
return 0;
}
QDomNodeList interpolationList = elem.elementsByTagName( "Interpolation" );
if ( interpolationList.size() < 1 )
{
QgsMSDebugMsg( "No Interpolation element found" );
return 0;
}
QDomElement interpolationElem = interpolationList.at( 0 ).toElement();
//create QgsInterpolator object from XML
QDomNodeList tinList = interpolationElem.elementsByTagName( "TINMethod" );
QDomNodeList idwList = interpolationElem.elementsByTagName( "IDWMethod" );
QgsInterpolator* theInterpolator = 0;
QList<QgsInterpolator::LayerData> layerDataList;
QgsInterpolator::LayerData currentLayerData;
currentLayerData.vectorLayer = mVectorLayer;
QDomNodeList propertyNameList = interpolationElem.elementsByTagName( "PropertyName" );
if ( propertyNameList.size() < 1 )
{
currentLayerData.zCoordInterpolation = true;
}
else
{
currentLayerData.zCoordInterpolation = false;
//set attribute field interpolation or z-Coordinate interpolation
QString attributeName = propertyNameList.at( 0 ).toElement().text();
QgsVectorDataProvider* provider = mVectorLayer->dataProvider();
if ( !provider )
{
return 0;
}
int attributeIndex = provider->fieldNameIndex( attributeName );
if ( attributeIndex == -1 )
{
return 0; //attribute field not found
}
currentLayerData.interpolationAttribute = attributeIndex;
}
currentLayerData.mInputType = QgsInterpolator::POINTS;
layerDataList.push_back( currentLayerData );
if ( idwList.size() > 0 ) //inverse distance interpolator
{
theInterpolator = new QgsIDWInterpolator( layerDataList );
//todo: parse <DistanceWeightingCoefficient>
}
else //tin is default
{
theInterpolator = new QgsTINInterpolator( layerDataList );
//todo: parse <InterpolationFunction>
}
//Resolution
int nCols, nRows;
QDomNodeList resolutionNodeList = elem.elementsByTagName( "Resolution" );
if ( resolutionNodeList.size() < 1 )
{
//use default values...
nCols = 100;
nRows = 100;
}
else
{
QDomElement resolutionElem = resolutionNodeList.at( 0 ).toElement();
nCols = resolutionElem.attribute( "ncols" ).toInt();
nRows = resolutionElem.attribute( "nrows" ).toInt();
if ( nCols == 0 && nRows == 0 )
{
QgsMSDebugMsg( "Reading of resolution failed" );
return 0;
}
}
QTemporaryFile* tmpFile = new QTemporaryFile();
if ( !tmpFile->open() )
{
delete tmpFile;
}
QgsRectangle extent = mVectorLayer->extent();
QgsGridFileWriter gridWriter( theInterpolator, tmpFile->fileName(), extent, nCols, nRows, extent.width() / nCols, extent.height() / nRows );
if ( gridWriter.writeFile( false ) != 0 )
{
QgsMSDebugMsg( "Interpolation of raster failed" );
return 0;
}
filesToRemove.push_back( tmpFile ); //store raster in temporary file and remove after request
QgsRasterLayer* theRaster = new QgsRasterLayer( tmpFile->fileName() );
//.........这里部分代码省略.........
示例8: apply
void qgis_dev_layerPropDialog::apply()
{
QSettings().setValue( "/Windows/VectorLayerProperties/diagram/tab",
mDiagramPropertiesTabWidget->currentIndex() );
if ( !mDisplayDiagramsGroupBox->isChecked() ) {m_layer->setDiagramRenderer( 0 ); return;}
QgsDiagram* diagram = 0;
int index = diagramType_comboBox->currentIndex();
QString diagramType = diagramType_comboBox->itemData( index ).toString();
if ( 0 == mDiagramAttributesTreeWidget->topLevelItemCount() )
{
qgis_dev::instance()->messageBar()->pushMessage(
tr( "Diagrams: No attributes added." ),
tr( "You did not add any attributes to this diagram layer. Please specify the attributes to visualize on the diagrams or disable diagrams." ),
QgsMessageBar::WARNING );
}
bool scaleAttributeValueOk = false;
// Check if a (usable) scale attribute value is inserted
mValueLineEdit->text().toDouble( &scaleAttributeValueOk );
if ( !mFixedSizeCheckBox->isChecked() && !scaleAttributeValueOk )
{
double maxVal = DBL_MIN;
QgsVectorDataProvider* provider = m_layer->dataProvider();
if ( provider )
{
if ( diagramType == DIAGRAM_NAME_HISTOGRAM )
{
// Find maximum value
for ( int i = 0; i < mDiagramAttributesTreeWidget->topLevelItemCount(); ++i )
{
QString fldName = mDiagramAttributesTreeWidget->topLevelItem( i )->data( 0, Qt::UserRole ).toString();
if ( fldName.count() >= 2 && fldName.at( 0 ) == '"' && fldName.at( fldName.count() - 1 ) == '"' )
{
fldName = fldName.mid( 1, fldName.count() - 2 ); // remove enclosing double quotes
}
int fld = provider->fieldNameIndex( fldName );
if ( fld != -1 )
{
bool ok = false;
double val = provider->maximumValue( fld ).toDouble( &ok );
if ( ok )
{
maxVal = qMax( maxVal, val );
}
}
}
}
else
{
maxVal = provider->maximumValue( mSizeAttributeComboBox->itemData( mSizeAttributeComboBox->currentIndex() ).toInt() ).toDouble();
}
}
if ( maxVal != DBL_MIN )
{
qgis_dev::instance()->messageBar()->pushMessage(
tr( "Interpolation value" ),
tr( "You did not specify an interpolation value. A default value of %1 has been set." ).arg( QString::number( maxVal ) ),
QgsMessageBar::INFO,
5 );
mValueLineEdit->setText( QString::number( maxVal ) );
}
}
if ( diagramType == DIAGRAM_NAME_TEXT )
{
diagram = new QgsTextDiagram();
}
else if ( diagramType == DIAGRAM_NAME_PIE )
{
diagram = new QgsPieDiagram();
}
else // if ( diagramType == DIAGRAM_NAME_HISTOGRAM )
{
diagram = new QgsHistogramDiagram();
}
QgsDiagramSettings ds;
ds.font = font_comboBox->currentFont(); // 字体
ds.transparency = mTransparencySlider->value(); // 透明度
QList<QColor> categoryColors;
QList<QString> categoryAttributes;
for ( int i = 0; i < mDiagramAttributesTreeWidget->topLevelItemCount(); ++i )
{
QColor color = mDiagramAttributesTreeWidget->topLevelItem( i )->background( 1 ).color();
color.setAlpha( 255 - ds.transparency );
categoryColors.append( color );
categoryAttributes.append( mDiagramAttributesTreeWidget->topLevelItem( i )->data( 0, Qt::UserRole ).toString() );
}
ds.categoryColors = categoryColors;
ds.categoryAttributes = categoryAttributes;
//ds.size = QSizeF( mDiagramSizeSpinBox->value(), mDiagramSizeSpinBox->value() );
ds.size = QSizeF( 50, 50 );
//ds.sizeType = static_cast<QgsDiagramSettings::SizeType>( mDiagramUnitComboBox->itemData( mDiagramUnitComboBox->currentIndex() ).toInt() );
//.........这里部分代码省略.........
示例9: calculateStatistics
//.........这里部分代码省略.........
newFieldList.push_back( maxField );
}
QString rangeFieldName;
if ( mStatistics & QgsZonalStatistics::Range )
{
rangeFieldName = getUniqueFieldName( mAttributePrefix + "range" );
QgsField rangeField( rangeFieldName, QVariant::Double, "double precision" );
newFieldList.push_back( rangeField );
}
QString minorityFieldName;
if ( mStatistics & QgsZonalStatistics::Minority )
{
minorityFieldName = getUniqueFieldName( mAttributePrefix + "minority" );
QgsField minorityField( minorityFieldName, QVariant::Double, "double precision" );
newFieldList.push_back( minorityField );
}
QString majorityFieldName;
if ( mStatistics & QgsZonalStatistics::Majority )
{
majorityFieldName = getUniqueFieldName( mAttributePrefix + "majority" );
QgsField majField( majorityFieldName, QVariant::Double, "double precision" );
newFieldList.push_back( majField );
}
QString varietyFieldName;
if ( mStatistics & QgsZonalStatistics::Variety )
{
varietyFieldName = getUniqueFieldName( mAttributePrefix + "variety" );
QgsField varietyField( varietyFieldName, QVariant::Int, "int" );
newFieldList.push_back( varietyField );
}
vectorProvider->addAttributes( newFieldList );
//index of the new fields
int countIndex = mStatistics & QgsZonalStatistics::Count ? vectorProvider->fieldNameIndex( countFieldName ) : -1;
int sumIndex = mStatistics & QgsZonalStatistics::Sum ? vectorProvider->fieldNameIndex( sumFieldName ) : -1;
int meanIndex = mStatistics & QgsZonalStatistics::Mean ? vectorProvider->fieldNameIndex( meanFieldName ) : -1;
int medianIndex = mStatistics & QgsZonalStatistics::Median ? vectorProvider->fieldNameIndex( medianFieldName ) : -1;
int stdevIndex = mStatistics & QgsZonalStatistics::StDev ? vectorProvider->fieldNameIndex( stdevFieldName ) : -1;
int minIndex = mStatistics & QgsZonalStatistics::Min ? vectorProvider->fieldNameIndex( minFieldName ) : -1;
int maxIndex = mStatistics & QgsZonalStatistics::Max ? vectorProvider->fieldNameIndex( maxFieldName ) : -1;
int rangeIndex = mStatistics & QgsZonalStatistics::Range ? vectorProvider->fieldNameIndex( rangeFieldName ) : -1;
int minorityIndex = mStatistics & QgsZonalStatistics::Minority ? vectorProvider->fieldNameIndex( minorityFieldName ) : -1;
int majorityIndex = mStatistics & QgsZonalStatistics::Majority ? vectorProvider->fieldNameIndex( majorityFieldName ) : -1;
int varietyIndex = mStatistics & QgsZonalStatistics::Variety ? vectorProvider->fieldNameIndex( varietyFieldName ) : -1;
if (( mStatistics & QgsZonalStatistics::Count && countIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Sum && sumIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Mean && meanIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Median && medianIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::StDev && stdevIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Min && minIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Max && maxIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Range && rangeIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Minority && minorityIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Majority && majorityIndex == -1 )
|| ( mStatistics & QgsZonalStatistics::Variety && varietyIndex == -1 )
)
{
//failed to create a required field
return 8;
}
//progress dialog
long featureCount = vectorProvider->featureCount();
if ( p )
{
示例10: on_buttonBox_accepted
void QgsInterpolationDialog::on_buttonBox_accepted()
{
if ( !mInterpolatorDialog )
{
return;
}
QgsRectangle outputBBox = currentBoundingBox();
if ( outputBBox.isEmpty() )
{
return;
}
//warn the user if there isn't any input layer
if ( mLayersTreeWidget->topLevelItemCount() < 1 )
{
QMessageBox::information( nullptr, tr( "No input data for interpolation" ), tr( "Please add one or more input layers" ) );
return;
}
//read file name
QString fileName = mOutputFileLineEdit->text();
QFileInfo theFileInfo( fileName );
if ( fileName.isEmpty() || !theFileInfo.dir().exists() )
{
QMessageBox::information( nullptr, tr( "Output file name invalid" ), tr( "Please enter a valid output file name" ) );
return;
}
//add .asc suffix if the user did not provider it already
QString suffix = theFileInfo.suffix();
if ( suffix.isEmpty() )
{
fileName.append( ".asc" );
}
int nLayers = mLayersTreeWidget->topLevelItemCount();
QList< QgsInterpolator::LayerData > inputLayerList;
for ( int i = 0; i < nLayers; ++i )
{
QString layerName = mLayersTreeWidget->topLevelItem( i )->text( 0 );
QgsVectorLayer* theVectorLayer = vectorLayerFromName( layerName );
if ( !theVectorLayer )
{
continue;
}
QgsVectorDataProvider* theProvider = theVectorLayer->dataProvider();
if ( !theProvider )
{
continue;
}
QgsInterpolator::LayerData currentLayerData;
currentLayerData.vectorLayer = theVectorLayer;
QString interpolationAttString = mLayersTreeWidget->topLevelItem( i )->text( 1 );
if ( interpolationAttString == "Z_COORD" )
{
currentLayerData.zCoordInterpolation = true;
currentLayerData.interpolationAttribute = -1;
}
else
{
currentLayerData.zCoordInterpolation = false;
int attributeIndex = theProvider->fieldNameIndex( interpolationAttString );
currentLayerData.interpolationAttribute = attributeIndex;
}
//type (point/structure line/ breakline)
QComboBox* itemCombo = qobject_cast<QComboBox *>( mLayersTreeWidget->itemWidget( mLayersTreeWidget->topLevelItem( i ), 2 ) );
if ( itemCombo )
{
QString typeString = itemCombo->currentText();
if ( typeString == tr( "Break lines" ) )
{
currentLayerData.mInputType = QgsInterpolator::BREAK_LINES;
}
else if ( typeString == tr( "Structure lines" ) )
{
currentLayerData.mInputType = QgsInterpolator::STRUCTURE_LINES;
}
else //Points
{
currentLayerData.mInputType = QgsInterpolator::POINTS;
}
}
else
{
currentLayerData.mInputType = QgsInterpolator::POINTS;
}
inputLayerList.push_back( currentLayerData );
}
mInterpolatorDialog->setInputData( inputLayerList );
QgsInterpolator* theInterpolator = mInterpolatorDialog->createInterpolator();
if ( !theInterpolator )
{
//.........这里部分代码省略.........