本文整理汇总了C++中qgsfeaturelist::iterator::attributes方法的典型用法代码示例。如果您正苦于以下问题:C++ iterator::attributes方法的具体用法?C++ iterator::attributes怎么用?C++ iterator::attributes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgsfeaturelist::iterator
的用法示例。
在下文中一共展示了iterator::attributes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addFeatures
bool QgsWFSProvider::addFeatures( QgsFeatureList &flist )
{
//create <Transaction> xml
QDomDocument transactionDoc;
QDomElement transactionElem = createTransactionElement( transactionDoc );
transactionDoc.appendChild( transactionElem );
//find out typename from uri and strip namespace prefix
QString tname = mShared->mURI.typeName();
if ( tname.isNull() )
{
return false;
}
removeNamespacePrefix( tname );
//Add the features
QgsFeatureList::iterator featureIt = flist.begin();
for ( ; featureIt != flist.end(); ++featureIt )
{
//Insert element
QDomElement insertElem = transactionDoc.createElementNS( QgsWFSConstants::WFS_NAMESPACE, "Insert" );
transactionElem.appendChild( insertElem );
QDomElement featureElem = transactionDoc.createElementNS( mApplicationNamespace, tname );
QgsAttributes featureAttributes = featureIt->attributes();
int nAttrs = featureAttributes.size();
for ( int i = 0; i < nAttrs; ++i )
{
const QVariant& value = featureAttributes.at( i );
if ( value.isValid() && !value.isNull() )
{
QDomElement fieldElem = transactionDoc.createElementNS( mApplicationNamespace, mShared->mFields.at( i ).name() );
QDomText fieldText = transactionDoc.createTextNode( value.toString() );
fieldElem.appendChild( fieldText );
featureElem.appendChild( fieldElem );
}
}
//add geometry column (as gml)
const QgsGeometry* geometry = featureIt->constGeometry();
if ( geometry != nullptr )
{
QDomElement geomElem = transactionDoc.createElementNS( mApplicationNamespace, mShared->mGeometryAttribute );
QgsGeometry the_geom( *geometry );
// convert to multi if the layer geom type is multi and the geom is not
if ( QGis::isMultiType( this->geometryType( ) ) && ! the_geom.isMultipart( ) )
{
the_geom.convertToMultiType();
}
QDomElement gmlElem = QgsOgcUtils::geometryToGML( &the_geom, transactionDoc );
if ( !gmlElem.isNull() )
{
gmlElem.setAttribute( "srsName", crs().authid() );
geomElem.appendChild( gmlElem );
featureElem.appendChild( geomElem );
}
}
insertElem.appendChild( featureElem );
}
QDomDocument serverResponse;
bool success = sendTransactionDocument( transactionDoc, serverResponse );
if ( !success )
{
return false;
}
if ( transactionSuccess( serverResponse ) )
{
//transaction successful. Add the features to the cache
QStringList idList = insertedFeatureIds( serverResponse );
QStringList::const_iterator idIt = idList.constBegin();
featureIt = flist.begin();
QVector<QgsWFSFeatureGmlIdPair> serializedFeatureList;
for ( ; idIt != idList.constEnd() && featureIt != flist.end(); ++idIt, ++featureIt )
{
serializedFeatureList.push_back( QgsWFSFeatureGmlIdPair( *featureIt, *idIt ) );
}
mShared->serializeFeatures( serializedFeatureList );
// And now set the feature id from the one got from the database
QMap< QString, QgsFeatureId > map;
for ( int idx = 0; idx < serializedFeatureList.size(); idx++ )
map[ serializedFeatureList[idx].second ] = serializedFeatureList[idx].first.id();
idIt = idList.constBegin();
featureIt = flist.begin();
for ( ; idIt != idList.constEnd() && featureIt != flist.end(); ++idIt, ++featureIt )
{
if ( map.find( *idIt ) != map.end() )
featureIt->setFeatureId( map[*idIt] );
}
return true;
}
else
{
//.........这里部分代码省略.........
示例2: if
bool QgsDb2Provider::addFeatures( QgsFeatureList & flist )
{
QgsDebugMsg( "mGeometryColType: " + mGeometryColType );
int writeCount = 0;
bool copyOperation = false;
if ( !mDatabase.isOpen() )
{
QString errMsg;
mDatabase = getDatabase( mConnInfo, errMsg );
if ( !errMsg.isEmpty() )
{
QgsDebugMsg( "getDatabase failed: " + errMsg );
return false;
}
}
if ( !mDatabase.transaction() )
{
QgsDebugMsg( "transaction failed" );
return false;
}
QSqlQuery query = QSqlQuery( mDatabase );
query.setForwardOnly( true );
QSqlQuery queryFid = QSqlQuery( mDatabase );
queryFid.setForwardOnly( true );
QgsFeature it = flist.at( 0 );
QString statement;
QString values;
statement = QString( "INSERT INTO %1.%2 (" ).arg( mSchemaName, mTableName );
bool first = true;
// Get the first geometry and its wkbType as when we are doing drag/drop,
// the wkbType is not passed to the DB2 provider from QgsVectorLayerImport
// Can't figure out how to resolved "unreferenced" wkbType compile message
// Don't really do anything with it at this point
#if 0
QgsGeometry *geom = it.geometry();
QgsWkbTypes::Type wkbType = geom->wkbType();
QgsDebugMsg( QString( "wkbType: %1" ).arg( wkbType ) );
QgsDebugMsg( QString( "mWkbType: %1" ).arg( mWkbType ) );
#endif
QgsAttributes attrs = it.attributes();
QgsDebugMsg( QString( "attrs.count: %1" ).arg( attrs.count() ) );
QgsDebugMsg( QString( "fields.count: %1" ).arg( mAttributeFields.count() ) );
if ( mAttributeFields.count() == ( attrs.count() + 1 ) )
{
copyOperation = true; // FID is first field but no attribute in attrs
}
else if ( mAttributeFields.count() != attrs.count() )
{
QgsDebugMsg( "Count mismatch - failing" );
return false;
}
if ( attrs.count() != mAttributeFields.count() )
{
QgsDebugMsg( "field counts don't match" );
// return false;
}
for ( int i = 0; i < mAttributeFields.count(); ++i )
{
QgsField fld = mAttributeFields.at( i );
QgsDebugMsg( QString( "i: %1; got field: %2" ).arg( i ).arg( fld.name() ) );
if ( fld.name().isEmpty() )
continue; // invalid
if ( mFidColName == fld.name() )
continue; // skip identity field
// if ( mDefaultValues.contains( i ) && mDefaultValues[i] == attrs.at( i ) )
// continue; // skip fields having default values
if ( !first )
{
statement += ',';
values += ',';
}
else
first = false;
statement += QString( "%1" ).arg( fld.name() );
values += QString( "?" );
}
// append geometry column name
if ( !mGeometryColName.isEmpty() )
{
if ( !first )
{
statement += ',';
values += ',';
}
statement += QString( "%1" ).arg( mGeometryColName );
//.........这里部分代码省略.........