Skip to content
Permalink
Browse files
Added the possibility to edit the geometries of OGR layers (tested wi…
…th GDAL1.2.6 and 1.3.2)

git-svn-id: http://svn.osgeo.org/qgis/trunk@5849 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Sep 21, 2006
1 parent 1eec820 commit edd90d2d24047ec69ce9a11ada1a65bb79a5da87
Showing with 47 additions and 2 deletions.
  1. +44 −2 src/providers/ogr/qgsogrprovider.cpp
  2. +3 −0 src/providers/ogr/qgsogrprovider.h
@@ -1182,6 +1182,49 @@ cannot change attribute");
return true;
}

bool QgsOgrProvider::changeGeometryValues(std::map<int, QgsGeometry> & geometry_map)
{
OGRFeature* theOGRFeature = 0;
OGRGeometry* theNewGeometry = 0;

for(std::map<int, QgsGeometry>::iterator it = geometry_map.begin(); it != geometry_map.end(); ++it)
{
theOGRFeature = ogrLayer->GetFeature(it->first);
if(!theOGRFeature)
{
QgsLogger::warning("QgsOgrProvider::changeGeometryValues, cannot find feature");
continue;
}

//create an OGRGeometry
if(OGRGeometryFactory::createFromWkb(it->second.wkbBuffer(), ogrLayer->GetSpatialRef(), &theNewGeometry, it->second.wkbSize()) != OGRERR_NONE)
{
QgsLogger::warning("QgsOgrProvider::changeGeometryValues, error while creating new OGRGeometry");
delete theNewGeometry;
theNewGeometry = 0;
continue;
}

if(!theNewGeometry)
{
QgsLogger::warning("QgsOgrProvider::changeGeometryValues, new geometry is NULL");
continue;
}

//set the new geometry
if(theOGRFeature->SetGeometryDirectly(theNewGeometry) != OGRERR_NONE)
{
QgsLogger::warning("QgsOgrProvider::changeGeometryValues, error while replacing geometry");
delete theNewGeometry;
theNewGeometry = 0;
continue;
}
ogrLayer->SetFeature(theOGRFeature);
}
ogrLayer->SyncToDisk();
return true;
}

bool QgsOgrProvider::createSpatialIndex()
{
QString filename=getDataSourceUri().section('/',-1,-1);//find out the filename from the uri
@@ -1272,8 +1315,7 @@ int QgsOgrProvider::capabilities() const
// TODO And test appropriately.

ability |= ChangeAttributeValues;
// This provider can't change geometries yet anyway (cf. Postgres provider)
// ability |= QgsVectorDataProvider::ChangeGeometries;
ability |= QgsVectorDataProvider::ChangeGeometries;
}

if (ogrLayer->TestCapability("FastSpatialFilter"))
@@ -172,6 +172,9 @@ class QgsOgrProvider:public QgsVectorDataProvider
/**Changes attribute values of existing features */
bool changeAttributeValues(std::map<int,std::map<QString,QString> > const & attr_map);

/**Changes existing geometries*/
bool changeGeometryValues(std::map<int, QgsGeometry> & geometry_map);

QgsDataSourceURI * getURI()
{
return 0;

0 comments on commit edd90d2

Please sign in to comment.