4

I want to select a feature by ID and zoom to it. I tried the following but the canvas doesn't change. Any ideas?

canvas = qgis.utils.iface.mapCanvas()
cLayer = canvas.currentLayer()
cLayer.select(51)
canvas.zoomToSelected()
4

Try this:

canvas.zoomToSelected( cLayer )

The zoomToSelected method accepts a layer as argument, see QgsMapCanvas.

However, I've noticed it should also work without argument. That's strange.

  • What (strange thing) have you done with your layer? Perhaps an on-the-fly projection or something? I'm just guessing. – Germán Carrillo Jan 21 '15 at 12:29
  • I realised somehow the selection doesn't work. You are right, the zoom works either way. – ustroetz Jan 21 '15 at 12:29
  • Yeah, that was going to be my next question! – Germán Carrillo Jan 21 '15 at 12:30

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.