<div dir="ltr"><div>Hi,<br><br>I'm trying to write my first plugin with pyqgis. I usually do my statistics analysis with R (or matlab), but I would like to speed up things with a custom plugin. Who knows it could be useful in the future for others.<br>
<br>I tried R in Sextante, but I think a separate plugin would be more useful.<br><br>ok, I created my plugin structure with pluginbuilder and started to customize things.<br><br>To keep it simple, in my ui file, I created a qcombobox to select a layer, and a qlistwidget to select one or more than one fields.<br>
<br>In my py file the code is something like this (most of this is adapted from other people's code :-) )...<br><br>-----<br>    def chooselayer1(self):<br>        self.dlg.ui.chosenlayer1.clear()<br>        for name, layer in QgsMapLayerRegistry.instance().mapLayers().iteritems():<br>
            if layer.type() == QgsMapLayer.VectorLayer:<br>                self.dlg.ui.chosenlayer1.addItem(<a href="http://layer.name">layer.name</a>())<br>                self.set_select_attributes()<br><br>    def set_select_attributes(self):<br>
        self.dlg.ui.Column.clear()<br><br>    if self.dlg.ui.chosenlayer1.currentText() != "":<br>            layername1 = self.dlg.ui.chosenlayer1.currentText()<br><br>            for name, selectlayer in QgsMapLayerRegistry.instance().mapLayers().iteritems():<br>
                if <a href="http://selectlayer.name">selectlayer.name</a>() == layername1:<br>                    for field in selectlayer.dataProvider().fields():<br>                        self.dlg.ui.Column1.addItem(<a href="http://field.name">field.name</a>())<br>
-----<br><br>Question 1: I want to include a button to calculate for example relative frequencies for a field.<br><br>In R I would something like:  data$fx <- data$x / sum(data$x) ###this would add a column to object data<br>
<br>In pyqgis, I would need to get for example the selected field.<br>Would it be something like: selectlayer.pendingFields() / "sum of x which I have no idea how to calculate".<br><br>Question 2: create a button to sum a selection of fields: again, in R: data$s <- data$var1 + data$var2.<br>
<br>I know this are very beginners' questions. I've been studying the material in pyqgis cookbook and qgis api. It's very useful, yet I'm still struggling.<br><br>Another detail which makes it much harder for beginners are the changes in api 2.0. For all beginners out there it makes it quite hard to google for help. But I guess there's no way around it.<br>
<br>Thank you for your help,<br></div>Aline<br></div>