Hot answers tagged

7

Saving this in a Python file and using it in the --code arg should do what you need: from PyQt4.QtCore import * from PyQt4.QtGui import * import os from qgis.core import * from qgis.gui import * from qgis.utils import iface for comp in iface.activeComposers(): print comp folder = r"C:\temp" title = "testing" printer = QPrinter() ...


6

The wonderful thing about open source is that it's possible to answer an interesting question like this when it arises ;) A large part of QGIS is in C++, but surprisingly large amounts are also written in Python, including Processing. Processing is technically a Python plugin, although it's been 'brought into core' - made into a standard feature. You can ...


6

For shapefiles already loaded into QGIS, you can use the following code in the Python Console: import processing # Set path to where you want the shapefiles saved shapes_result = "path/to/results//" # Set crs crs = 'EPSG:4326' shapefiles = QgsMapLayerRegistry.instance().mapLayers().values() for shapes in shapefiles: processing.runalg("qgis:...


5

You can use something like the following: layer = qgis.utils.iface.activeLayer() provider = layer.dataProvider() ext = layer.extent() stats = provider.bandStatistics(1,QgsRasterBandStats.All,ext,0) print "minimum value = ", stats.minimumValue print "maximum value = ", stats.maximumValue print "mean = ", stats.mean print "stdDev = ", stats.stdDev Here ...


4

Short answer: No, this is not possible. You need to have ArcView 3.x to run these files. I seem to remember there used to be an ArcView project importer made by Esri that allowed for ArcView 3.x projects to be imported into ArcGIS Desktop. However I'm not sure (Actually, I'm quite certain) that Avenue code is not converted by the importer. If you want to ...


4

## Iterate through each of the buildings That should be a single comment sign (#), not a double one, otherwise, it tries to parse it as if it was a parameter, and it fails BTW, you do not need to add the script from file. Just save it to the scripts folder, and it will be automatically added to the toolbox Hope this helps!


4

@GeoJohn: I don't know if you've solved this, but the result of the pointGeometry.projectAs("WGS 1984") needs to be assigned to a result variable (e.g., projectedPointGeometry = pointGeometry.projectAs("WGS 1984")). The original pointGeometry is unchanged by the projectAs method. The result variable should have the location in decimal degrees. I need to do a ...


4

Can you use GDAL? The first step would to be create an output merge.shp file, so file1 you would do: ogr2ogr -f ‘ESRI Shapefile’ merge.shp filename1.shp Then update that merge.shp file with the other files: ogr2ogr -f ‘ESRI Shapefile’ -update -append merge.shp filename2.shp -nln merge You would loop that last command for each of the files that are ...


4

Nice question! Say that you have a vector layer referenced: lyr = iface.activeLayer() At this point, I assume you start an edit session and digitize some features. Now you can use the QgsVectorLayerEditBuffer class, in this way: if lyr.editBuffer(): print len( lyr.editBuffer().addedFeatures() ), "features to add!" addedFeatures gives you a ...


4

It looks like your issue might be caused by as simple syntax error. The correct syntax is if __name__ == '__main__': (with double underscores around main) That if statement is essentially used to check whether the file is being executed as a standalone script or if it has been imported by some other python script. Anything inside the if statement will only ...


3

self refer to the instance of the class you have to load to make any QGIS plugin work e.g this example file. In the console, you don't need the self stuff as you don't use the same loading mechanism as in a QGIS plugin. self isn't specific to QGIS, it's a convention when doing object oriented programming with Python. You can look at some Python course to ...


3

No you can't. mapLayersByName returns a list of layers matching a single name (you can have many layers with the same name) setActiveLayer takes a single active layer because there is only one active layer at a time in QGIS.


3

It looks like your issue here is with your function x. Since nothing is being returned from the function, you cannot iterate over it. I would suggest making use of the yield keyword. This will return a generator which you can iterate over. Essentially it returns each result in the function in turn. For example: def a_function(x): for i in range(x): ...


2

