Skip to content
Permalink
Browse files

[API] add QgsVectorLayer::updateFeature()

  • Loading branch information
jef-n committed Oct 7, 2011
1 parent cb7d3ed commit f39a19c12b13acbdfd83e5b2fd89b0dc915bd333
Showing with 50 additions and 0 deletions.
  1. +8 −0 python/core/qgsvectorlayer.sip
  2. +36 −0 src/core/qgsvectorlayer.cpp
  3. +6 −0 src/core/qgsvectorlayer.h
@@ -272,10 +272,18 @@ public:
bool featureAtId(int featureId, QgsFeature& f, bool fetchGeometries = true, bool fetchAttributes = true);

/** Adds a feature
@param f feature to add
@param alsoUpdateExtent If True, will also go to the effort of e.g. updating the extents.
@return True in case of success and False in case of error
*/
bool addFeature(QgsFeature& f, bool alsoUpdateExtent = TRUE);

/** Update an existing feature
@param f feature to update
@return True in case of success and False in case of error
@note added in 1.8
*/
bool updateFeature(QgsFeature& f );


/** Insert a new vertex before the given vertex number,
@@ -1947,6 +1947,42 @@ bool QgsVectorLayer::addFeature( QgsFeature& f, bool alsoUpdateExtent )
return true;
}

bool QgsVectorLayer::updateFeature( QgsFeature &f )
{
QgsFeature current;
if ( !featureAtId( f.id(), current, f.geometry(), !f.attributeMap().isEmpty() ) )
{
QgsDebugMsg( QString( "feature %1 could not be retrieved" ).arg( f.id() ) );
return false;
}

if ( f.geometry() && current.geometry() && f.geometry() != current.geometry() && !f.geometry()->isGeosEqual( *current.geometry() ) )
{
if ( !changeGeometry( f.id(), f.geometry() ) )
{
QgsDebugMsg( QString( "geometry of feature %1 could not be changed." ).arg( f.id() ) );
return false;
}
}

const QgsAttributeMap &fa = f.attributeMap();
const QgsAttributeMap &ca = current.attributeMap();

foreach( int attr, fa.keys() )
{
if ( fa.contains( attr ) && ca.contains( attr ) && fa[attr] != ca[attr] )
{
if ( !changeAttributeValue( f.id(), attr, fa[attr] ) )
{
QgsDebugMsg( QString( "attribute %1 of feature %2 could not be changed." ).arg( attr ).arg( f.id() ) );
return false;
}
}
}

return true;
}


bool QgsVectorLayer::insertVertex( double x, double y, QgsFeatureId atFeatureId, int beforeVertex )
{
@@ -351,6 +351,12 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
*/
bool addFeature( QgsFeature& f, bool alsoUpdateExtent = true );

/** Updates an existing feature
@param f feature to update
@return True in case of success and False in case of error
@note added in 1.8
*/
bool updateFeature( QgsFeature &f );

/** Insert a new vertex before the given vertex number,
* in the given ring, item (first number is index 0), and feature

0 comments on commit f39a19c

Please sign in to comment.
You can’t perform that action at this time.