Python bindings for QGIS.

learn more… | top users | synonyms (1)

5
votes
2answers
605 views

Load and display a layer from SQL Server using PyQGIS

I'm having a go at using pyqgis from within the QGIS python console to load a layer from SQL Server and display it. I feel like I'm part way there but I'm having a real issue getting the layer to ...
0
votes
0answers
16 views

polygonize giving duplicated polygons

I am trying to reproject some ascii files and convert them into shapefiles. I am new to python but looking at some code online and help files I was able to write the following code to run on Python ...
1
vote
1answer
42 views

differences in distance between shapely and geopy

I am getting totally different distances from shapely and geopy. On one hand - it makes total sense, shapely measures on a plane and geopy measures on a spheroid. But the differences are so dramatic, ...
0
votes
1answer
31 views

Script not processing shapefiles from one folder to another

I am working on a script which takes shapefiles from one folder called "Original files", process them and then output the results into another folder named "Processed files. I asked a question on how ...
1
vote
1answer
24 views

Rename layers with script

Just discovered Qgis and really impressed! I've not formal GIS training so rely on Google to figure stuff out. I'm using the SHP files made available by the Canadian Government as part of their ...
1
vote
1answer
47 views

Where is the python library of QGIS 2.8

where is the Python library for QGIS 2.8 on a mac (10.10)? I cannot find it... sys.path in the QGIS python console gave me some path, but where the interesting part is happening it replaces the ...
4
votes
2answers
1k views

Setting the extent for a QGIS map using python

I am writing a stand-alone application in Python/QGIS that simply creates maps. I want to load vector/raster layers, set symbology, set extent At the moment, that is all! Currently I am just using ...
2
votes
1answer
44 views

Go through items in a composer legend (QGIS 2.6)

I'm trying to develop a plugin in QGIS 2.6, which opens a composer, add a map and a legend, and (among other things) adjusts the legend. Is there a way to go through items in a composer legend with ...
1
vote
1answer
25 views

Multi-Ring Buffer Methodology

When creating a multi-ring buffer I see two methodologies: Create buffer around feature, buffer the resulting buffer, and repeat for as many rings as required. Using the initial feature to create ...
-4
votes
0answers
35 views

Creating Check Boxes for all the Layers displayed inside the List View

I have a List View in my UI. Inside which I would like to display the layers loaded in my QGIS toc. For each layer in List View, it should automatically create checkboxes for all layers. How this can ...
1
vote
2answers
183 views

How to delete empty fields from a Shapefile with QGIS or ogr2ogr?

I have a Shapefile with a lot of empty columns but many of them are empty. Using QGIS or ogr2ogr, how do I remove all attribute columns where everything is NULL?
1
vote
0answers
57 views

Qgis 2.6 and 2.8. Custom form and Init function

I try to apply the good tutorial written by Nathan "Custom feature forms with Python logic". I try his sample on qgis 2.6 and 2.8. I altered the sample to allow field initialization by setting ...
0
votes
0answers
20 views

Reading/writing utf-8 encoded data using Fiona?

So I have a 'cpg' file with my 'in_file' shapefile data (definitely set to 'utf-8'). I was using 'meta' to create the same schema/crs as 'in_file'...though it runs, my text fields are borked on ...
0
votes
1answer
40 views

Problems with Geometry collections. (Fiona: write output of Multipoints and Points)

Updated: I am getting the following error on this function: ValueError: Record's geometry type does not match collection schema's geometry type: 'Point' != 'MultiPoint' The problem is that I have ...
1
vote
0answers
31 views

Something changed in QgsVectorDataProvider().changeAttributeValues() in QGIS 2.8?

I have a plugin that works with QGIS 2.2 but does not work with 2.8. Only deleteFeatures() works fine, but changeAttributeValues(), changeGeometryValues() and addFeatures() not. I receive r == False ...
1
vote
1answer
24 views

Can you change the layer name of an output vector from a processing script in QGIS?

