Re: [Qgis-user] python plugin action vs mode tool
gLine = QgsGeometry.fromPolyline( [ QgsPoint(1,1), QgsPoint(2,2) ] ) # buffer with distance 0.5, use 5 segments to approximate curves gBuffer = gLine.buffer(0.5, 5) print gBuffer.asPolygon() The buffer() method is a great starting point to create a geoprocessing plugin. At the moment we want to implement a geoprocessing plugin with functions like buffer, union, difference etc. At the moment we realised it with Shapely. But this approach with third party libs is not nice and would be obsolete when QGIS offers the mentioned methods. QGIS native methods() based on GEOS would be the much better approach! What are your plans? Do you plan to implement union(), difference(), intersect() and relate() as QgsGeometry methods? A second question. I want to create a dissolved buffer polygon. To achieve this it is neccessary to combine all single objects p.e. LineStrings to one MultiLineString before buffer(). How do I concatenate single Linstrings into one Multilinestring? Best Regards Horst Dr. Horst Düster GIS-Koordinator, Stv. Amtschef Kanton Solothurn Bau- und Justizdepartement Amt für Geoinformation SO!GIS Koordination Rötistrasse 4 CH-4501 Solothurn Telefon ++41(0)32 627 25 32 Telefax ++41(0)32 627 22 14 mailto:[EMAIL PROTECTED] http://www.agi.so.ch -Ursprüngliche Nachricht- Von: Martin Dobias [mailto:[EMAIL PROTECTED] Gesendet am: Mittwoch, 16. Januar 2008 23:41 An: Richard Duivenvoorde Cc: [EMAIL PROTECTED] Betreff: Re: [Qgis-user] python plugin action vs mode tool On Jan 16, 2008 8:42 PM, Richard Duivenvoorde [EMAIL PROTECTED] wrote: My 'problem': I've build a sort of XY-Info tool plugin, like the raster info plugin in the repository. But mine is suppossed to be a tool like the zoom tool, or the select tool: you click on the tool/plugin-button, the button gets activated/surpressed/darker, and keeps in that state until you select one of the other (zoom, select or info) tools. Current plugin-buttons do not get 'activated', when you click the plugin button it doesn't stay visually(!)'active', it's a clickclack button. To get the behaviour the only thing you have to do is to call map tool's setAction() or setButton() method. That will cause that when the tool is activated/deactivated, the associated action or button will get selected/delected. (This behaviour is implemented in QgsMapTool::activate() and QgsMapTool::deactivate() so that's why it's good to call them also if you reimplement these methods.) But still some details were not clear for me: for example it's not clear for me if you must make a new 'tool' when you want to make a plugin which does something with a click in the mapcanvas. No, you can use ready-made QgsMapToolEmitPoint tool and just connect to its gotPoint signal. Another question is the one about keeping a button 'activated'. I hope that one got answered above. My idea is to make some 'plugin-stubs' for different kind of simple plugins: eg starting with a very simple plugin which does not have an interaction with the map, to a tool like the xy-info tool which must handle a mouse click, and finally your copyright-plugin which was really helpful for me. But maybe a plugin stubb is not what I'm looking for: it's either to complicated because you want to make it technically useful, or it's to simple to be functionally useful. The idea was to hand beginners the first steps to to a really easy plugin. Probably the best way would be to create the same starting plugin as the template plugin written in c++. For the rest I think it's better to use code snippets... But maybe we need a code-snippets wiki page with questions like: - I want to keep de plugin button activated - I want to get hold of the active geometries of the active layer - I want to loop through all geometries of this layer - How do I test the type of a geometry - How do I make pixel coordinates from world coordinates and vice versa - How can I add a label to a (new) layer - How can I add a new geometry to a layer - How can I keep some project info by writing it to a project file etc etc. ... I should start this page myself maybe ... Well, some of those are already on PythonBindings wiki page, however some are probably missing :) I'll see what more could I add. For sure you can start a list of such simple tasks, we could address them with the code snippets. ps (referring to my buffer questions a while a go) if you point me to some 'easy' buffer algorithms, I'm ready to give C++ a try :-) ) Uhm, starting from r7986 you can use QgsGeometry::buffer() function that does exactly what you need :-) Obligatory snippet: gLine = QgsGeometry.fromPolyline( [ QgsPoint(1,1), QgsPoint(2,2) ] ) # buffer with distance 0.5, use 5 segments to approximate curves gBuffer = gLine.buffer(0.5, 5) print gBuffer.asPolygon() Enjoy! Martin ___ Qgis-user mailing list Qgis-user@lists.qgis.org http
Re: [Qgis-user] python plugin action vs mode tool
On Jan 17, 2008 10:07 AM, Düster Horst [EMAIL PROTECTED] wrote: gLine = QgsGeometry.fromPolyline( [ QgsPoint(1,1), QgsPoint(2,2) ] ) # buffer with distance 0.5, use 5 segments to approximate curves gBuffer = gLine.buffer(0.5, 5) print gBuffer.asPolygon() The buffer() method is a great starting point to create a geoprocessing plugin. At the moment we want to implement a geoprocessing plugin with functions like buffer, union, difference etc. At the moment we realised it with Shapely. But this approach with third party libs is not nice and would be obsolete when QGIS offers the mentioned methods. QGIS native methods() based on GEOS would be the much better approach! What are your plans? Do you plan to implement union(), difference(), intersect() and relate() as QgsGeometry methods? Since adding the geometry operations is just simple passing the call to GEOS routines, I've added in r7994 more processing - difference, union, intersection, convex hull, symmetric difference. (we're in feature freeze but since these additions don't infere with any other part of QGIS I think it's ok to add them) A second question. I want to create a dissolved buffer polygon. To achieve this it is neccessary to combine all single objects p.e. LineStrings to one MultiLineString before buffer(). How do I concatenate single Linstrings into one Multilinestring? Well, you can create an instance of QgsMultiPolyline (which is in fact vector of vectors of points) and export one by one all geometries to it using QgsGeometry::asPolyline() and then saving them again as geometry using QgsGeometry::fromMultiPolyline(). So we're expecting a geoprocessing plugin soon ;-) Bye Martin ___ Qgis-user mailing list Qgis-user@lists.qgis.org http://lists.qgis.org/cgi-bin/mailman/listinfo/qgis-user
Re: [Qgis-user] python plugin action vs mode tool
Hi We have the same idea already implemented for C++ programmers for some time - so maybe Martin could extend the plugin build to ask which language you want your plugin to be in and then build from a python plugin template when applicable. Qt automatically changes the brightness of buttons based on whether they are enabled or not, so I guess you need to call setEnabled on your button based on context. Regards Tim 2008/1/14, Richard Duivenvoorde [EMAIL PROTECTED]: Hi List, I'm currently working on a python plugin which is actually a click-tool, comparable to the I-tool from the attributes-view. That is: when you click the plugin button, you click in the map and something happens, you are supposed to be in that 'mode'/'state' untill you choose to use another tool (like zoomin, select etc). This opposed to (plugin)-tools which work via their own 'config'-screen: you activate the plugin, a config screen pops up, and after completing the configuration you're still in the old (eg zoom) mode. Questions: - is there a difference between these two 'modes', in term of names (tools vs wizard or so)? How do you call these? - I was not able to 'enable' my plugin button, aka: make it a little darker so you know that you're still in the xyz-mode. Can somebody point me to such an example, or are plugins not supposed to work like this? Idea: Is it an idea for one of the (python)-guru's to make two plugin annotated stubbs and add it to the pluginrepository, which can be used by 'normal' people to implement their functionality. I'm thinking of two plugins: one for this 'wizard'-like plugins and one for this 'state'-like plugin. This plugins do nothing more then enable certain (click) events in the map and do a print out (though these print out lines can't be seen in windows?). Actually in line with this wiki article: http://wiki.qgis.org/qgiswiki/DevelopingPluginsWithPython, but adding some more events, and maybe some simple qt dialogs. A user which knows a few words of python can then copy the plugin stubb, and add some simple code for example in the 'mapClick'handler, without knowing to much about the Qt-event handling system. If needed this can be learned later. Essentials: - the stubbs should contain ready made parts for thinks like: showing the essential events: mouseClicks in the map etc - there should be a difference between a (more advanced) wizard like plugin and a simple 'commandline'-plugin. Regards, Richard ___ Qgis-user mailing list Qgis-user@lists.qgis.org http://lists.qgis.org/cgi-bin/mailman/listinfo/qgis-user -- Tim Sutton QGIS Project Steering Committee Member - Release Manager Visit http://qgis.org for a great open source GIS openModeller Desktop Developer Visit http://openModeller.sf.net for a great open source ecological niche modelling tool Home Page: http://tim.linfiniti.com Skype: timlinux Irc: timlinux on #qgis at freenode.net ___ Qgis-user mailing list Qgis-user@lists.qgis.org http://lists.qgis.org/cgi-bin/mailman/listinfo/qgis-user