1

When I try to change with python the datasource of a WFS layer, QGis crashes with this error:

Warning: QObject::connect: Cannot connect (null)::raiseError( QString ) to QgsVectorLayer::raiseError( QString )

My code is:

        ...
        newDatasource = urllib.quote_plus(wfsURI)
        WFSLayer.setDataSource(newDatasource, wfs_layer_name, "wfs", True)
        WFSLayer.reload()

where WFSLayer is a qgis._core.QgsVectorLayer.

Any suggestions?

1

My solution: i delete the old features and add new ones from temporary layer.

# delete existing features
idF = []
for f in WFSLayer.getFeatures():
    idF.append(f.id())
WFSLayer.startEditing()
for idFea in idF:
    WFSLayer.deleteFeature(idFea)
WFSLayer.commitChanges()

# new temporary layer
v_layerNew = QgsVectorLayer(uri, wfs_layer_name, "WFS")

# add new features to old layer
WFSLayer.startEditing()
for feature in v_layerNew.getFeatures():
    WFSLayer.addFeature(feature)                        
WFSLayer.commitChanges()
0

I corrected the wrong parameter "wfs" in "WFS" (uppercase), and i applied this solution to the write cache Qgis bug: Warning: QNetworkDiskCache::prepare() unable to open temporary file

Now it has disappeared the above error, but it presents a new one:

segmentation error
0

Have you tried to removing the layer by code and setting a new WFS vector layer like this:

# first instance of WFSlayer
url1 = "http://myServer.com/geoserver/wfs?version=1.0.0&service=wfs&typeName=StoreName:layerName1&request=GetFeature"
WFSlayer = QgsVectorLayer(url1, "layer1", "WFS")
QgsMapLayerRegistry.instance().addMapLayer(WFSlayer)
QgsMapLayerRegistry.instance().removeMapLayers( [WFSlayer.id()] )

# second instance of WFSlayer
url2 = "http://myServer.com/geoserver/wfs?version=1.0.0&service=wfs&typeName=StoreName:layerName2&request=GetFeature"
WFSlayer = QgsVectorLayer(url2, "layer2", "WFS")
QgsMapLayerRegistry.instance().addMapLayer(WFSlayer)
  • I don't want to add a new layer, otherwise i loose the settings of the existing level. – Luca Guida Aug 25 '16 at 7:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.