本文整理汇总了C++中qgsfeaturelist::iterator::setFeatureId方法的典型用法代码示例。如果您正苦于以下问题:C++ iterator::setFeatureId方法的具体用法?C++ iterator::setFeatureId怎么用?C++ iterator::setFeatureId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgsfeaturelist::iterator
的用法示例。
在下文中一共展示了iterator::setFeatureId方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addFeatures
bool QgsMemoryProvider::addFeatures( QgsFeatureList & flist )
{
// TODO: sanity checks of fields and geometries
for ( QgsFeatureList::iterator it = flist.begin(); it != flist.end(); ++it )
{
mFeatures[mNextFeatureId] = *it;
QgsFeature& newfeat = mFeatures[mNextFeatureId];
newfeat.setFeatureId( mNextFeatureId );
it->setFeatureId( mNextFeatureId );
// update spatial index
if ( mSpatialIndex )
mSpatialIndex->insertFeature( newfeat );
mNextFeatureId++;
}
updateExtent();
return true;
}
示例2: 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
{
//.........这里部分代码省略.........
示例3: if
//.........这里部分代码省略.........
}
else if ( type == QVariant::String )
{
// binding a TEXT value
query.bindValue( bindIdx, attrs.at( i ).toString() );
}
else if ( type == QVariant::Time )
{
// binding a TIME value
query.bindValue( bindIdx, attrs.at( i ).toTime().toString( Qt::ISODate ) );
}
else if ( type == QVariant::Date )
{
// binding a DATE value
query.bindValue( bindIdx, attrs.at( i ).toDate().toString( Qt::ISODate ) );
}
else if ( type == QVariant::DateTime )
{
// binding a DATETIME value
query.bindValue( bindIdx, attrs.at( i ).toDateTime().toString( Qt::ISODate ) );
}
else
{
query.bindValue( bindIdx, attrs.at( i ) );
}
#if 0
QgsDebugMsg( QString( "bound i: %1; name: %2; value: %3; bindIdx: %4" ).
arg( i ).arg( fld.name() ).arg( attrs.at( i ).toString() ).arg( bindIdx ) );
#endif
bindIdx++;
}
if ( !mGeometryColName.isEmpty() )
{
QgsGeometry geom = it->geometry();
QByteArray bytea = QByteArray(( char* )geom.asWkb(), ( int ) geom.wkbSize() );
query.bindValue( bindIdx, bytea, QSql::In | QSql::Binary );
}
QList<QVariant> list = query.boundValues().values();
// Show bound values
#if 0
for ( int i = 0; i < list.size(); ++i )
{
QgsDebugMsg( QString( "i: %1; value: %2; type: %3" )
.arg( i ).arg( list.at( i ).toString().toLatin1().data() ).arg( list.at( i ).typeName() ) );
}
#endif
if ( !query.exec() )
{
QString msg = query.lastError().text();
QgsDebugMsg( msg );
if ( !mSkipFailures )
{
pushError( msg );
return false;
}
}
statement = QString( "select IDENTITY_VAL_LOCAL() AS IDENTITY "
"FROM SYSIBM.SYSDUMMY1" );
// QgsDebugMsg( statement );
if ( !queryFid.exec( statement ) )
{
QString msg = query.lastError().text();
QgsDebugMsg( msg );
if ( !mSkipFailures )
{
pushError( msg );
return false;
}
}
if ( !queryFid.next() )
{
QString msg = query.lastError().text();
QgsDebugMsg( msg );
if ( !mSkipFailures )
{
pushError( msg );
return false;
}
}
it->setFeatureId( queryFid.value( 0 ).toLongLong() );
writeCount++;
// QgsDebugMsg( QString( "count: %1; featureId: %2" ).arg( writeCount ).arg( queryFid.value( 0 ).toLongLong() ) );
}
bool commitStatus = mDatabase.commit();
QgsDebugMsg( QString( "commitStatus: %1; write count: %2; featureId: %3" )
.arg( commitStatus ).arg( writeCount ).arg( queryFid.value( 0 ).toLongLong() ) );
if ( !commitStatus )
{
pushError( "Commit of new features failed" );
return false;
}
return true;
}