Tag Info

New answers tagged

1

intersects gives the boolean value True, False, intersection gives the geometry If you use the dir function of Python dir(intersection) ['Error', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__geo_interface__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', ...


0

Hey moderator that deleted my last post on the same topic, please leave this one up. This is completely relevant because I don't believe the answers above still work and I'm not the only one that's struggling here. Either I'm crazy, or the two bits of code no longer work. I've copied these and tweaked them for my use and for the life of me I can't get a tif ...


1

There is a nice example from QGIS Python Cookbook: from PyQt4.QtGui import QColor # load the vector layer: lyr = QgsVectorLayer("Users/joellawhead/qgis_data/hancock/landuse.shp","Land Use", "ogr") # create our three land use categories using a Python dictionary with a field value as the key, color name, and label landuse = {"0":("yellow", ...


1

if geom.isMultipart() is False: # if only simple polygon, calculate only for this polyg = geom.asPolygon() # transform to list of points for ring in polyg: # doSomething...FILL HOLES else: # is multipart multi = geom.asMultiPolygon() for polyg in multi: for ring in polyg: # doSomething ...


1

After having investigated the QGIS code, I'd decided that custom code needs to be created to store and load composer configurations. The QGIS desktop app does it all with custom classes and not the common library, so a standalone app written in python is going to have to do the same for the time being. relevant files: src/app/composer/qgscomposer.cpp ...


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

You will need to call the method QgsComposer.readXML(node) with the XML node representing the composer you want to load. The QGIS desktop app does it this way: create a slot method that takes a parameter loadComposers(doc) Search for doc.elementsByTagName("Composer") Iterate over all found xml_nodes and Create a new QgsComposer Call ...


1

The QgsRubberBand does not support holes. The rubberband it is the kind of thing that is used to represent an ongoing action with the mouse. You would use it to draw the shell of a polygon or cut a hole from an existing shell. If you need support for holes, you need to use QgsHighlight instead.


1

You can do that from the QGIS Python console in this way: Copy the next function, taken (and slightly adapted) from the Processing framework source code, into the QGIS Python console: from processing.core.Processing import Processing from processing.gui.AlgorithmDialog import AlgorithmDialog def runAlgorithm(alg): """ Borrowed from CommanderWindow.py, ...


1

In ArcGIS... Let's say you have polygons and lines such as in the example below: Perform a feature to line, with the polygons and the lines as your input. This slices the polygons by the lines. Select all the features on one side of the line. Export selected features. Turn off all layers except the new layer. Select the 'slivers'. Perform ...


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

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 ...


1

in your plugin init() you can add a listener to iface.initializationCompleted signal http://qgis.org/api/classQgisInterface.html#a6f1cc8be7d4e0b4c76c2806b78b3d8b0 then do what you want regards


0

You can use the following script (save it in Processing Toolbox > Scripts > Tools > Create new script) in the graphical modeler to copy the first row of attributes and apply it to each feature in the input layer. (Unfortunately I was unable to add a filter for your required fields so hopefully others can provide a solution which completely answers your ...


1

Hausdorff Distance To actually quantify how regular a polygon is, POSTGIS has an implementation of Hausdorff Distance, ST_HausdorffDistance(geom1,geom2). You could compare the polygon geometry with something like the bounding box of your polygon, the minumum bounding circle a simplified version of your polygon for example. any of these would give an ...


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 ...


1

Great methods already posted! There are also tools from the Processing Toolbox which you could call from your script (this is assuming you are running scripts inside QGIS): Count points in polygon Counts points in polygon (weighted) Count unique points in polygon Taking the first tool, you could call it using: import processing Result = ...


1

It is a pure Python question: in your script you initialize the list at each iteration t = [1,2,3,4] for i in t: l = [] l.append(i) print l [4] while l = [] for i in t: l.append(i) print l [1,2,3,4] or with list comprehensions l = [i for i in t] So, your script becomes: l = [i.attributes() for i in layer.getFeatures()]


1

In this order: l = [] for i in layer.getFeatures(): l.append(i.attributes()) In your code you have list which is created and overwritten each time.


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.


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 ...


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( ...


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)


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.


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 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


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" ...


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 ...


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

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

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

there are few (paid and free) third party programs you can use to convert csv to dbf (just google csv to dbf) and a few (free) online tools. Online: http://www.files-conversion.com/spreadsheet-converter.php http://dbfconv.com/ programs: http://www.dbf2002.com/csv-converter/convert-csv-to-dbf.html http://dbfview.com/csv-dbf.html last depending on your ...


0

1 - Add your functions in Myplugin.py. You can also add in Myplugin_dialog.py, but for start try add in Myplugin.py 2 - Also in Myplugin.py in class Myplugin in function init you can catch signals, e.g. self.dlg.pushButton.clicked(self.my_function) Have "def my_function(self):" in the same class. Hope that helps!


0

You can use predefined color ramp by using QgsGraduatedSymbolRendererV2 rather than QgsCategorizedSymbolRendererV2 Here is the code: myRenderer = QgsGraduatedSymbolRendererV2() myRenderer.setClassAttribute(field) myRenderer.setMode(QgsGraduatedSymbolRendererV2.EqualInterval) ...


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

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 ...


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.


1

I had the same problem and found a solution for QGIS version 2.10.1. The size of the box/scene containing the image need to be big enough, otherwise it is not visible. According to the pyQgis API documentation it also resizes the svg. You have to add the following line before adding it to the composition. northarrowIcon.setSceneRect(QrectF(0,0,20,20)) ...


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

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

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 ...


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 ...


0

I ran across this problem and came to a solution. I added a question/answer post to add some insight to this problem. See that here.


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 ...


0

You may need to upgrade your version of QGIS. From what I can gather, versions of QGIS before 2.6.0 had an issue where extra GDAL parameters passed to the processing plugin were quoted in a way that GDAL wouldn't recognise them. (We've had to work around this issue ourselves as we can't upgrade our version of QGIS. Our workaround is to build our own GDAL ...


1

The problem is that you are using an empty list for categories, [], at the renderer constructor class: renderer = QgsCategorizedSymbolRendererV2("SETOR", []) It needs a QgsRendererCategoryV2 object class. I don't know how to do that precisely but, I modified your code for creating the categories from a dictionary, by using the colors of ramp named ...


1

Next script works for me. layer=iface.activeLayer() myGrayRenderer = QgsSingleBandGrayRenderer(layer.dataProvider(), 1) layer.setRenderer(myGrayRenderer) renderer = layer.renderer() provider = layer.dataProvider() layer_extent = layer.extent() uses_band = renderer.usesBands() myType = ...


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 ...



Top 50 recent answers are included