Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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/qgis@5849 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Sep 21, 2006
1 parent 2cc6de7 commit bede7d7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
46 changes: 44 additions & 2 deletions src/providers/ogr/qgsogrprovider.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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"))
Expand Down
3 changes: 3 additions & 0 deletions src/providers/ogr/qgsogrprovider.h
Expand Up @@ -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;
Expand Down

0 comments on commit bede7d7

Please sign in to comment.