[Qgis-developer] plugin zoom question

SJWC GIS sjwcgis at gmail.com
Tue Apr 24 19:30:32 EDT 2012


Hello all,

I've written a piece of code that will search a database for a given point,
and then return that point so we can center the map canvas on it and zoom
in.  Unfortunately, it's not working.  QGIS crashes after the code
executes, leaving no error messages behind.  Is there a better way to
center/zoom to a given point?  I've tried the canvas method
"centerWithZoom" as well, with no success.  (It also crashes.)  I have
checked my coords -- they are in the proper projection (the same as the
mapCanvas) and I haven't reversed them.  Any other ideas/methods of
accomplishing this are greatly appreciated.  Thanks!

Aaron

      x = result[0][1]
      y = result[0][2]
      xscale = 1.0

      # Get the map canvas
      mc = self.plugin.iface.mapCanvas()

      height2 = mc.extent().height() * xscale / 2.0
      width2 = mc.extent().width() * xscale / 2.0

      rect = QgsRectangle(x-width2,y-height2,x+width2,y+height2)

      # Set the extent to our new rectangle
      mc.setExtent(rect)

      # Refresh the map
      mc.refresh()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20120424/0bee8dd6/attachment.html


More information about the Qgis-developer mailing list