本文整理汇总了C++中QgsVectorDataProvider::wkbType方法的典型用法代码示例。如果您正苦于以下问题:C++ QgsVectorDataProvider::wkbType方法的具体用法?C++ QgsVectorDataProvider::wkbType怎么用?C++ QgsVectorDataProvider::wkbType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QgsVectorDataProvider
的用法示例。
在下文中一共展示了QgsVectorDataProvider::wkbType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: on_mInputLayerComboBox_currentIndexChanged
void QgsInterpolationDialog::on_mInputLayerComboBox_currentIndexChanged( const QString& text )
{
Q_UNUSED( text );
mInterpolationAttributeComboBox->clear();
mUseZCoordCheckBox->setEnabled( false );
//get current vector layer
QString currentComboText = mInputLayerComboBox->currentText();
QgsVectorLayer* theVectorLayer = vectorLayerFromName( currentComboText );
if ( !theVectorLayer )
{
return;
}
QgsVectorDataProvider* provider = theVectorLayer->dataProvider();
if ( !provider )
{
return;
}
//find out if the layer has 25D type
QgsWkbTypes::Type geomType = provider->wkbType();
if ( geomType == QgsWkbTypes::Point25D ||
geomType == QgsWkbTypes::LineString25D ||
geomType == QgsWkbTypes::Polygon25D ||
geomType == QgsWkbTypes::MultiPoint25D ||
geomType == QgsWkbTypes::MultiLineString25D ||
geomType == QgsWkbTypes::MultiPolygon25D )
{
mUseZCoordCheckBox->setEnabled( true );
}
//insert numeric attributes of layer into mInterpolationAttributesComboBox
Q_FOREACH ( const QgsField& currentField, provider->fields() )
{
QVariant::Type currentType = currentField.type();
if ( currentType == QVariant::Int || currentType == QVariant::Double )
{
mInterpolationAttributeComboBox->insertItem( 0, currentField.name() );
}
}
}
示例2: dissolve
bool QgsGeometryAnalyzer::dissolve( QgsVectorLayer* layer, const QString& shapefileName,
bool onlySelectedFeatures, int uniqueIdField, QProgressDialog* p )
{
if ( !layer )
{
return false;
}
QgsVectorDataProvider* dp = layer->dataProvider();
if ( !dp )
{
return false;
}
bool useField = false;
if ( uniqueIdField == -1 )
{
uniqueIdField = 0;
}
else
{
useField = true;
}
QgsWkbTypes::Type outputType = dp->wkbType();
QgsCoordinateReferenceSystem crs = layer->crs();
QgsVectorFileWriter vWriter( shapefileName, dp->encoding(), layer->fields(), outputType, crs );
QgsFeature currentFeature;
QMultiMap<QString, QgsFeatureId> map;
if ( onlySelectedFeatures )
{
//use QgsVectorLayer::featureAtId
const QgsFeatureIds selection = layer->selectedFeaturesIds();
QgsFeatureIds::const_iterator it = selection.constBegin();
for ( ; it != selection.constEnd(); ++it )
{
if ( !layer->getFeatures( QgsFeatureRequest().setFilterFid( *it ) ).nextFeature( currentFeature ) )
{
continue;
}
map.insert( currentFeature.attribute( uniqueIdField ).toString(), currentFeature.id() );
}
}
else
{
QgsFeatureIterator fit = layer->getFeatures();
while ( fit.nextFeature( currentFeature ) )
{
map.insert( currentFeature.attribute( uniqueIdField ).toString(), currentFeature.id() );
}
}
QgsGeometry dissolveGeometry; //dissolve geometry
QMultiMap<QString, QgsFeatureId>::const_iterator jt = map.constBegin();
QgsFeature outputFeature;
while ( jt != map.constEnd() )
{
QString currentKey = jt.key();
int processedFeatures = 0;
bool first = true;
//take only selection
if ( onlySelectedFeatures )
{
//use QgsVectorLayer::featureAtId
const QgsFeatureIds selection = layer->selectedFeaturesIds();
if ( p )
{
p->setMaximum( selection.size() );
}
while ( jt != map.constEnd() && ( jt.key() == currentKey || !useField ) )
{
if ( p && p->wasCanceled() )
{
break;
}
if ( selection.contains( jt.value() ) )
{
if ( p )
{
p->setValue( processedFeatures );
}
if ( !layer->getFeatures( QgsFeatureRequest().setFilterFid( jt.value() ) ).nextFeature( currentFeature ) )
{
continue;
}
if ( first )
{
outputFeature.setAttributes( currentFeature.attributes() );
first = false;
}
dissolveGeometry = dissolveFeature( currentFeature, dissolveGeometry );
++processedFeatures;
}
++jt;
}
}
//take all features
else
{
int featureCount = layer->featureCount();
//.........这里部分代码省略.........
示例3: simplify
bool QgsGeometryAnalyzer::simplify( QgsVectorLayer* layer,
const QString& shapefileName,
double tolerance,
bool onlySelectedFeatures,
QProgressDialog *p )
{
if ( !layer )
{
return false;
}
QgsVectorDataProvider* dp = layer->dataProvider();
if ( !dp )
{
return false;
}
QgsWkbTypes::Type outputType = dp->wkbType();
QgsCoordinateReferenceSystem crs = layer->crs();
QgsVectorFileWriter vWriter( shapefileName, dp->encoding(), layer->fields(), outputType, crs );
QgsFeature currentFeature;
//take only selection
if ( onlySelectedFeatures )
{
//use QgsVectorLayer::featureAtId
const QgsFeatureIds selection = layer->selectedFeaturesIds();
if ( p )
{
p->setMaximum( selection.size() );
}
int processedFeatures = 0;
QgsFeatureIds::const_iterator it = selection.constBegin();
for ( ; it != selection.constEnd(); ++it )
{
if ( p )
{
p->setValue( processedFeatures );
}
if ( p && p->wasCanceled() )
{
break;
}
if ( !layer->getFeatures( QgsFeatureRequest().setFilterFid( *it ) ).nextFeature( currentFeature ) )
{
continue;
}
simplifyFeature( currentFeature, &vWriter, tolerance );
++processedFeatures;
}
if ( p )
{
p->setValue( selection.size() );
}
}
//take all features
else
{
QgsFeatureIterator fit = layer->getFeatures();
int featureCount = layer->featureCount();
if ( p )
{
p->setMaximum( featureCount );
}
int processedFeatures = 0;
while ( fit.nextFeature( currentFeature ) )
{
if ( p )
{
p->setValue( processedFeatures );
}
if ( p && p->wasCanceled() )
{
break;
}
simplifyFeature( currentFeature, &vWriter, tolerance );
++processedFeatures;
}
if ( p )
{
p->setValue( featureCount );
}
}
return true;
}
示例4: intersection
bool QgsOverlayAnalyzer::intersection( QgsVectorLayer* layerA, QgsVectorLayer* layerB,
const QString& shapefileName, bool onlySelectedFeatures,
QProgressDialog* p )
{
if ( !layerA || !layerB )
{
return false;
}
QgsVectorDataProvider *dpA = layerA->dataProvider();
QgsVectorDataProvider *dpB = layerB->dataProvider();
if ( !dpA || !dpB )
{
return false;
}
QgsWkbTypes::Type outputType = dpA->wkbType();
QgsCoordinateReferenceSystem crs = layerA->crs();
QgsFields fieldsA = layerA->fields();
QgsFields fieldsB = layerB->fields();
combineFieldLists( fieldsA, fieldsB );
QgsVectorFileWriter vWriter( shapefileName, dpA->encoding(), fieldsA, outputType, crs );
QgsFeature currentFeature;
QgsSpatialIndex index;
//take only selection
if ( onlySelectedFeatures )
{
const QgsFeatureIds selectionB = layerB->selectedFeaturesIds();
QgsFeatureIds::const_iterator it = selectionB.constBegin();
for ( ; it != selectionB.constEnd(); ++it )
{
if ( !layerB->getFeatures( QgsFeatureRequest().setFilterFid( *it ) ).nextFeature( currentFeature ) )
{
continue;
}
index.insertFeature( currentFeature );
}
//use QgsVectorLayer::featureAtId
const QgsFeatureIds selectionA = layerA->selectedFeaturesIds();
if ( p )
{
p->setMaximum( selectionA.size() );
}
QgsFeature currentFeature;
int processedFeatures = 0;
it = selectionA.constBegin();
for ( ; it != selectionA.constEnd(); ++it )
{
if ( p )
{
p->setValue( processedFeatures );
}
if ( p && p->wasCanceled() )
{
break;
}
if ( !layerA->getFeatures( QgsFeatureRequest().setFilterFid( *it ) ).nextFeature( currentFeature ) )
{
continue;
}
intersectFeature( currentFeature, &vWriter, layerB, &index );
++processedFeatures;
}
if ( p )
{
p->setValue( selectionA.size() );
}
}
//take all features
else
{
QgsFeatureIterator fit = layerB->getFeatures();
while ( fit.nextFeature( currentFeature ) )
{
index.insertFeature( currentFeature );
}
int featureCount = layerA->featureCount();
if ( p )
{
p->setMaximum( featureCount );
}
int processedFeatures = 0;
fit = layerA->getFeatures();
QgsFeature currentFeature;
while ( fit.nextFeature( currentFeature ) )
{
if ( p )
{
p->setValue( processedFeatures );
}
if ( p && p->wasCanceled() )
{
break;
//.........这里部分代码省略.........
示例5: commitChanges
bool QgsVectorLayerEditBuffer::commitChanges( QStringList &commitErrors )
{
QgsVectorDataProvider *provider = L->dataProvider();
commitErrors.clear();
int cap = provider->capabilities();
bool success = true;
// geometry updates attribute updates
// yes no => changeGeometryValues
// no yes => changeAttributeValues
// yes yes => changeFeatures
// to fix https://issues.qgis.org/issues/15741
// first of all check if feature to add is compatible with provider type
// this check have to be done before all checks to avoid to clear internal
// buffer if some of next steps success.
if ( success && !mAddedFeatures.isEmpty() )
{
if ( cap & QgsVectorDataProvider::AddFeatures )
{
if ( provider->doesStrictFeatureTypeCheck() )
{
for ( const auto &f : qgis::as_const( mAddedFeatures ) )
{
if ( ( ! f.hasGeometry() ) ||
( f.geometry().wkbType() == provider->wkbType() ) )
continue;
if ( provider->convertToProviderType( f.geometry() ).isNull() )
{
commitErrors << tr( "ERROR: %n feature(s) not added - geometry type is not compatible with the current layer.", "not added features count", mAddedFeatures.size() );
success = false;
break;
}
}
}
}
else
{
commitErrors << tr( "ERROR: %n feature(s) not added - provider doesn't support adding features.", "not added features count", mAddedFeatures.size() );
success = false;
}
}
//
// update geometries
//
if ( !mChangedGeometries.isEmpty() && ( ( cap & QgsVectorDataProvider::ChangeFeatures ) == 0 || mChangedAttributeValues.isEmpty() ) )
{
if ( provider->changeGeometryValues( mChangedGeometries ) )
{
commitErrors << tr( "SUCCESS: %n geometries were changed.", "changed geometries count", mChangedGeometries.size() );
emit committedGeometriesChanges( L->id(), mChangedGeometries );
mChangedGeometries.clear();
}
else
{
commitErrors << tr( "ERROR: %n geometries not changed.", "not changed geometries count", mChangedGeometries.size() );
success = false;
}
}
QgsFields oldFields = L->fields();
//
// delete attributes
//
bool attributesChanged = false;
if ( !mDeletedAttributeIds.isEmpty() )
{
if ( ( cap & QgsVectorDataProvider::DeleteAttributes ) && provider->deleteAttributes( mDeletedAttributeIds.toSet() ) )
{
commitErrors << tr( "SUCCESS: %n attribute(s) deleted.", "deleted attributes count", mDeletedAttributeIds.size() );
emit committedAttributesDeleted( L->id(), mDeletedAttributeIds );
mDeletedAttributeIds.clear();
attributesChanged = true;
}
else
{
commitErrors << tr( "ERROR: %n attribute(s) not deleted.", "not deleted attributes count", mDeletedAttributeIds.size() );
#if 0
QString list = "ERROR: Pending attribute deletes:";
Q_FOREACH ( int idx, mDeletedAttributeIds )
{
list.append( ' ' + L->fields().at( idx ).name() );
}
commitErrors << list;
#endif
success = false;
}
}