Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

Python bindings for QGIS.

0
votes
0answers
15 views

PyQGIS - Automatically download local map

I am trying to develop a program which will completely automatically generate a QGIS project to display data I have collected. In order to do this I need some way of automatically downloading some ...
2
votes
1answer
54 views

Using expression to number unique string values consecutively in QGIS

I have a set of string values in a shapefile's attribute column and want to assign a number to them in a way that each unique string gets an integer number, like this: strings numbers ------- ...
1
vote
1answer
42 views

get feature on mouse click event on active layer

I am trying to write a python plugin and want to provide functionality similar to the "Identify feature" tool that already exists in QGIS. Plus the possibility to open the document relied to a feature ...
1
vote
1answer
21 views

How to remove part of a string value in the attribute table of a shapefile in PyQGIS

I have a number of shapefiles with a field in the attribute table containing many different string values similar to this one: 'Waypoints_17-JUL-18Timothy waypoints.shp Waypoints_17-JUL-18Timothy ...
0
votes
1answer
13 views

Creating and manipulating an HTML frame in QGIS3 Print Composer using PyQGIS

I'm trying to create, reposition and resize an HTML frame in a QGIS3 Print Composer layout using PyQGIS: proj = QgsProject.instance() comp = QgsPrintLayout(proj) blockStats = QgsLayoutItemHtml.create(...
0
votes
0answers
14 views

Change the TypeName of a field in PyQGIS [duplicate]

I am developing a plugin for QGIS. I would want to change the TypeName of a field from 'textEdit' to 'Value Map'. I found the documentation on QGIS.org qgis.core.QgsField.setTypeName. But I can't ...
1
vote
1answer
48 views

Select feature by id in QGIS using Python

I have a ComboBox shows feature ids of selected features in a layer. I am trying to select one feature using ids in ComboBox currentIndex. I used setSelectedFeature(), but it didn't worked.I can't ...
0
votes
0answers
12 views

QGIS 3 PyQGIS Disable Layer

I am working with QGIS 3 and trying to add Layer in QGIS Canvas using PyQGIS. What i want is that when the layer will be added in QGIS, it should be disabled as there will not be any user control it, ...
1
vote
0answers
16 views

Node demand Allocation in Water Distribution Network [on hold]

I am completely new to this QGIS. I have been given a task to automate node demand (amount of water needed). I have a "XYZ" district data set which include: district shp files, village road shp ...
1
vote
0answers
32 views

addVectorLayer('filename','layername','ogr') loads layer and names it “filename layername featuretype”

I have a PyQGIS script that loads shapefile to the canvas with this line: iface.addVectorLayer('pathto/file.shp','layername',"ogr") It was working fine and was always loading layer named 'layername', ...
0
votes
0answers
11 views

Script for computing layer statistics, create a style and save image

I tried to create a script for computing layer statistics, create a style and save image but when I run it I get an error saying "invalid syntax (, line 32) See log for more details." How can I ...
1
vote
0answers
15 views

setFilterExpression not giving results because of space

I am trying to select data based on QgsVectorLayer() getting it's features from layer.getFeatures().next() method. When I pass expression in that using QgsFeatureRequest().setFilterExpression(...
0
votes
0answers
25 views

Detect wfs connection user

I am working with plugin builder. As I can detect the user that belongs to the wfs connection, I just need the username, in order to pass it to the plugin I am developing. The configuration of the ...
1
vote
1answer
32 views

Adding an empty PostGIS table as a layer in QGIS?

In QGIS 3.2 (and 3.0), when trying to load a PostGIS layer into QGIS using a python function as follows: def create_pg_layer(table,schema,geom_column='geom'): uri = QgsDataSourceUri() # set ...
1
vote
1answer
26 views

How to correctly use the filter with empty values in pyQGIS?

