void QgsOfflineEditing::committedGeometriesChanges( const QString& qgisLayerId, const QgsGeometryMap& changedGeometries ) { sqlite3* db = openLoggingDb(); if ( db == NULL ) { return; } // insert log int layerId = getOrCreateLayerId( db, qgisLayerId ); int commitNo = getCommitNo( db ); for ( QgsGeometryMap::const_iterator it = changedGeometries.begin(); it != changedGeometries.end(); ++it ) { QgsFeatureId fid = it.key(); if ( isAddedFeature( db, layerId, fid ) ) { // skip added features continue; } QgsGeometry geom = it.value(); QString sql = QString( "INSERT INTO 'log_geometry_updates' VALUES ( %1, %2, %3, '%4' )" ) .arg( layerId ) .arg( commitNo ) .arg( fid ) .arg( geom.exportToWkt() ); sqlExec( db, sql ); // TODO: use WKB instead of WKT? } increaseCommitNo( db ); sqlite3_close( db ); }
bool QgsMemoryProvider::changeGeometryValues( QgsGeometryMap & geometry_map ) { for ( QgsGeometryMap::const_iterator it = geometry_map.begin(); it != geometry_map.end(); ++it ) { QgsFeatureMap::iterator fit = mFeatures.find( it.key() ); if ( fit == mFeatures.end() ) continue; // update spatial index if ( mSpatialIndex ) mSpatialIndex->deleteFeature( *fit ); fit->setGeometry( it.value() ); // update spatial index if ( mSpatialIndex ) mSpatialIndex->insertFeature( *fit ); } updateExtent(); return TRUE; }
bool QgsWFSProvider::changeGeometryValues( const QgsGeometryMap &geometry_map ) { //find out typename from uri and strip namespace prefix QString tname = mShared->mURI.typeName(); if ( tname.isNull() ) { return false; } //create <Transaction> xml QDomDocument transactionDoc; QDomElement transactionElem = createTransactionElement( transactionDoc ); transactionDoc.appendChild( transactionElem ); QgsGeometryMap::const_iterator geomIt = geometry_map.constBegin(); for ( ; geomIt != geometry_map.constEnd(); ++geomIt ) { QString gmlid = mShared->findGmlId( geomIt.key() ); if ( gmlid.isEmpty() ) { QgsDebugMsg( QString( "Cannot identify feature of id %1" ).arg( geomIt.key() ) ); continue; } QDomElement updateElem = transactionDoc.createElementNS( QgsWFSConstants::WFS_NAMESPACE, "Update" ); updateElem.setAttribute( "typeName", tname ); //Property QDomElement propertyElem = transactionDoc.createElementNS( QgsWFSConstants::WFS_NAMESPACE, "Property" ); QDomElement nameElem = transactionDoc.createElementNS( QgsWFSConstants::WFS_NAMESPACE, "Name" ); QDomText nameText = transactionDoc.createTextNode( mShared->mGeometryAttribute ); nameElem.appendChild( nameText ); propertyElem.appendChild( nameElem ); QDomElement valueElem = transactionDoc.createElementNS( QgsWFSConstants::WFS_NAMESPACE, "Value" ); QDomElement gmlElem = QgsOgcUtils::geometryToGML( &geomIt.value(), transactionDoc ); gmlElem.setAttribute( "srsName", crs().authid() ); valueElem.appendChild( gmlElem ); propertyElem.appendChild( valueElem ); updateElem.appendChild( propertyElem ); //filter QDomElement filterElem = transactionDoc.createElementNS( QgsWFSConstants::OGC_NAMESPACE, "Filter" ); QDomElement featureIdElem = transactionDoc.createElementNS( QgsWFSConstants::OGC_NAMESPACE, "FeatureId" ); featureIdElem.setAttribute( "fid", gmlid ); filterElem.appendChild( featureIdElem ); updateElem.appendChild( filterElem ); transactionElem.appendChild( updateElem ); } QDomDocument serverResponse; bool success = sendTransactionDocument( transactionDoc, serverResponse ); if ( !success ) { return false; } if ( transactionSuccess( serverResponse ) ) { mShared->changeGeometryValues( geometry_map ); return true; } else { handleException( serverResponse ); return false; } }