My Ubuntu has just downloaded the latest version of QGis (1.8 -> 2.01), and my plugin failed with a plenty of bugs due to implemented changes in QGis API.

I still can not figure out how do I replace the function QgsRasterLayer::identify() returning the values of the raster layer bands:

rlayer = QgsRasterLayer(rlayer_path, rlayer_basebame)  
val = rlayer.identify(QgsPoint(current_point.x, current_point.y))[1]

What should I use instead of the one?


As I can see now, QGis official site has introduced these changes. The QGis classes hierarchy has become much more complex... So this code worked in my case (getting the value from 1-Band raster by x,y coordinates), but I'm not sure if this way is correct in terms of computational complexity:

rlayer = QgsRasterLayer(rlayer_path, rlayer_basebame)     
provider = rlayer.constDataProvider()
qgis_current_point = QgsPoint(current_point.x, current_point.y)
result = provider.identify(qgis_current_point, 1).results()
for key, value in result.items():                          
    print key, value.toPyObject()

Note that second argument in provider.identify(qgis_current_point, 1) belongs to enum QgsRaster::IdentifyFormat type.

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.