If you look at the API documentation for QgsVectorDataProvider you'll see that the select method returns void (see http://qgis.org/api/1.8/classQgsVectorDataProvider.html). This is why A is of NoneType in Python.
To access the features you need to iterate over the selection set after your select statement. Here is an example using a shapefile of cities, zoomed to a small area:
iface = qgis.utils.iface
canvas = iface.mapCanvas()
layer = canvas.layer(0)
provider = layer.dataProvider()
provider.select(provider.attributeIndexes(), canvas.extent())
feature = QgsFeature()
while provider.nextFeature(feature):
attributes = feature.attributeMap()
print attributes[0].toString()
This results in:
...
Seward
Anchorage
>>>
See Iterating over Vector Layer in the PyQGIS Cookbook: http://www.qgis.org/pyqgis-cookbook/vector.html
As you are in a standalone application according to your code, you need to load your qgs/qgz QGIS project file before trying to get WFS list.
At the moment, you ask to read WFS list from an empty project. So, it will always return an empty result.
from qgis.core import *
from PyQt5.QtCore import QFileInfo
qgs = QgsApplication([], False)
successfull = QGsProject.instance().read('your_path/to/your/qgis/project.qgz')
if successfull:
print(QgsProject.instance().entryList("WFSLayers", "/"));
else:
print("Your project wasn't loaded well")
qgs.exitQgis()
Edit: the fact to load QGIS project was only part of the solution. You need to use
print(QgsProject.instance().readListEntry('WFSLayers', '/'))
instead of
print(QgsProject.instance().entryList("WFSLayers", "/"))
Found looking at QGSProject API doc
Edit 2: Illustrations about the 6 methods readBoolEntry
, readDoubleEntry
, readEntry
, readListEntry
, subkeyList
and readNumEntry
to access some of the XML content within your QGIS project file.
Difference between readListEntry
and entryList
due to xml structure in your QGIS project (see below excerpt). Explain why QgsProject.instance().entryList("WFSLayersPrecision", "/")
works and then you need QgsProject.instance().readListEntry('WFSLayers', '/')
.
<WFSLayers type="QStringList">
<value>ne_110m_populated_places_56976df7_6be4_41d8_b331_a76771b8141d</value>
</WFSLayers>
<WFSLayersPrecision>
<ne_110m_admin_0_countries_d24b9f99_da2b_470c_966c_7402b525eace type="int">6</ne_110m_admin_0_countries_d24b9f99_da2b_470c_966c_7402b525eace>
<ne_110m_populated_places_56976df7_6be4_41d8_b331_a76771b8141d type="int">6</ne_110m_populated_places_56976df7_6be4_41d8_b331_a76771b8141d>
</WFSLayersPrecision>
You can also test the following:
QgsProject.instance().readNumEntry("WFSLayersPrecision", "/ne_110m_admin_0_countries_d24b9f99_da2b_470c_966c_7402b525eace")
,
QgsProject.instance().readBoolEntry(f"WMSServiceCapabilities", "/")
QgsProject.instance().readDoubleEntry(f"PAL", "/CandidatesPolygonPerCM")
QgsProject.instance().subkeyList('DBManager', 'savedQueries')
(need to save a SQL query in DB Manager to get results)
Best Answer
You should be able to do something like:
I tested this in QGIS 3.4 on a new project and it worked fine with no other layers loaded (see image below).
It should also work fine when loading subsequent layers. However, if you want to be more explicit in referencing a layer, you could use something like the following (assuming that the
name
variable holds the reference to the name of the layer you want to put into edit mode):