I define an input csv file and an output like so in my processing script: ##Input_CSV_File=file ##Output_Shapefile=output vector The output shapefile is added to the map automatically when the ...
0
votes
2answers
45 views

How to measure distance using shapely

Reading the documentation...it looks like I should have this right, but I don't. The example is: Point(0,0).distance(Point(1,1)) 1.4142135623730951 Based on this example I wrote this block ...
1
vote
2answers
34 views

Writing PyQGIS Output to Shapefile

I'm trying to find the closest point on a line to another point as in this post. However when I try to write the result as a shapefile I get an error: TypeError: ...
1
vote
1answer
124 views

using postgis function in pyqgis

I'd use Postgis function in Pyqgis script. This code: qsql="(select gid, id, St_Buffer(the_geom,200) as geom from archi)" uri = QgsDataSourceURI() uri.setConnection("ip", "port", "x", "x", "x") ...
2
votes
1answer
133 views

Accessing CRS info with pyqgis in a standalone application

I'm currently having trouble accessing and defining CRS information in a standalone application. I've read the API documentation and have tried it in the python console in QGIS 2.2.0. The python ...
1
vote
0answers
35 views

While loop in QGIS modeler

I am looking for a way in QGIS - preferably using the graphical modeler but console scripting will also do - to build a model that iterates through features of a given layer until a condition is met - ...
1
vote
0answers
59 views

can not delete file after using runalg function

I my plugin I use the runalg function: processing.runalg("qgis:clip",filepath + "/temp2.shp", Layer, filepath + '/' + layerName) vlayer = QgsVectorLayer(filepath + '/' + layerName + '.shp',layerName, ...
1
vote
1answer
44 views

How to call 'shapely' .coords on a fiona filtered list?

I have to filter a shapefile by attribute then compare it to another shapefile using .coords...however I am a bit perplexed how to do this as my filter is returning a list type...(and .coords requires ...
1
vote
1answer
44 views

No expected output when accessing variable from one function and using in another fucntion

I have a function say selectedfeatures this function would be called when a selection changed event happens in mapcanvas. self.canvas.selectionChanged.connect(self.selectedfeatures) ...
0
votes
1answer
25 views

Behaviour of Select Feature by Freehand tool in my own plugin

I am calling QGIS "Select Feature by Freehand tool" in my plugin. what it will does is it allows the user to select features in mapcanvas and i made a signal like if selection changed in mapcanvas , ...
1
vote
1answer
34 views

How to define an event for features selected in mapcanvas in qgis using python

I have created a push button, when it is clicked it calls the function 'selectfeatures'. This function will call the Select feature by free hand tool of QGIS and allows the user to select features in ...
2
votes
1answer
232 views

Setting up pycharm and pyqgis

I wanted to set up PyCharm the way this blog post explains: Setting up PyCharm for PyQGIS and Qt. I did everything as instructed but when it comes to adding project interpreters I got this error ...
1
vote
1answer
33 views

How to replace VectorWriter with QgsVectorFileWriter?

Within QGIS 2.8.1 I found within the Processing Toolbox a script called "Points on crossing lines" which should exactly as it is named. Unfortunately it needs processing.core.VectorWriter which I ...
4
votes
2answers
925 views

How to change the color of a vector layer in pyQGIS?

Is it possible to change the color while adding a vector layer? I have a vector layer with water areas and want to load it with a blue color style. The layer is added with: ...
2
votes
1answer
126 views

Loading features attributes into numpy array

I am currently working on an add-on that relies on the user choosing fields of tables (that can be from shapefiles, csv or dbf) that are open in QGIS and then making computations with such data. ...
1
vote
1answer
29 views

PyQGIS - Setting Scale Dependent Visibility for WMS

This code imports 'MiniScale' mapping from my WMS miniScale = ...
4
votes
2answers
429 views

How to add a layer group using pyQGIS?

Good morning, I would like to know how I can create a new group in the layer manager using python code, someone could help me?
1
vote
0answers
17 views

QGIS plugin : connect to polygonselect Maptool signals

Working on a new plugin I am trying to connect a custom function to the mouse right-clic signal while using the polygon selecting maptool. I have activated the maptool through : def run(self): ...
3
votes
2answers
83 views

Rotating geometry to specific angle using pyqgis?

I do not know how to rotate a geometry using pyqgis. Is there any sample/example code available to show me how?
3
votes
1answer
70 views

Error writing memory layer to shapefile in QGIS

I have created a memory polygon layer in my QGIS plugin. Then I added a buffer based on a point. I can see the ploygon memory layer in the map canvas and I can save it to a shapefile from the main ...
1
vote
1answer
125 views

Import error when utilizing QGIS's Python Init function

Based on the answer to Referencing Qt UIs external to plugin with python. I'm trying to utilize the "Layer Properties / Fields / Python Init function" to execute a file (test_file.py) that is located ...
0
votes
2answers
737 views

How to read the attribute values using pyQgis?

What is the way to get the information contained in the attribute table, say in column 2, row 2 using pyQgis?
2
votes
1answer
38 views

How to import the “QGis” class in a script?

I want to check which type of geometry the current layer has. Therefore I use the PyQGIS documentation on Access to Geometry and my code looks like: if iface.mapCanvas().currentLayer().wkbType() == ...
0
votes
0answers
37 views

How to store a triggering action and events and call them when needed using python in qgis

Can anyone explain in detail how to store the triggering action or an event that take place in the mapcanvas in a variable and call the same when needed in python. Say for example,say i have ...
2
votes
0answers
69 views

How to load all items from a template with pyQGIS in QGIS 2.6 [closed]

Since QGIS 2.6, the LoadFromTemplate method seems not work any more (or works differently?) This is my code to add items in my composer from a template : self.composition = ...
1
vote
1answer
75 views

“ImportError: no module named qgis.core” in standalone app

I am developing a standalone app (in Windows) using libraries from QGIS. When I run the script in cmd, I get the ImportError: no module named qgis.core. I read in several posts that I need to ...
2
votes
2answers
100 views

Batch add column to layers and add layer prefix in PyQGIS

I have a number of layers each with a prefix like A_ B_ and so forth. I'd like to: Add a column (text) called DENSITY to each shp Add the prefix letter from the layer name to each row in the ...
5
votes
1answer
145 views

How to open QGIS attribute table in form view using Python?

I've got a plugin where I load some layers. After the last layer loaded, I show the attribute table. However, I would like to select the form view and not the table view (see image). How can I do ...
2
votes
1answer
128 views

How to print 2 maps in the same PDF page using PyQGIS?

I am trying to generate a one-page PDF document containing the following items: 1) On the left half, a full state map (say, New York State). 2) On the top right quadrant, a map that zooms in to one ...
2
votes
2answers
60 views