I am using the version Qgis 2.14, in my script at the moment of having the layers loaded, I filter all the ToC layers with a unique value for all the layers. I use the setSubsetString('"FIELD" = \' ...
1
vote
1answer
29 views

Splitting polyline into list of subpolylines by distance using PyQGIS?

I'm actually working on a way to print parts of a Polyline according to both specified paper size and scale. The paper should be rotated in order to maximize the visualisation comfort, and this must ...
0
votes
1answer
33 views

Search any .qgs file in Python

In [Actions] How do I refer to any file with the .qgs ending within the county folder? (rather than need to specify a specific file .qgs?)
2
votes
0answers
36 views
+50

QgsVariableEditorWidget does not save changes

I would like to edit the variables of a composer item in QGIS 2.18.x. The widget itself is working so far. In my example, I am selecting a QgsComposerLabel called "Plankopf" to show its variables. ...
0
votes
1answer
39 views

Converting Kelvin to Celsius in PyQgis

from qgis.analysis import QgsRasterCalculator, QgsRasterCalculatorEntry raster = '/home/francis/QGIS/epelwrf/temp/temp0000-postwrf_d01_20180720_0600_f00000.gr2' bohLayer = QgsRasterLayer(raster) ...
1
vote
1answer
32 views

How to turn off a layer's labels programmatically in QGIS 3?

I'm trying to turn off QGIS3 (3.2) labels via pyqgis per How to turn on/off all labels of all layers in QGIS . I adapted the code in QGIS 2 answers linked above, as follows: #... def toggleAllLabels(...
0
votes
0answers
27 views

Using Python to set text for a label in a QGIS3 print layout label

I am able to assign a QGIS 3.2 print layout label item to a Python variable using: MyMapLabel = MyPrintLayoutObject.itemById('MyLabelName') Which is all well and good but I need to be able to change ...
1
vote
1answer
21 views

Do not save .pgw file

When I capture the screen and save the file it also generates a .pwg file, I do not need it, only the .png self.iface.mapCanvas().saveAsImage("doc.png")
0
votes
1answer
23 views

Saving image to variable using PyQGIS

I'm generating an image from QgsComposer composition through QgsLayoutExporter.exportToImage() method that allows to save the image to disk. I wonder if there is any way to get image binary data into ...
0
votes
0answers
34 views

How to setup Visual Studio Code (Windows) for PyQGIS 2 or 3?

I'm trying to use Visual Studio Code (VSC) as IDE for my QGIS plugins with the Python extension, but something doesn't work as expected. I've been reading about the PyCharm config from Gary S. but I ...
0
votes
0answers
27 views

How can I ask Python to listen to a click

I am currently developing a plugin for QGIS. At some point I want to print the current layer. I would want an event listener that checks the active layer whenever there is a click. Here's my code : ...
0
votes
0answers
10 views

How do I reclassify many rasters in PyQgis? [closed]

I need to reclassify many files in qgis for which I need a script, I am a new user in terms of pyqgis and I know that the file should not be very complex but as I mentioned before, I am a novice and I ...
0
votes
0answers
33 views

AttributeError: Myclass instance has no attribute 'x'

I am trying to select a feature from the layer using my plugin. When working with my plugin in main Python function using QGIS, I receive an AttributeError when I call a class method from within the ...
0
votes
1answer
40 views

QGIS API 3.2 and PyQT5 in Ubuntu Fails: Native Qt signal is not callable

I'm trying to migrate from QGIS API 2.18 to 3.2 in Ubuntu18. Several changes are made, including the update from PyQT4 to PyQT5. This is the very beginning of my code: from qgis.core import ...
0
votes
0answers
22 views

PyQGIS save as .TAB not working?

I am trying to save all the layers in Layers panel as MapInfo TAB file Then closed them all. But, Save as part doesn't work. There is no error but it doesn't save it. When I change the format to ...
1
vote
0answers
22 views

Simple user input in QGIS with pyqt plugin

SplitPolygon plugin allows the user to enter an angle by which the polygon(s) will be split. I would like to modify the plugin and take that value from graphical user input (say, parallel with one ...
0
votes
0answers
14 views

Python stops working after QgsApplication.initQgis()

With a fresh install of QGIS 3.2.1. I first run this .bat file, that I modified from C:\OSGeo4W\bin\o4w_env.bat to explicitly state the location of the .bat file (2nd line). This mod was necessary to ...
1
vote
0answers
18 views

pyqgis: release all image locks

I have a QGIS 3.2 workflow that helps me to mass produce image classiication labels for some deep learning work. The workflow creates multiple files with various prefixes in tif format. At the end ...
1
vote
1answer
24 views

Fill a comboBox with the result of a query to sqlServer

I need to fill a comboBox with the result of a query to sqlServer, this result is filtered according to the data that was entered in the batch field Try doing it with pyodbc, but when the form is ...
0
votes
0answers
21 views

Create axes given origin and angle [closed]

I have a QgsPoint. One of the attributes of this point is 'heading', a number from 0 to 359 indicating an angle. I want to create two lines going though this point, one in the direction of this ...
0
votes
0answers
15 views

Altered Minimum Bounding Box Algorithm [duplicate]

I'm trying to create an algorithm similar to minimum bounding box (though it may end up looking nothing like it). In this case the angle will be passed as a parameter and given the angle I need the ...
2
votes
2answers
61 views

How do I run SAGA algorithms in PyCharm? [closed]

Is there anyway I can input a raster and number and then use the SAGA algorithm "Fill Sinks (Wang and Liu)" on the raster through an IDE such as PyCharm? How would I go about calling the algorithm? ...
1
vote
1answer
32 views

Correct way to delete a field, add a field and update attributes in pyqgis

I am working on a script that runs a model and then appends the result to a spatialite layer. The model runs zonal statistics using 4 different rasters and appends them to the attribute table of a ...
0
votes
2answers
41 views

Exporting map canvas to PNG file using custom plugin created by Plugin Builder

I'm making a complement for QGIS3, how can I export the map I'm seeing in the window to .PNG using Plugin Builder. Without having to go through Print Composers.
-1
votes
0answers
30 views

Running Processing scripts from an IDE?

I've exported a python script using the processing modeler. Is there anyway I can run it through an IDE like PyCharm or Spyder? If so, how do I set up the IDE?
0
votes
2answers
48 views

OGR says that my data source is invalid when I use the method QgsVectorLayer in PyQGIS

I am begining with PyQGIS and QGIS in general. I wanted a way to create a layer via python, so i downloaded "Plugin Builder" and starded coding. Here's the code : def activatePlugin (self): ...
1
vote
1answer
40 views

How to iterate through a list of polygons' centroids in QGIS

I'm the new one. I try to calculate the azimuth between a row of polygonsheets to print the number of the last and the next sheet inside the sheet in direction of the last and the next sheet. This ...
1
vote
1answer
24 views

PyQGIS Raster Value Range

I have a geotiff that I've generated the way I'd like it displayed in QGIS. When I load the image as a raster layer, however, it automatically re-scales the pixel brightness values, and the image ...
2
votes
1answer
26 views

How to call “Clip Raster by Mask Layer” tool using QGIS console? (gdal:cliprasterbymasklayer)

I execute the followng code in QGIS 3.2.1 console, but Clip Raster by Mask Layer tool doesn't work - output file is not created. Here is QGIS console output: None # perhaps this None appears as a ...
0
votes
0answers
19 views

I'm trying to do ‘Multilevel bspline interpolation’ in QGIS using Python console, [duplicate]

I'm trying to do ‘Multilevel bspline interpolation’ in QGIS using Python console, but I am getting errors such as “Algorithm not found ” and “wrong number of parameters.” Here is my code : ...
0
votes
0answers
26 views

Multilevel bspline interpolation

I'm trying to do ‘Multilevel bspline interpolation’ in QGIS using Python console, but I am getting errors such as “Algorithm not found ” and “wrong number of parameters.” Here is my code : ...
1
vote
1answer
41 views

Polygon area calculation discrepancies

I use the following code to calculate the areas of a multi-polygon shapefile. However, to validate these results, I calculate the polygon’ areas directly in table attribute by creating a new field and ...
0
votes
1answer
18 views

Unable to load layers from MSSQL PyQGIS

I have a plugin that loads layers from SQL Server 2008. It has worked before but when I reset my PC, i wasn't able to backup my plugins. I am left with an older copy. Below is my python code to load ...
0
votes
1answer
39 views

How to add a layer to a group in layers panel?

I am trying to add a group to the layer panel, then place a vector layer (vectorLayer) into this group from a python script. The code I am using is: groupName="test group" root = QgsProject.instance()...
1
vote
0answers
19 views

QgsMapCanvas.setExtent() has no effect when loading and rendering many layers

The following script is intended to load a pile of vector layers (50 times the same) and after loading to set map canvas center and scale: from qgis.core import QgsProject, QgsVectorLayer, ...
1
vote
3answers
80 views

Convert dwg (CAD) to shp in any open source GIS software?

I would like to do what's needed in a GIS (GRASS, QGIS, etc) alone, no other converters-only. In Arcmap it can be done using Arcpy but it would be important to do this using open source GIS. The ...