Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using the WMS-provider.inspect as feature in pyqgis gives: "unable to convert a C++ 'QgsFeatureStoreList' instance to a Python object" #39479

Closed
rduivenvoorde opened this issue Oct 19, 2020 · 4 comments · Fixed by #39510
Assignees
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter!

Comments

@rduivenvoorde
Copy link
Contributor

plz see:
https://lists.osgeo.org/pipermail/qgis-user/2020-October/046834.html

in short:

  • users want to run a script to fire WMS-GetFeatureInfo-requests in pyQGIS
  • but the layer.dataProvider().identify in combi with IdentifyFormatFeature returns a result which cannot (yet?) be used in PyQGIS:

TypeError: unable to convert a C++ 'QgsFeatureStoreList' instance to a Python object
or:
cannot unpack non-iterable QgsRasterIdentifyResult object

Is this missing some SIP magic?
Or is this not supposed to work?

Note that
https://docs.qgis.org/3.10/en/docs/pyqgis_developer_cookbook/raster.html#query-values
do not work on a WMS?

To reproduce:

l=qgis.utils.iface.addRasterLayer(
"crs=EPSG:28992&layers=Bebouwingvlak&styles=&format=image/png&url=https://geodata.nationaalgeoregister.nl/kadastralekaart/wms/v4_0?", # uri
"buildings", # name for layer (as seen in QGIS)
"wms" # dataprovider key
)

result = l.dataProvider().identify( QgsPointXY(104606,490213),
             QgsRaster.IdentifyFormatHtml,
             QgsRectangle(104391.1406077263819,490161.0749502293766,104899.6563292678911,490283.3410253541078),
             1465,
             352,
             96)     
print(result.results()[0])  # OK

result = l.dataProvider().identify( QgsPointXY(104606,490213),
             QgsRaster.IdentifyFormatText,
             QgsRectangle(104391.1406077263819,490161.0749502293766,104899.6563292678911,490283.3410253541078),
             1465,
             352,
             96)
print(result.results()[0])  # OK

result = l.dataProvider().identify( QgsPointXY(104606,490213),
             QgsRaster.IdentifyFormatFeature,
             QgsRectangle(104391.1406077263819,490161.0749502293766,104899.6563292678911,490283.3410253541078),
             1465,
             352,
             96)
print(result.results()[0])  # prints: unable to convert a C++ 'QgsFeatureStoreList' instance to a Python object

@rduivenvoorde rduivenvoorde added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Oct 19, 2020
@agiudiceandrea
Copy link
Contributor

Note that
https://docs.qgis.org/3.10/en/docs/pyqgis_developer_cookbook/raster.html#query-values
do not work on a WMS?

Maybe it is due to the fact that this WMS server does not support the IdentifyValue capability?

@rduivenvoorde
Copy link
Contributor Author

@agiudiceandrea I am not familiar with the IdentifyValue capability? Is this a new WMS request?
Or do you mean 'getFeatureInfo'? Because that last one does definitly work. I think the problem that the short 'identify' and 'sample' versions do not work because a WMS always needs 'context', as in Width/Height and Bbox params?

@agiudiceandrea
Copy link
Contributor

agiudiceandrea commented Oct 20, 2020

@rduivenvoorde, with your layer (and AFAIK generally with WMS layers) : print(l.dataProvider().capabilities()) returns 928 (decimal) == 01110100000 (binary) which maps to:
Identify = True // at least one identify format supported
IdentifyValue = False // numerical values
IdentifyText = True // WMS text
IdentifyHtml = True // WMS HTML
IdentifyFeature = True // WMS GML -> feature

enum Capability
{
NoCapabilities = 0,
Size = 1 << 1, // original data source size (and thus resolution) is known, it is not always available, for example for WMS
Create = 1 << 2, // create new datasets
Remove = 1 << 3, // delete datasets
BuildPyramids = 1 << 4, // supports building of pyramids (overviews)
Identify = 1 << 5, // at least one identify format supported
IdentifyValue = 1 << 6, // numerical values
IdentifyText = 1 << 7, // WMS text
IdentifyHtml = 1 << 8, // WMS HTML
IdentifyFeature = 1 << 9, // WMS GML -> feature
Prefetch = 1 << 10, // allow prefetching of out-of-view images
};

This means that the WMS raster layer does not support QgsRaster::IdentifyFormatValue format so both identify( , QgsRaster.IdentifyFormatValue) and sample() will fail: QgsError: WMS provider Format not supported

For a WCS layers, print(l.dataProvider().capabilities()) usually returns 98, i.e. Identify = True, IdentifyValue = True.

@rduivenvoorde
Copy link
Contributor Author

Cool. Thanks Nyall!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants