Skip to content

Commit

Permalink
Merge branch 'master' of github.com:qgis/Quantum-GIS
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent committed Nov 30, 2012
2 parents 9342a9c + aab08cb commit 047d393
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
21 changes: 13 additions & 8 deletions python/plugins/db_manager/dlg_import_vector.py
Expand Up @@ -63,8 +63,9 @@ def __init__(self, inLayer, outDb, outUri, parent=None):

pk = self.outUri.keyColumn()
self.editPrimaryKey.setText(pk if pk != "" else self.default_pk)
geom = self.outUri.geometryColumn()
self.editGeomColumn.setText(geom if geom != "" else self.default_geom)
if self.inLayer.hasGeometryType():
geom = self.outUri.geometryColumn()
self.editGeomColumn.setText(geom if geom != "" else self.default_geom)

inCrs = self.inLayer.crs()
srid = inCrs.postgisSrid() if inCrs.isValid() else 4236
Expand All @@ -76,10 +77,11 @@ def __init__(self, inLayer, outDb, outUri, parent=None):

def checkSupports(self):
allowSpatial = self.db.connector.hasSpatialSupport()
self.chkGeomColumn.setEnabled(allowSpatial and self.inLayer.hasGeometryType())
self.chkSourceSrid.setEnabled(allowSpatial)
self.chkTargetSrid.setEnabled(allowSpatial)
self.chkSpatialIndex.setEnabled(allowSpatial)
hasGeomType = self.inLayer.hasGeometryType()
self.chkGeomColumn.setEnabled(allowSpatial and hasGeomType)
self.chkSourceSrid.setEnabled(allowSpatial and hasGeomType)
self.chkTargetSrid.setEnabled(allowSpatial and hasGeomType)
self.chkSpatialIndex.setEnabled(allowSpatial and hasGeomType)


def populateSchemas(self):
Expand Down Expand Up @@ -174,8 +176,11 @@ def importLayer(self):
# get pk and geom field names from the source layer or use the
# ones defined by the user
pk = self.outUri.keyColumn() if not self.chkPrimaryKey.isChecked() else self.editPrimaryKey.text()
geom = self.outUri.geometryColumn() if not self.chkGeomColumn.isChecked() else self.editGeomColumn.text()
geom = geom if geom != "" else self.default_geom
if self.inLayer.hasGeometryType():
geom = self.outUri.geometryColumn() if not self.chkGeomColumn.isChecked() else self.editGeomColumn.text()
geom = geom if geom != "" else self.default_geom
else:
geom = QString()

self.outUri.setDataSource( schema, table, geom, QString(), pk )
uri = self.outUri.uri()
Expand Down
5 changes: 3 additions & 2 deletions src/core/qgsvectorlayerimport.cpp
Expand Up @@ -121,11 +121,12 @@ bool QgsVectorLayerImport::addFeature( QgsFeature& feat )
const QgsAttributeMap &attrs = feat.attributeMap();

QgsFeature newFeat;
newFeat.setGeometry( *feat.geometry() );
if ( feat.geometry() )
newFeat.setGeometry( *feat.geometry() );

for ( QgsAttributeMap::const_iterator it = attrs.begin(); it != attrs.end(); it++ )
{
// add only mapped attributes (un-mapped ones are not present in the
// add only mapped attributes (un-mapped ones will not be present in the
// destination layer)
if ( mOldToNewAttrIdx.contains( it.key() ) )
{
Expand Down
19 changes: 13 additions & 6 deletions src/mapserver/qgswfsserver.cpp
Expand Up @@ -1168,6 +1168,9 @@ QDomDocument QgsWFSServer::transaction( const QString& requestBody )
typeName = actionElem.attribute( "typeName" );
}

if ( typeName.contains( ":" ) )
typeName = typeName.section( ":", 1, 1 );

QDomNodeList typeNameList = mDocElem.elementsByTagName( typeName );
if ( typeNameList.count() == 0 )
{
Expand Down Expand Up @@ -1424,13 +1427,12 @@ QDomDocument QgsWFSServer::transaction( const QString& requestBody )
}
// Add the feature to th layer
// and store it to put it's Feature Id in the response
layer->addFeature( *f, true );
inFeatList << *f;
inFeatList.append( *f );
}
}
}
// Commit the changes of the insert elements
if ( !layer->commitChanges() )
if ( !provider->addFeatures( inFeatList ) )
{
QDomElement trElem = doc.createElement( "TransactionResult" );
QDomElement stElem = doc.createElement( "Status" );
Expand All @@ -1444,6 +1446,13 @@ QDomDocument QgsWFSServer::transaction( const QString& requestBody )
trElem.appendChild( locElem );

QDomElement mesElem = doc.createElement( "Message" );
QStringList mesErrors;
mesErrors << QString( "ERROR: %n feature(s) not added.").arg(inFeatList.size());
if ( provider->hasErrors() )
{
mesErrors << "\n Provider errors:" << provider->errors();
provider->clearErrors();
}
mesElem.appendChild( doc.createTextNode( layer->commitErrors().join( "\n " ) ) );
trElem.appendChild( mesElem );

Expand All @@ -1460,16 +1469,14 @@ QDomDocument QgsWFSServer::transaction( const QString& requestBody )
// Put the Feature Ids of the inserted feature
if ( insertResults.size() > 0 )
{
QDomElement irsElem = doc.createElement( "InsertResults" );
foreach (const QString &fidStr, insertResults)
{
QDomElement irElem = doc.createElement( "InsertResult" );
QDomElement fiElem = doc.createElement( "ogc:FeatureId" );
fiElem.setAttribute( "fid", fidStr );
irElem.appendChild( fiElem );
irsElem.appendChild( irElem );
respElem.appendChild( irElem );
}
respElem.appendChild( irsElem );
}

// Set the transaction reposne for success
Expand Down

0 comments on commit 047d393

Please sign in to comment.