Skip to content

Commit b1995af

Browse files
author
wonder
committed
Added possibility to delete features for OGR layers.
However then I've found out that nearly no OGR drivers support it :-) git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5062 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 7955a13 commit b1995af

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/providers/ogr/qgsogrprovider.cpp

+28-2
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,25 @@ bool QgsOgrProvider::createSpatialIndex()
11591159
}
11601160
}
11611161

1162+
bool QgsOgrProvider::deleteFeatures(std::list<int> const & id)
1163+
{
1164+
bool returnvalue=true;
1165+
for(std::list<int>::const_iterator it=id.begin();it!=id.end();++it)
1166+
{
1167+
if(!deleteFeature(*it))
1168+
{
1169+
returnvalue=false;
1170+
}
1171+
}
1172+
return returnvalue;
1173+
}
1174+
1175+
bool QgsOgrProvider::deleteFeature(int id)
1176+
{
1177+
OGRErr res = ogrLayer->DeleteFeature(id);
1178+
return (res == OGRERR_NONE);
1179+
}
1180+
11621181
int QgsOgrProvider::capabilities() const
11631182
{
11641183
int ability = NoCapabilities;
@@ -1185,6 +1204,12 @@ int QgsOgrProvider::capabilities() const
11851204
ability |= QgsVectorDataProvider::AddFeatures;
11861205
}
11871206

1207+
if (ogrLayer->TestCapability("DeleteFeature"))
1208+
// TRUE if this layer can delete its features
1209+
{
1210+
ability |= DeleteFeatures;
1211+
}
1212+
11881213
if (ogrLayer->TestCapability("RandomWrite"))
11891214
// TRUE if the SetFeature() method is operational on this layer.
11901215
{
@@ -1232,9 +1257,10 @@ int QgsOgrProvider::capabilities() const
12321257
{
12331258
// No use required for this QGIS release.
12341259
}
1235-
1260+
12361261
#ifdef QGISDEBUG
1237-
std::cout << "QgsOgrProvider::capabilities: GDAL Version Num is 'GDAL_VERSION_NUM'." << std::endl;
1262+
std::cout << "QgsOgrProvider::capabilities: GDAL Version Num is '" <<
1263+
GDAL_VERSION_NUM << "'." << std::endl;
12381264
#endif
12391265

12401266
if (1)

src/providers/ogr/qgsogrprovider.h

+5
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ class QgsOgrProvider:public QgsVectorDataProvider
147147
/**Writes a list of features to the file*/
148148
bool addFeatures(std::list<QgsFeature*> const flist);
149149

150+
/**Deletes a feature*/
151+
bool deleteFeatures(std::list<int> const & id);
152+
150153
/**Adds new attributess. Unfortunately not supported for layers with features in it*/
151154
bool addAttributes(std::map<QString,QString> const & name);
152155

@@ -260,6 +263,8 @@ class QgsOgrProvider:public QgsVectorDataProvider
260263
OGRPolygon * mSelectionRectangle;
261264
/**Adds one feature*/
262265
bool addFeature(QgsFeature* f);
266+
/**Deletes one feature*/
267+
bool deleteFeature(int id);
263268
//! The geometry factory
264269
geos::GeometryFactory *geometryFactory;
265270
//! The well known text reader

0 commit comments

Comments
 (0)