Tag Info

Hot answers tagged

6

You'll want to use a QgsMapLayerComboBox. If you're just after quick and dirty, you can show the combobox alone in a window using: w=qgis.gui.QgsMapLayerComboBox() w.show() Then, you can retrieve the selected layer with: w.currentLayer() You can also filter the displayed layers by calling something like w.setFilters( ...


6

I decided to play around with the System Variables part of the Environment Variables settings to see if I can make it easier to access each python installation while in the Command Prompt. I found I could add in a new System Variable and call it from the Command Prompt to access whatever python installation I wanted. Some examples: Variable = PyQGIS Value ...


4

I'm going to offer an alternative that I think is a bit cleaner. It's inspired by a combination of Josef's suggestion and a common pattern on *nix systems. Start by creating a directory. This directory will be used to hold "alias" files for each install. So something like C:\Python\aliases or C:\PythonAliases will work. Next create a script for each ...


4

Try in your script: from qgis.utils import iface #your code here iface.actionExit().trigger() It works for me. Editing Note: Based in Conley Owens'comment, I changed slightly my script to do "something useful" (where the line that import iface was commented). #from qgis.utils import iface import os os.system('clear') print "Hello" ...


3

I rewrote my answer from a parallel question counting points in current atlas feature: How to count points within the current Print composer atlas feature in QGIS 2.8? Build a new function in the expression editor: from qgis.core import * from qgis.gui import * from qgis.utils import iface @qgsfunction(args="auto", group='Custom') def ...


3

qgis.utils is a set of utilities used by the application to do Python based things. Some of these things are setting up plugins, adding Python error handling, etc. qgis.core is the main core library for QGIS. This holds most of the non ui based objects that you can use to build a plugin or standalone application. This library holds things like layers ...


2

http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/loadlayer.html If you looked here, there is "?" between name of file and "delimiter". Hope it helps.


2

This is the snipped code of my application (at the main program): . . . # Create the dialog and keep reference reload(output_file_dialog) dlg = OutputFile() #create Dialog object dlg.show() #show Dialog object dlg.ui.lineEdit.clear() #clear text in lineEdit object dlg.ui.pushButton.clicked.connect(dlg.select_output_file) #send signal ...


2

This should be all you need: feats = self.layer.getFeatures() self.layer.startEditing() for feat in feats: score = scores[i] feat['F_SCORE'] = score layer.updateFeature(feat) self.layer.commitChanges() You are mixing update via the layer vs at the provider. Generally you should only update via the layer as it provides rollback and error ...


2

In the QGIS source code, you will find the Python code for the Points in Polygon tool ... https://github.com/qgis/QGIS/blob/master/python/plugins/fTools/tools/doPointsInPolygon.py Not sure why you are coding this from scratch. You might want to have a look at Processing which allows to combine these existing tools into automated workflows.


2

Not sure if there's another way, but this is how I've implemented it. You need these three functions (make sure you import the required QGIS and Qt4 classes before): def createMapTips( self ): """ Create MapTips on the map """ self.timerMapTips = QTimer( self.canvas ) self.mapTip = QgsMapTip() self.connect( self.canvas, SIGNAL( ...


2

Easy way You don't need to write code to this Vector > Geometry Tools > Check Geometry Validity will tell you if there are any problems such as self intersection winding rule violations .. although it's only a report, it won't fix your geometry. To fix these, you can use v.clean in Grass, via the Processing Toolkit. In code If you're wanting to ...


2

From documentation: pushMessage(const QString &title, const QString &text, MessageLevel level=INFO, int duration=0) So, first and second agruments are strings. If you have some variables in your plugin, and you want to pass them into this function, you have to convert them to strings. For example we have a variable which contains coordinates and ...


2

Using QgsMessageLog you can do variable interpolation in strings using the usual python % operator: >>> QgsMessageLog.logMessage("hello") >>> x=99 >>> QgsMessageLog.logMessage("x is %s" % x) shows me "x is 99" in the message window.


2

You could use the iface.mapCanvas().layers() method, which gives you only the checked layers in the ToC, i.e., no need to iterate through all map layers. You should then iterate through checked layers to evaluate if their scale-based visibility contains the current map scale, like this: canvas = iface.mapCanvas() for layer in canvas.layers(): if ...


1

the most simple way is to use "Join attribute by location". You can do it from the menu (data managment > Join by location), or with Python ("qgis:joinbylocation") with the option "take summary of intersecting features", computing the sum of a field with "1" at each point.


1

I assume your polygon is a qgsfeature : http://qgis.org/api/classQgsFeature.html I didn't test it but I guess it would work : len(polygon.geometry().asPolygon()) polygon.geometry() gives a qgsgeometry class. qgsgeometry.asPolygon() gives a list of the point of your polygon. Edit : You want the points inside the polygon? You have points in an other ...


1

I have never worked with QGIS's python API, so my answer is a wild guess. But it looks like QGIS is using GEOS geometry objects similar to django. So this could work in QGIS too: len(geom.coords)


1

You have to get acces to an instance of that plugin: from qgis.utils import plugins instance = plugins['plugin_name'] Then if you want to use some widgets from main window ex.: value = instance.dlg.comboBox.currentText() If you define a variable under __init__, you can use it with: variable = instance.variable_name


1

This looks like an interesting plugin, and one I would have a lot of use for. You can use the inspect module to peek inside objects without using dictionaries. Better still, you can peek at the code, comments, argument lists and so on. The latter would be useful for a plugin like this ;-) Here's a quick example to get you started.. in this case, I'm ...


1

The expression editor shows a completely different syntax for the overlaps function: overlaps function Returns 1 if the geometries share space, are of the same dimension, but are not completely contained by each other. Syntax overlaps( a, b ) Arguments a → geometry b → geometry Example overlaps( geomFromWKT( 'LINESTRING(3 5 , 4 ...


1

Okay ..I figured out a way to do that . I had to use QgsGraduatedSymbolRendererV2 rather than QgsCategorizedSymbolRendererV2 Here is the code: layer = iface.activeLayer() field='count' myRenderer = QgsGraduatedSymbolRendererV2() myRenderer.setClassAttribute(field) myRenderer.setMode(QgsGraduatedSymbolRendererV2.EqualInterval) ...


1

I tried this and it worked : in your function run : Put the line layer = self.wcb.currentLayer() after if result: It did what I think you wanted it to do. On a side note : you know you can make your app calculate the average without clicking on ok? If you play with the signals, you can make a text appear in your main window each time you change ...


1

setSpatialFilter() is from GDAL/OGR not from Pyqgis. With PyQGIS, you have to deal with geometries. Check out the QgsGeometry class. It has few functions to check conditions: intersects, crosses, disjoint etc. So, to check if features in one layer intersects for example one feature in another layer, you have to get geometries of all features and check ...


1

There can be issues with QGIS but the service is also broken. Test with WFS 1.0.0 because it is the simplest of all and the server supports only WFS 1.0.0 and 1.1.0. The first test is to read the capabilities: ...


1

You should be able to form a 'get capabilities' request using your browser too, something like this: https://www.geostore.com/OGC/OGCInterface?SERVICE=WFS&UID=UDATAGOV2011&PASSWORD=datagov2011&INTERFACE=ENVIRONMENTWFS&VERSION=2.0.0&LC=0&request=getcapabilities I tested that and it works in the browser, but it doesn't in QGIS. The ...


1

I tried this with a Spatialite layer now, same result. Interestingly, QGIS shows "SQLite error: Expression tree is too large (maximum depth 1000)" in the Spatialite log panel. I've raised this issue on the mailing list and the SQLite bug should now be fixed in the latest developer version according to ...


1

This is solve for me. myFile = os.path.join('r:/Graf/_temp/Templates/', 'template.qpt') myTemplateFile = file(myFile, 'rt') myTemplateContent = myTemplateFile.read() myTemplateFile.close() myDocument = QDomDocument() myDocument.setContent(myTemplateContent, False) newcomp = self.iface.createNewComposer() ...


1

Everything's easy when you know how... For simplicity I've put the point's coordinates in here. #define the point pt = QgsPoint(289749,56754) pt = QgsGeometry.fromPoint(pt) #get the active polygon layer = qgis.utils.iface.activeLayer() polygon = layer.getFeatures().next() geom = polygon.geometry() #do the business distanceToPolygon = ...


1

I guess you have to override a mouseReleaseEvent in QGraphicsScene. class MyScene(QGraphicsScene): def mouseReleaseEvent(self, event): # here you should do something with your scene if mouse button was released then create scene with: self.scene = MyScene()



Only top voted, non community-wiki answers of a minimum length are eligible