Is it possible to sort the features by an attribute programmatically?

I have written a PyQGIS script that loops through an attribute table and finds duplicated values in a target attribute field. My technique requires that the attribute table is first sorted by the ...
3
votes
2answers
73 views

How to access checked layers in PyQGIS?

qgis.utils.iface.activeLayer() accesses the current active layer, but I would like to get all checked layers in the QGIS ToC. How can I do it?
1
vote
1answer
30 views

Initalize plugin with current working directory?

Upon starting Qgis, a (currently under construction) plugin needs a means of checking the current project/legend/registry. This checksum would ideally occur upon startup automatically. As the plugin ...
2
votes
1answer
45 views

PyQGIS jump to row N

Is it possible to go to a specified row number (or perhaps the next/previous) row using PyQGIS? This code gets the value of the first attribute in the first row of the table features = ...
2
votes
1answer
36 views

PyQGIS: Is it possible to replace an action triggered script by one supplied through a plugin?

In ArcView 3 all controls (menu choices, buttons, tools) had scripts associated with them that could be changed simply by supplying a script with the same name through an extension (plugin). That way ...
1
vote
1answer
47 views

Plugin to run one function when run button is clicked

My plugin gui is attached below which has two functions one is selecting state, cities from the combo box and distance to be entered in the lineedit and the other is if we click a pushbutton it will ...