Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options not deleted user 23263
21 votes

Reading attribute values using PyQGIS

In order to get the information in a table you would first have to access the layer's features. In my case, I put the features in a variable. Then you loop through the features, and for each feature y …
BritishSteel's user avatar
  • 6,657
13 votes
Accepted

User Interface file compilation using OSGeo4W shell during qgis plugin creation

I will write a quick explanation of the pyuic4 and pyrcc4 commands for future reference. Most tutorials simply tell you to copy some code, but no one explains exactly what you are about to do. It is q …
BritishSteel's user avatar
  • 6,657
11 votes
Accepted

Loading CSV data table as Vector layer using PyQGIS

The following snippet works for me: uri = "file:///C:/testdata/somecsv.csv?delimiter=%s" % (";") lyr = QgsVectorLayer(uri, 'New CSV','delimitedtext') QgsMapLayerRegistry.instance().addMapLayer(lyr) F …
BritishSteel's user avatar
  • 6,657
9 votes
Accepted

How to access a specific feature?

You could access the specific feature, without a loop, using the setFilterFid() method. In your case, if you wanted to call the feature in row 222, you would do: aLayer = iface.activeLayer() reques …
BritishSteel's user avatar
  • 6,657
9 votes
2 answers
2k views

Using memory layer as input and/or output with runalg?

Can a memory layer be used as an input and/or output with runalg? With runandload I get this to work: processing.runandload("qgis:mergevectorlayers","memory:bufferOne", "memory:bufferTwo", r"memory …
BritishSteel's user avatar
  • 6,657
9 votes
3 answers
4k views

Performing a Spatial Query in a loop in PyQGIS

What I am trying to do: loop through a point shapefile and select each point that falls into a polygon. The following code is inspired by a spatial query example I found in a book: mitte_path = r"D: …
BritishSteel's user avatar
  • 6,657
8 votes
1 answer
4k views

Using qgis:selectbylocation in PyQGIS

I am trying to use the processing toolbox to perform a spatial query (points in polygon). I am not sure how to use the tool and I keep getting this Error: Wrong number of parameters. Here is my scri …
BritishSteel's user avatar
  • 6,657
5 votes

Split feature by line in PyQGIS

A simple way would be using The polygon-line intersection tool from the SAGA toolbox. This would work: import processing polys = QgsVectorLayer(r"C:\PyQGIS_Test\polys.shp", 'poly', 'ogr') lines = Qg …
BritishSteel's user avatar
  • 6,657
4 votes
1 answer
118 views

Getting only joined fields using PyQGIS

I am not performing the join via PyQGIS. The join is done manually and I would just like to use PyQGIS to detect which fields have been joined. …
BritishSteel's user avatar
  • 6,657
4 votes
1 answer
371 views

Adding a PyQGIS Plugin to the Database Menu

According to the PyQGIS Developer Cookbook all I have to do is add category=Database to my plugin's metadata.txt. However, that does not have any effect. …
BritishSteel's user avatar
  • 6,657
4 votes
2 answers
3k views

Why use QgsFeatureRequest() when iterating?

I am unclear on why one should use QgsFeatureRequest() when iterating over a file’s features. Let’s say I would like to print out all IDs in my currently active dataset. Now, most examples will provi …
BritishSteel's user avatar
  • 6,657
4 votes
Accepted

How may I use Umlaute programmatically to show up correctly in PyQGIS messagebar?

Two steps: - add a line that indicates UTF-8 encoding to the top of your script - add the letter u (to indicate unicode) before the string that contains the umlaut For example, the following snippet: …
BritishSteel's user avatar
  • 6,657
4 votes
Accepted

Performing a Spatial Query in a loop in PyQGIS

With some advice from a workmate I finally got it to work using within(). General logic get features of polygon(s) get features of points loop through each feature from polygon file, and for each: …
BritishSteel's user avatar
  • 6,657
3 votes

Using PyQGIS, how do you project a shapefile from EPSG:4326 to 3857?

You can use the Reproject Layer algorithm from the processing toolbox. Let's assume you have a cities.shp in a folder named testing, and you want to create a new file cities_prj.shp that is transform …
BritishSteel's user avatar
  • 6,657
2 votes
Accepted

Global name canvas is not defined

You are calling the wrong class. What you need to call is mapCanvas, and not canvas. Change your code to this: allLayers = iface.mapCanvas().layers() for i in allLayers: print i.name() This wi …
BritishSteel's user avatar
  • 6,657

15 30 50 per page