Hot answers tagged

22

Interesting question! It's something I've wanted to try myself, so gave it a go. You can do this in PostGRES/POSTGIS with a function which generates a set of polygons. In my case, I have a table with one feature (a MULTILINESTRING) which represents a railway line. It needs to use a CRS in meters, I'm using osgb (27700). I've done 4km x 2km 'pages'. Here, ...


10

tl;dr import qgis import PyQt4 etc is the correct way Long version Yes the import order can matter and in the case of QGIS 2.0 and above it does matter. You should always import qgis.core or qgis.gui, even just import qgis is enough, before you import any PyQt stuff. That seems silly. Why? In QGIS 2.0 we switched to using version 2 bindings of SIP ...


9

There is differents solutions. And this can work with simple polyline and multiple selected entities block diagram: Parameters select orientation for generation and read index (left-to-right, north-to-south...) set object size shape = (4000,8000) # (<width>,<length>) define superposition coef (10% by default ?) init Ordering ...


8

Sextante is now called Processing and has become a core feature of QGIS 2.0. You can still load experimental versions of the plugin under it's new name.


7

I was starting to work with it a week ago and it's a little bit strange from the arc-user-perspective. You have to start with adding your input data for example with double-click on "vector layer". This is just an empty slot while you are creating the model. Afterwards you can add the functions. At the last function you give a name for the output. Everything ...


6

Finally found the proper way of running processing algorithms in PyQGIS standalone scripts. This answer is based on answers to Problem with import qgis.core when writing a stand-alone Python script that uses QGIS and to Error: Algorithm not found, which is in turn based on a Qgis-dev mailing-list discussion. I suggest you to follow the work flow given in ...


6

This is an example of how to open the Processing "Join attributes" algorithm by pressing Ctrl+1 (you can copy and paste it into the QGIS Python console): # Function to open the "Join attributes" algorithm's UI # See http://gis.stackexchange.com/questions/156633/how-to-launch-processing-tool-user-interface-using-pyqgis from processing.core.Processing import ...


5

If you never have run kriging before, you should understand what you are doing. If this is not the case, get a textbook on geostatistics. Anyway, most parameters are there to determine the variogram: johan@cdh7:~$ saga_cmd libgeostatistics_kriging 5 _____________________________________________ ##### ## ##### ## ### ### ## ### ### # ...


4

Here is a way to set a primitive progress bar. Design is based on example you can found within the PyQgis Dev. Cookbook (see section 11.2) Example is designed to work with features of a QgsVectorLayer but it shows the main steps you could adapt for your process algo. The key to your problem is to find a way to evaluate the progression of your algo within ...


4

Finally found the proper way of running processing algorithms via standalone PyQGIS scripts. Using Processing plugin version 2.2.0-2, you can try the following script: # Prepare the environment import sys from qgis.core import * from PyQt4.QtGui import * app = QApplication([]) QgsApplication.setPrefixPath("/usr", True) QgsApplication.initQgis() # Prepare ...


4

I have found the answer I need by using the advanced python field calculator. I set the following parameters; Field type:String Field length: 10 Global Expression: import time Formula: value = time.strftime("%Y-%m-%d") This gave me a new field with today's date added at the end.


4

Right, I've tested your script and, as you say it doesn't throw anything (not even errors) when I run it. Try instead this script, it works for me on Linux, emulating your scenario (moving processing folder to my script folder): # Prepare the environment import sys from qgis.core import QgsApplication from PyQt4.QtGui import QApplication app = ...


4

The Processing menu is tied to the Processing plugin. So please check if you have deactivated the Processing plugin in the Plugin Manager.


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!


3

You can create help files via Scripts -> Tools -> Create New Script and in editing window hit Edit script help button. There you will find all the fields to fill. If your script is script.py the name of the help-file must be script.py.help and it should be placed next to the script itself (in the same folder). For example in Linux the path to the ...


3

