[Qgis-developer] plugin zoom question

bernhard.stroebl at jena.de bernhard.stroebl at jena.de
Wed Apr 25 02:43:35 EDT 2012


Hi Aaron,

the code works for me when entering it in the console directly (QGIS 
1.7.1/WinXP)
Maybe there is something wrong with your coordinates? Try to enter 
values for x and y directly in the code and see if it works.

Bernhard

Am 25.04.2012 07:00, schrieb Denis Rouzaud:
> Hi,
>
> How is defined self.plugin ?
>
> On 04/25/2012 01:30 AM, SJWC GIS wrote:
>> 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()
>>
>>


________ Information from NOD32 ________
This message was checked by NOD32 Antivirus System for Linux Mail Server.
http://www.nod32.com


More information about the Qgis-developer mailing list