@@ -1182,6 +1182,49 @@ cannot change attribute");
1182
1182
return true ;
1183
1183
}
1184
1184
1185
+ bool QgsOgrProvider::changeGeometryValues (std::map<int , QgsGeometry> & geometry_map)
1186
+ {
1187
+ OGRFeature* theOGRFeature = 0 ;
1188
+ OGRGeometry* theNewGeometry = 0 ;
1189
+
1190
+ for (std::map<int , QgsGeometry>::iterator it = geometry_map.begin (); it != geometry_map.end (); ++it)
1191
+ {
1192
+ theOGRFeature = ogrLayer->GetFeature (it->first );
1193
+ if (!theOGRFeature)
1194
+ {
1195
+ QgsLogger::warning (" QgsOgrProvider::changeGeometryValues, cannot find feature" );
1196
+ continue ;
1197
+ }
1198
+
1199
+ // create an OGRGeometry
1200
+ if (OGRGeometryFactory::createFromWkb (it->second .wkbBuffer (), ogrLayer->GetSpatialRef (), &theNewGeometry, it->second .wkbSize ()) != OGRERR_NONE)
1201
+ {
1202
+ QgsLogger::warning (" QgsOgrProvider::changeGeometryValues, error while creating new OGRGeometry" );
1203
+ delete theNewGeometry;
1204
+ theNewGeometry = 0 ;
1205
+ continue ;
1206
+ }
1207
+
1208
+ if (!theNewGeometry)
1209
+ {
1210
+ QgsLogger::warning (" QgsOgrProvider::changeGeometryValues, new geometry is NULL" );
1211
+ continue ;
1212
+ }
1213
+
1214
+ // set the new geometry
1215
+ if (theOGRFeature->SetGeometryDirectly (theNewGeometry) != OGRERR_NONE)
1216
+ {
1217
+ QgsLogger::warning (" QgsOgrProvider::changeGeometryValues, error while replacing geometry" );
1218
+ delete theNewGeometry;
1219
+ theNewGeometry = 0 ;
1220
+ continue ;
1221
+ }
1222
+ ogrLayer->SetFeature (theOGRFeature);
1223
+ }
1224
+ ogrLayer->SyncToDisk ();
1225
+ return true ;
1226
+ }
1227
+
1185
1228
bool QgsOgrProvider::createSpatialIndex ()
1186
1229
{
1187
1230
QString filename=getDataSourceUri ().section (' /' ,-1 ,-1 );// find out the filename from the uri
@@ -1272,8 +1315,7 @@ int QgsOgrProvider::capabilities() const
1272
1315
// TODO And test appropriately.
1273
1316
1274
1317
ability |= ChangeAttributeValues;
1275
- // This provider can't change geometries yet anyway (cf. Postgres provider)
1276
- // ability |= QgsVectorDataProvider::ChangeGeometries;
1318
+ ability |= QgsVectorDataProvider::ChangeGeometries;
1277
1319
}
1278
1320
1279
1321
if (ogrLayer->TestCapability (" FastSpatialFilter" ))
0 commit comments