Skip to content

Commit bede7d7

Browse files
author
mhugent
committedSep 21, 2006

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed
 

‎src/providers/ogr/qgsogrprovider.cpp

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,49 @@ cannot change attribute");
11821182
return true;
11831183
}
11841184

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+
11851228
bool QgsOgrProvider::createSpatialIndex()
11861229
{
11871230
QString filename=getDataSourceUri().section('/',-1,-1);//find out the filename from the uri
@@ -1272,8 +1315,7 @@ int QgsOgrProvider::capabilities() const
12721315
// TODO And test appropriately.
12731316

12741317
ability |= ChangeAttributeValues;
1275-
// This provider can't change geometries yet anyway (cf. Postgres provider)
1276-
// ability |= QgsVectorDataProvider::ChangeGeometries;
1318+
ability |= QgsVectorDataProvider::ChangeGeometries;
12771319
}
12781320

12791321
if (ogrLayer->TestCapability("FastSpatialFilter"))

‎src/providers/ogr/qgsogrprovider.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ class QgsOgrProvider:public QgsVectorDataProvider
172172
/**Changes attribute values of existing features */
173173
bool changeAttributeValues(std::map<int,std::map<QString,QString> > const & attr_map);
174174

175+
/**Changes existing geometries*/
176+
bool changeGeometryValues(std::map<int, QgsGeometry> & geometry_map);
177+
175178
QgsDataSourceURI * getURI()
176179
{
177180
return 0;

0 commit comments

Comments
 (0)
Please sign in to comment.