Skip to content

Commit

Permalink
Added possibility to delete features for OGR layers.
Browse files Browse the repository at this point in the history
However then I've found out that nearly no OGR drivers support it :-)


git-svn-id: http://svn.osgeo.org/qgis/trunk@5062 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Mar 19, 2006
1 parent 643bd1e commit 7c9442a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -1159,6 +1159,25 @@ bool QgsOgrProvider::createSpatialIndex()
}
}

bool QgsOgrProvider::deleteFeatures(std::list<int> const & id)
{
bool returnvalue=true;
for(std::list<int>::const_iterator it=id.begin();it!=id.end();++it)
{
if(!deleteFeature(*it))
{
returnvalue=false;
}
}
return returnvalue;
}

bool QgsOgrProvider::deleteFeature(int id)
{
OGRErr res = ogrLayer->DeleteFeature(id);
return (res == OGRERR_NONE);
}

int QgsOgrProvider::capabilities() const
{
int ability = NoCapabilities;
Expand All @@ -1185,6 +1204,12 @@ int QgsOgrProvider::capabilities() const
ability |= QgsVectorDataProvider::AddFeatures;
}

if (ogrLayer->TestCapability("DeleteFeature"))
// TRUE if this layer can delete its features
{
ability |= DeleteFeatures;
}

if (ogrLayer->TestCapability("RandomWrite"))
// TRUE if the SetFeature() method is operational on this layer.
{
Expand Down Expand Up @@ -1232,9 +1257,10 @@ int QgsOgrProvider::capabilities() const
{
// No use required for this QGIS release.
}

#ifdef QGISDEBUG
std::cout << "QgsOgrProvider::capabilities: GDAL Version Num is 'GDAL_VERSION_NUM'." << std::endl;
std::cout << "QgsOgrProvider::capabilities: GDAL Version Num is '" <<
GDAL_VERSION_NUM << "'." << std::endl;
#endif

if (1)
Expand Down
5 changes: 5 additions & 0 deletions src/providers/ogr/qgsogrprovider.h
Expand Up @@ -147,6 +147,9 @@ class QgsOgrProvider:public QgsVectorDataProvider
/**Writes a list of features to the file*/
bool addFeatures(std::list<QgsFeature*> const flist);

/**Deletes a feature*/
bool deleteFeatures(std::list<int> const & id);

/**Adds new attributess. Unfortunately not supported for layers with features in it*/
bool addAttributes(std::map<QString,QString> const & name);

Expand Down Expand Up @@ -260,6 +263,8 @@ class QgsOgrProvider:public QgsVectorDataProvider
OGRPolygon * mSelectionRectangle;
/**Adds one feature*/
bool addFeature(QgsFeature* f);
/**Deletes one feature*/
bool deleteFeature(int id);
//! The geometry factory
geos::GeometryFactory *geometryFactory;
//! The well known text reader
Expand Down

0 comments on commit 7c9442a

Please sign in to comment.