Ahh I remember when I first started trying to learn python scripts for QGIS almost a year ago (and I'm still quite bad at it!). The documentation I followed to some extent was the PyQGIS Cookbook which offers help in such things as describing how to do simple tasks through the Python Console rather than through interface. Another huge help I found was in an ...


2

Tip - if running under Linux at least, stating QGIS from a terminal gives a lot more debugging info, including some errors which don't get as far as the gui. In your case, it says that the number of parameters is incorrect. If you look at the answer @gene gave, you'll see that final parameter isn't needed. Removing the final output parameter gets rid of ...


2

The latest versions of the Processing plugin (from 2.10 onwards) contains a couple of errors in the code for the Frequency Analysis tool. You can manually update the tool (located in C:\Users\You\.qgis2\python\plugins\processing\algs\qgis\scripts) or create a new script and use the following code, which is directly taken from the tool, but includes the ...


2

I would try this: '"STRNAME" = ' + "'Main'" The trick is to concatenate two strings together, and since each of the strings contains either a single or a double quote, you need to wrap it inside a pair of the opposite type of quotes. For the selectbyexpression, as you have commented, this would be the equivalent: processing.runalg('qgis:...


2

@Miro, I must say thank you again. I used your approach again and found another tool that helps i.e. "split lines with lines". For every class(order) I intersect it using the next higher order. So finally the approach I used is; Dissolve (dissolve everything with the same class) Multipart to singleparts (will break lines which are not touching to single ...


2

It all depends what are your data looking like. One easy way is to use two steps: Vector - Geoprocessing tools - Dissolve (dissolve everything with the same class) Vector - Geometry tools - Multipart to singleparts (will brake lines which are not touching to single lines) Please be aware this way the table values - start_point and end_point for lines ...


2

I got it: ##RED=raster ##a=number 0.0 ##XXX=output raster import numpy from qgis.analysis import QgsRasterCalculator, QgsRasterCalculatorEntry # Get layer object layer1 = processing.getObject(RED) # Get number number1 = a def xxx (RED,a,output): entries=[] #define raster 1 ("RED") raster1=QgsRasterCalculatorEntry() raster1.ref='RED@1' ...


2

After some search I finally found a working solution: As I saw that layer.maximumValue(idx) always kept the same value until I commited changes, I added the number of new elements and that are pending to be commited to this variable. This way I always get serial (autonumeric) number. Idea taken from here: def openProject(): from qgis.core import ...


1

I think I understand now. Let me know if this is not what you're looking for. >>> import subprocess >>> p = subprocess.Popen(['v.in.ascii', 'input=/home/username/Desktop/temp.txt', 'output=raster_pnts','x=1','y=2','fs=\',\'','--o'],stdout=subprocess.PIPE, stderr=subprocess.PIPE) >>> stdoutdata, stderrdata = p.communicate() >>...


1

The ##Input_civic_pts=vector doesn't mean the layer object, you have to use a function to get the layer object itself: inputLayer = processing.getObject(Input_civic_pts) See the documentation here: http://docs.qgis.org/2.0/ca/docs/user_manual/processing/console.html


1

You have not said what your license level is, it's always important you state this as this dictates the solution. Assuming you have at least Standard you could use the SNAP tool. I've not worked with water networks so my image below may not be correct but it at least shows you the tool. In the image below you have polygons with points and your mains. It's ...


1

This script selects at the very end all features being part of multiple combinations. It finds #2309. I have extended the list by an adress PID 3459, STREET Oxford, to deal with cases, where PIDs border at streets with equal AND different names (3x Main, 1x Oxford). Properties with all NULL attributes are ignored. # get reference to the layer layer = ...


1

I've probably misunderstood you but using None in a processing script creates a temporary output file which can also be used as an intermediate layer in scripts. From the docs: For output data objects, type the file path to be used to save it, just as it is done from the toolbox. If you want to save the result to a temporary file, use None. The ...


1

If you don't want to rename the layer, you could use the following code to load the output that's saved directly into your map project and assign it any name you wish. No need to use runandload and the only two parameters that you may want to change would be the name and the directory in the path: from qgis.core import QgsMapLayerRegistry, QgsVectorLayer ...


1

The answer is to replace 'runalg' with 'runandload' (as suggested by @Joseph). Many thanks.


1

1) Processing has a log file located in the /.../.qgis2/processing folder (processing.log). if you open this file, you find the result of the process (or the resulting errors that allow you to solve them theoretically...) The result of the "Select by attribute" Toolbox command is Started logging at Sat Oct 17 2015 18:57:39 ALGORITHM|Sat Oct 17 2015 19:...


1

First alternative: You could uncheck the Open output file after running algorithm option if you uncheck Produce output 2. As you mentioned in your comment, QGIS cannot load this output if it doesn't get processed by the algorithm, therefore disabling the option to load it should work without an error message showing up. Second alternative: Use output ...



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