For using processing standalone, it must be initiated with an interface. Thus, you can create a dummy iface before calling processing (this worked for me for QGIS 2.4): import qgis app = qgis.core.QgsApplication([], True) import processing class DummyInterface(object): def __init__(self): self.destCrs = None def __getattr__(self, *args, ...


3

first thing, osgeo.gdal is for pure Python scripting: from osgeo import gdal raster = gdal.Open('your.tif') raster.GetProjection() Everything else is a problem of osgeo, and not of PyQGIS, since you use 2 QGIS existing layers: ##raster_1=raster ##raster_2=raster you don't need it. To process the layers, the correct code is: raster_1 = ...


3

I found out what was wrong. No Layer call inside ggplot, here the right code: ##Vector processing=group ##showplots ##Layer=vector ##a=Field Layer ##b=Field Layer library("ggplot2") ggplot() + geom_point(aes(Layer[[a]], Layer[[b]])) Cheers


3

So why doesn't it work? Look at your code, specifically the line with the attribute fields. You need to point R/QGIS directly towards the field data vectors unless you attach them beforehand. The following code works without issues for me (provided that you have installed ggplot2): ##Vector processing=group ##showplots ##Layer=vector ##Field1=Field Layer ...


3

You get this message whenever the SAGA process is stuck somewhere, and therefor the resulting file is not created. The message tells you also that SAGA is correctly installed, so it must have to do with the data, or the parameters you entered. Usefull hints may come from the log, which is behind the error message box. Just a guess: Are all your layers in ...


3

Another Thing to try: Go to Processing->Options and Configuration Click on Providers->SAGA Uncheck "Enable SAGA 2.0.8 compatibility"


3

This answer is based on answers to Problem with import qgis.core when writing a stand-alone Python script that uses QGIS and to How to use QGIS explode lines with Python. I suggest you to follow the work flow given in Problem with import qgis.core when writing a stand-alone Python script that uses QGIS to enable your QGIS libraries in your OSGeo4W Shell. ...


3

Try this: import os, glob, shutil root_dir = "C:\Users\xxxx\Desktop\Test\\" country_dir = "Country_" grid_path = "C:\Users\xxxx\Desktop\Test\Grid\Grid.shp" # Get all files that constitute the Grid Shapefile gridShpFiles = glob.glob(grid_path[:-3]+"*") for path,dirname,files in os.walk(root_dir): if country_dir in path: for f in gridShpFiles: ...


3

Assuming that you always want to match like files from Original and Processed folders (i.e. Paris(O).shp always matched with Paris(P).shp or New York City(O).shp always matched with New York City(P).shp), You need to add a conditional after your second for loop to filter out everything you are grabbing from the processed folder. for f in glob.glob(root_dir ...


3

r.bioclim (I suppose, because r.bioclimatic don't exist), is an GRASS GIS 7 addon If you want to create or modify an algorithm, read the file ../processing/algs/grass7/grass7.txt that begins with "A short guide for creating and editing GRASS GIS 7 algorithms" But, how do these commands work ? to use the GRASS7 commands in processing,you need to first ...


3

The predicate is u'intersects'. For more than one predicate use an array like "[u'within',u'intersects']" The full command is processing.runalg('qgis:extractbylocation', inputlayer, intersectlayer, u'intersects', None) The possible arguments for the predicates are: ...


3

The problem has a few days ago been solved in QGIS master. I have prepared a patch for QGIS 2.10 but I hope that the QGIS developers will backport it. Since only Python changes are involved, an existing installation can now be easily fixed without having to reinstall everything.


3

The script can be placed in any paths that the environment variable PYTHONPATH has. If some of the default locations don't suit your need, then you can make changes to PYTHONPATH as needed. In QGIS, you can append or prepend the PYTHONPATH variable. Check out the System tab in the Settings > Options window. Place a check beside Use custom variables ...


3

Processing provides example code for a new algorithm provider. It's located in the processing folder inside your home directory, e.g. on my machine: C:\Users\anita\.qgis2\python\plugins\processing\algs\exampleprovider Based on these example files, you can build your own plugin which can contain as many new algorithms as you want.


3

You can do that from the QGIS Python console in this way: # Import both Processing and CommanderWindow # classes from the Processing framework. from processing.core.Processing import Processing from processing.gui.CommanderWindow import CommanderWindow # Then get the algorithm you're interested in (for instance, Join Attributes): alg = ...



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