本文整理汇总了C++中qgsattributemap::const_iterator::key方法的典型用法代码示例。如果您正苦于以下问题:C++ const_iterator::key方法的具体用法?C++ const_iterator::key怎么用?C++ const_iterator::key使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgsattributemap::const_iterator
的用法示例。
在下文中一共展示了const_iterator::key方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: expandAction
QString QgsAttributeAction::expandAction( QString action, const QgsAttributeMap &attributes,
uint clickedOnValue )
{
// This function currently replaces all %% characters in the action
// with the value from values[clickedOnValue].second, and then
// searches for all strings that go %attribite_name, where
// attribute_name is found in values[x].first, and replaces any that
// it finds by values[s].second.
// Additional substitutions could include symbols for $CWD, $HOME,
// etc (and their OSX and Windows equivalents)
// This function will potentially fall apart if any of the
// substitutions produce text that could match another
// substitution. May be better to adopt a two pass approach - identify
// all matches and their substitutions and then do a second pass
// for the actual substitutions.
QString expanded_action;
if ( clickedOnValue >= 0 && attributes.contains( clickedOnValue ) )
expanded_action = action.replace( "%%", attributes[clickedOnValue].toString() );
else
expanded_action = action;
const QgsFieldMap &fields = mLayer->pendingFields();
for ( int i = 0; i < 4; i++ )
{
for ( QgsAttributeMap::const_iterator it = attributes.begin(); it != attributes.end(); it++ )
{
QgsFieldMap::const_iterator fit = fields.find( it.key() );
if ( fit == fields.constEnd() )
continue;
QString to_replace;
switch ( i )
{
case 0: to_replace = "[%" + fit->name() + "]"; break;
case 1: to_replace = "[%" + mLayer->attributeDisplayName( it.key() ) + "]"; break;
case 2: to_replace = "%" + fit->name(); break;
case 3: to_replace = "%" + mLayer->attributeDisplayName( it.key() ); break;
}
expanded_action = expanded_action.replace( to_replace, it.value().toString() );
}
}
return expanded_action;
}
示例2: canvasReleaseEvent
void QgsMapToolChangeLabelProperties::canvasReleaseEvent( QMouseEvent * e )
{
QgsVectorLayer* vlayer = currentLayer();
if ( mLabelRubberBand && mCanvas && vlayer )
{
QgsLabelPropertyDialog d( mCurrentLabelPos.layerID, mCurrentLabelPos.featureId, mCanvas->mapRenderer() );
if ( d.exec() == QDialog::Accepted )
{
const QgsAttributeMap& changes = d.changedProperties();
if ( changes.size() > 0 )
{
vlayer->beginEditCommand( tr( "Label properties changed" ) );
QgsAttributeMap::const_iterator changeIt = changes.constBegin();
for ( ; changeIt != changes.constEnd(); ++changeIt )
{
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, changeIt.key(), changeIt.value(), false );
}
vlayer->endEditCommand();
mCanvas->refresh();
}
}
deleteRubberBands();
}
}
示例3: canvasReleaseEvent
void QgsMapToolChangeLabelProperties::canvasReleaseEvent( QMouseEvent *e )
{
Q_UNUSED( e );
QgsVectorLayer* vlayer = currentLayer();
if ( mLabelRubberBand && mCanvas && vlayer )
{
QString labeltext = QString(); // NULL QString signifies no expression
bool settingsOk;
QgsPalLayerSettings& labelSettings = currentLabelSettings( &settingsOk );
if ( settingsOk && labelSettings.isExpression )
{
labeltext = mCurrentLabelPos.labelText;
}
QgsLabelPropertyDialog d( mCurrentLabelPos.layerID, mCurrentLabelPos.featureId, mCurrentLabelPos.labelFont, labeltext, 0 );
if ( d.exec() == QDialog::Accepted )
{
const QgsAttributeMap& changes = d.changedProperties();
if ( changes.size() > 0 )
{
vlayer->beginEditCommand( tr( "Changed properties for label" ) + QString( " '%1'" ).arg( currentLabelText( 24 ) ) );
QgsAttributeMap::const_iterator changeIt = changes.constBegin();
for ( ; changeIt != changes.constEnd(); ++changeIt )
{
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, changeIt.key(), changeIt.value() );
}
vlayer->endEditCommand();
mCanvas->refresh();
}
}
deleteRubberBands();
}
}
示例4: createFeatureGeoJSON
QString QgsWFSServer::createFeatureGeoJSON( QgsFeature* feat, QgsCoordinateReferenceSystem &, QMap< int, QgsField > fields, QSet<QString> hiddenAttributes ) /*const*/
{
QString fStr = "{\"type\": \"Feature\",\n";
fStr += " \"id\": ";
fStr += QString::number( feat->id() );
fStr += ",\n";
QgsGeometry* geom = feat->geometry();
if ( geom && mWithGeom )
{
QgsRectangle box = geom->boundingBox();
fStr += " \"bbox\": [ " + QString::number( box.xMinimum(), 'f', 6 ).remove( QRegExp( "[0]{1,5}$" ) ) + ", " + QString::number( box.yMinimum(), 'f', 6 ).remove( QRegExp( "[0]{1,5}$" ) ) + ", " + QString::number( box.xMaximum(), 'f', 6 ).remove( QRegExp( "[0]{1,5}$" ) ) + ", " + QString::number( box.yMaximum(), 'f', 6 ).remove( QRegExp( "[0]{1,5}$" ) ) + "],\n";
fStr += " \"geometry\": ";
fStr += geom->exportToGeoJSON();
fStr += ",\n";
}
//read all attribute values from the feature
fStr += " \"properties\": {\n";
QgsAttributeMap featureAttributes = feat->attributeMap();
int attributeCounter = 0;
for ( QgsAttributeMap::const_iterator it = featureAttributes.begin(); it != featureAttributes.end(); ++it )
{
QString attributeName = fields[it.key()].name();
//skip attribute if it has edit type 'hidden'
if ( hiddenAttributes.contains( attributeName ) )
{
continue;
}
if ( attributeCounter == 0 )
fStr += " \"";
else
fStr += " ,\"";
fStr += attributeName;
fStr += "\": ";
if ( it->type() == 6 || it->type() == 2 )
{
fStr += it->toString();
}
else
{
fStr += "\"";
fStr += it->toString().replace( QString( "\"" ), QString( "\\\"" ) );
fStr += "\"";
}
fStr += "\n";
++attributeCounter;
}
fStr += " }\n";
fStr += " }";
return fStr;
}
示例5: createFeatureElem
QDomElement QgsWFSServer::createFeatureElem( QgsFeature* feat, QDomDocument& doc, QgsCoordinateReferenceSystem& crs, QMap< int, QgsField > fields, QSet<QString> hiddenAttributes ) /*const*/
{
//gml:FeatureMember
QDomElement featureElement = doc.createElement( "gml:featureMember"/*wfs:FeatureMember*/ );
//qgs:%TYPENAME%
QDomElement typeNameElement = doc.createElement( "qgs:" + mTypeName.replace( QString( " " ), QString( "_" ) )/*qgs:%TYPENAME%*/ );
typeNameElement.setAttribute( "fid", QString::number( feat->id() ) );
featureElement.appendChild( typeNameElement );
if ( mWithGeom )
{
//add geometry column (as gml)
QgsGeometry* geom = feat->geometry();
QDomElement geomElem = doc.createElement( "qgs:geometry" );
QDomElement gmlElem = createGeometryElem( geom, doc );
if ( !gmlElem.isNull() )
{
QgsRectangle box = geom->boundingBox();
QDomElement bbElem = doc.createElement( "gml:boundedBy" );
QDomElement boxElem = createBoxElem( &box, doc );
if ( crs.isValid() )
{
boxElem.setAttribute( "srsName", crs.authid() );
gmlElem.setAttribute( "srsName", crs.authid() );
}
bbElem.appendChild( boxElem );
typeNameElement.appendChild( bbElem );
geomElem.appendChild( gmlElem );
typeNameElement.appendChild( geomElem );
}
}
//read all attribute values from the feature
QgsAttributeMap featureAttributes = feat->attributeMap();
for ( QgsAttributeMap::const_iterator it = featureAttributes.begin(); it != featureAttributes.end(); ++it )
{
QString attributeName = fields[it.key()].name();
//skip attribute if it has edit type 'hidden'
if ( hiddenAttributes.contains( attributeName ) )
{
continue;
}
QDomElement fieldElem = doc.createElement( "qgs:" + attributeName.replace( QString( " " ), QString( "_" ) ) );
QDomText fieldText = doc.createTextNode( it->toString() );
fieldElem.appendChild( fieldText );
typeNameElement.appendChild( fieldElem );
}
return featureElement;
}
示例6: updateAttributeMapIndex
void QgsVectorLayerEditBuffer::updateAttributeMapIndex( QgsAttributeMap& map, int index, int offset ) const
{
QgsAttributeMap updatedMap;
for ( QgsAttributeMap::const_iterator it = map.begin(); it != map.end(); ++it )
{
int attrIndex = it.key();
updatedMap.insert( attrIndex < index ? attrIndex : attrIndex + offset, it.value() );
}
map = updatedMap;
}
示例7: editFeature
bool QgsFeatureAction::editFeature()
{
bool res = false;
if ( !mLayer )
return res;
QgsAttributeDialog *dialog = newDialog( false );
if ( !mLayer->isEditable() )
{
res = dialog->exec();
}
else
{
QgsAttributeMap src = mFeature.attributeMap();
if ( dialog->exec() )
{
mLayer->beginEditCommand( text() );
const QgsAttributeMap &dst = mFeature.attributeMap();
for ( QgsAttributeMap::const_iterator it = dst.begin(); it != dst.end(); it++ )
{
if ( !src.contains( it.key() ) || it.value() != src[it.key()] )
{
mLayer->changeAttributeValue( mFeature.id(), it.key(), it.value() );
}
}
mLayer->endEditCommand();
res = true;
}
else
{
res = false;
}
}
delete dialog;
return res;
}
示例8: applyChanges
void QgsMapToolChangeLabelProperties::applyChanges( const QgsAttributeMap& changes )
{
QgsVectorLayer* vlayer = mCurrentLabel.layer;
if ( !vlayer )
return;
if ( !changes.isEmpty() )
{
vlayer->beginEditCommand( tr( "Changed properties for label" ) + QStringLiteral( " '%1'" ).arg( currentLabelText( 24 ) ) );
QgsAttributeMap::const_iterator changeIt = changes.constBegin();
for ( ; changeIt != changes.constEnd(); ++changeIt )
{
vlayer->changeAttributeValue( mCurrentLabel.pos.featureId, changeIt.key(), changeIt.value() );
}
vlayer->endEditCommand();
vlayer->triggerRepaint();
}
}
示例9: updateChangedAttributes
void QgsVectorLayerFeatureIterator::updateChangedAttributes( QgsFeature &f )
{
QgsAttributes& attrs = f.attributes();
// remove all attributes that will disappear - from higher indices to lower
for ( int idx = mDeletedAttributeIds.count() - 1; idx >= 0; --idx )
{
attrs.remove( mDeletedAttributeIds[idx] );
}
// adjust size to accommodate added attributes
attrs.resize( attrs.count() + mAddedAttributes.count() );
// update changed attributes
if ( mChangedAttributeValues.contains( f.id() ) )
{
const QgsAttributeMap &map = mChangedAttributeValues[f.id()];
for ( QgsAttributeMap::const_iterator it = map.begin(); it != map.end(); it++ )
attrs[it.key()] = it.value();
}
}
示例10: applyFeaturesAdded
void QgsOfflineEditing::applyFeaturesAdded( QgsVectorLayer* offlineLayer, QgsVectorLayer* remoteLayer, sqlite3* db, int layerId )
{
QString sql = QString( "SELECT \"fid\" FROM 'log_added_features' WHERE \"layer_id\" = %1" ).arg( layerId );
QList<int> newFeatureIds = sqlQueryInts( db, sql );
// get new features from offline layer
QgsFeatureList features;
for ( int i = 0; i < newFeatureIds.size(); i++ )
{
QgsFeature feature;
if ( offlineLayer->featureAtId( newFeatureIds.at( i ), feature, true, true ) )
{
features << feature;
}
}
// copy features to remote layer
mProgressDialog->setupProgressBar( tr( "%v / %m features added" ), features.size() );
int i = 1;
for ( QgsFeatureList::iterator it = features.begin(); it != features.end(); ++it )
{
QgsFeature f = *it;
// NOTE: Spatialite provider ignores position of geometry column
// restore gap in QgsAttributeMap if geometry column is not last (WORKAROUND)
QMap<int, int> attrLookup = attributeLookup( offlineLayer, remoteLayer );
QgsAttributeMap newAttrMap;
QgsAttributeMap attrMap = f.attributeMap();
for ( QgsAttributeMap::const_iterator it = attrMap.begin(); it != attrMap.end(); ++it )
{
newAttrMap.insert( attrLookup[ it.key()], it.value() );
}
f.setAttributeMap( newAttrMap );
remoteLayer->addFeature( f, false );
mProgressDialog->setProgressValue( i++ );
}
}
示例11: committedAttributeValuesChanges
void QgsOfflineEditing::committedAttributeValuesChanges( const QString& qgisLayerId, const QgsChangedAttributesMap& changedAttrsMap )
{
sqlite3* db = openLoggingDb();
if ( db == NULL )
{
return;
}
// insert log
int layerId = getOrCreateLayerId( db, qgisLayerId );
int commitNo = getCommitNo( db );
for ( QgsChangedAttributesMap::const_iterator cit = changedAttrsMap.begin(); cit != changedAttrsMap.end(); ++cit )
{
QgsFeatureId fid = cit.key();
if ( isAddedFeature( db, layerId, fid ) )
{
// skip added features
continue;
}
QgsAttributeMap attrMap = cit.value();
for ( QgsAttributeMap::const_iterator it = attrMap.begin(); it != attrMap.end(); ++it )
{
QString sql = QString( "INSERT INTO 'log_feature_updates' VALUES ( %1, %2, %3, %4, '%5' )" )
.arg( layerId )
.arg( commitNo )
.arg( fid )
.arg( it.key() ) // attr
.arg( it.value().toString() ); // value
sqlExec( db, sql );
}
}
increaseCommitNo( db );
sqlite3_close( db );
}
示例12: changeAttributeValues
bool QgsWFSProvider::changeAttributeValues( const QgsChangedAttributesMap &attr_map )
{
//find out typename from uri and strip namespace prefix
QString tname = mShared->mURI.typeName();
if ( tname.isNull() )
{
return false;
}
//create <Transaction> xml
QDomDocument transactionDoc;
QDomElement transactionElem = createTransactionElement( transactionDoc );
transactionDoc.appendChild( transactionElem );
QgsChangedAttributesMap::const_iterator attIt = attr_map.constBegin();
for ( ; attIt != attr_map.constEnd(); ++attIt )
{
QString gmlid = mShared->findGmlId( attIt.key() );
if ( gmlid.isEmpty() )
{
QgsDebugMsg( QString( "Cannot identify feature of id %1" ).arg( attIt.key() ) );
continue;
}
QDomElement updateElem = transactionDoc.createElementNS( QgsWFSConstants::WFS_NAMESPACE, "Update" );
updateElem.setAttribute( "typeName", tname );
QgsAttributeMap::const_iterator attMapIt = attIt.value().constBegin();
for ( ; attMapIt != attIt.value().constEnd(); ++attMapIt )
{
QString fieldName = mShared->mFields.at( attMapIt.key() ).name();
QDomElement propertyElem = transactionDoc.createElementNS( QgsWFSConstants::WFS_NAMESPACE, "Property" );
QDomElement nameElem = transactionDoc.createElementNS( QgsWFSConstants::WFS_NAMESPACE, "Name" );
QDomText nameText = transactionDoc.createTextNode( fieldName );
nameElem.appendChild( nameText );
propertyElem.appendChild( nameElem );
QDomElement valueElem = transactionDoc.createElementNS( QgsWFSConstants::WFS_NAMESPACE, "Value" );
QDomText valueText = transactionDoc.createTextNode( attMapIt.value().toString() );
valueElem.appendChild( valueText );
propertyElem.appendChild( valueElem );
updateElem.appendChild( propertyElem );
}
//Filter
QDomElement filterElem = transactionDoc.createElementNS( QgsWFSConstants::OGC_NAMESPACE, "Filter" );
QDomElement featureIdElem = transactionDoc.createElementNS( QgsWFSConstants::OGC_NAMESPACE, "FeatureId" );
featureIdElem.setAttribute( "fid", gmlid );
filterElem.appendChild( featureIdElem );
updateElem.appendChild( filterElem );
transactionElem.appendChild( updateElem );
}
QDomDocument serverResponse;
bool success = sendTransactionDocument( transactionDoc, serverResponse );
if ( !success )
{
return false;
}
if ( transactionSuccess( serverResponse ) )
{
mShared->changeAttributeValues( attr_map );
return true;
}
else
{
handleException( serverResponse );
return false;
}
}
示例13: makeGraph
//.........这里部分代码省略.........
tiedPoint[ i ] = info.mTiedPoint;
}
}
}
pt1 = pt2;
isFirstPoint = false;
}
}
emit buildProgress( ++step, featureCount );
}
// end: tie points to graph
if ( mDirectionFieldId != -1 )
{
la.push_back( mDirectionFieldId );
}
if ( mSpeedFieldId != -1 )
{
la.push_back( mSpeedFieldId );
}
SpeedUnit su = SpeedUnit::byName( mSpeedUnitName );
// begin graph construction
vl->select( la );
while ( vl->nextFeature( feature ) )
{
QgsAttributeMap attr = feature.attributeMap();
int directionType = mDefaultDirection;
QgsAttributeMap::const_iterator it;
// What direction have feature?
for ( it = attr.constBegin(); it != attr.constEnd(); ++it )
{
if ( it.key() != mDirectionFieldId )
{
continue;
}
QString str = it.value().toString();
if ( str == mBothDirectionValue )
{
directionType = 3;
}
else if ( str == mDirectDirectionValue )
{
directionType = 1;
}
else if ( str == mReverseDirectionValue )
{
directionType = 2;
}
}
// What speed have feature?
double speed = 0.0;
for ( it = attr.constBegin(); it != attr.constEnd(); ++it )
{
if ( it.key() != mSpeedFieldId )
{
continue;
}
speed = it.value().toDouble();
}
if ( speed <= 0.0 )
{
speed = mDefaultSpeed;
}
示例14: addFeature
bool QgsGPXProvider::addFeature( QgsFeature& f )
{
unsigned char* geo = f.geometry()->asWkb();
QGis::WkbType wkbType = f.geometry()->wkbType();
bool success = false;
QgsGPSObject* obj = NULL;
const QgsAttributeMap& attrs( f.attributeMap() );
QgsAttributeMap::const_iterator it;
// is it a waypoint?
if ( mFeatureType == WaypointType && geo != NULL && wkbType == QGis::WKBPoint )
{
// add geometry
QgsWaypoint wpt;
std::memcpy( &wpt.lon, geo + 5, sizeof( double ) );
std::memcpy( &wpt.lat, geo + 13, sizeof( double ) );
// add waypoint-specific attributes
for ( it = attrs.begin(); it != attrs.end(); ++it )
{
if ( it.key() == EleAttr )
{
bool eleIsOK;
double ele = it->toDouble( &eleIsOK );
if ( eleIsOK )
wpt.ele = ele;
}
else if ( it.key() == SymAttr )
{
wpt.sym = it->toString();
}
}
QgsGPSData::WaypointIterator iter = data->addWaypoint( wpt );
success = true;
obj = &( *iter );
}
// is it a route?
if ( mFeatureType == RouteType && geo != NULL && wkbType == QGis::WKBLineString )
{
QgsRoute rte;
// reset bounds
rte.xMin = std::numeric_limits<double>::max();
rte.xMax = -std::numeric_limits<double>::max();
rte.yMin = std::numeric_limits<double>::max();
rte.yMax = -std::numeric_limits<double>::max();
// add geometry
int nPoints;
std::memcpy( &nPoints, geo + 5, 4 );
for ( int i = 0; i < nPoints; ++i )
{
double lat, lon;
std::memcpy( &lon, geo + 9 + 16 * i, sizeof( double ) );
std::memcpy( &lat, geo + 9 + 16 * i + 8, sizeof( double ) );
QgsRoutepoint rtept;
rtept.lat = lat;
rtept.lon = lon;
rte.points.push_back( rtept );
rte.xMin = rte.xMin < lon ? rte.xMin : lon;
rte.xMax = rte.xMax > lon ? rte.xMax : lon;
rte.yMin = rte.yMin < lat ? rte.yMin : lat;
rte.yMax = rte.yMax > lat ? rte.yMax : lat;
}
// add route-specific attributes
for ( it = attrs.begin(); it != attrs.end(); ++it )
{
if ( it.key() == NumAttr )
{
bool numIsOK;
long num = it->toInt( &numIsOK );
if ( numIsOK )
rte.number = num;
}
}
QgsGPSData::RouteIterator iter = data->addRoute( rte );
success = true;
obj = &( *iter );
}
// is it a track?
if ( mFeatureType == TrackType && geo != NULL && wkbType == QGis::WKBLineString )
{
QgsTrack trk;
QgsTrackSegment trkseg;
// reset bounds
trk.xMin = std::numeric_limits<double>::max();
trk.xMax = -std::numeric_limits<double>::max();
trk.yMin = std::numeric_limits<double>::max();
trk.yMax = -std::numeric_limits<double>::max();
// add geometry
//.........这里部分代码省略.........