Stack Exchange Network

Stack Exchange network consists of 175 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

Questions tagged [pyqgis]

Python bindings for QGIS.

0
votes
0answers
15 views

QGIS Required Edit Field

is it possible to set a field in QGIS to "required" using PyQgis? The user should select a value from a valuemap in my plugin. If he has not selected a value, he should not be able to save the object. ...
0
votes
0answers
22 views

QGIS Set Label Placement in Python

I'm writing a plugin that extracts some data from a Postgres database, saves a point shapefile of the data and displays it in QGIS. As part of that process, I want to generate a QML style file. I ...
-1
votes
1answer
29 views

Python code indentation in QGIS

I'm writing Python macros in QGIS project properties/macros window (3.4/3.6). I lose quite a lot of time correcting errors due most of the time to indentation errors. I find QGIS macro window rather ...
1
vote
0answers
22 views

Calculate net elevation gain from a vector?

I have a vector data (path/route) with points equally spaced with elevation data (in the attributes table). The elevation data was extracted from a raster. I would like to calculate net elevation gain ...
1
vote
1answer
29 views

How to export attributes from QGIS to a .txtf file using Python

I have used this method outlined in: https://howtoinqgis.wordpress.com/2016/10/31/how-to-export-attributes-from-qgis-to-a-txt-file/ ##input_file=vector from qgis.core import * import processing # ...
-1
votes
1answer
32 views

Any algorithm to draw lines inside a shape? [on hold]

Let's say you have a circle and have all the coordinates (x,y) that make up the circle.... How would you create lines (vertical and horizontal inside it? What about a rectangle? What if you have the ...
0
votes
0answers
29 views

Creating DEM from contour pyQGIS? [duplicate]

How can I create Digital Elevation Model using python codes in QGIS software?
0
votes
0answers
17 views

QgsMeshLayer in memory

I am trying to create a Meshlayer in memory and tried this simple test in QGIS 3.6: from qgis.core import QgsProject,QgsMeshLayer proj = QgsProject.instance() uri="1.0, 2.0 \n2.0, 2.0 \n3.0, 2.0 \n2....
1
vote
1answer
34 views

Accumulate selections by expression using a for loop (Pyqgis)

I need to run a for loop to select features by their attributes, because the values are within lists (strkey and strvalue). I'm using the following script: k=0 v=0 layer = iface.activeLayer() for ...
0
votes
0answers
13 views

Processing commands not producing shapefiles in Python 3.7

I am using a standalone python 3.7. QGIS script to reproduce a commands that work when using the QGIS interface. The code works in the standalone script (i.e. produces no errors or warnings), however ...
1
vote
0answers
26 views

Load a shapefile using PyQGIS (QGIS 3.4) on ubuntu?

I want to create a standalone application based on QGIS API. Here is my source code to load a shapefile: import sys from qgis.gui import * from qgis.core import * from qgis.core import QgsProject ...
1
vote
0answers
10 views

QGIS 3.6 splitwithlines algorithm does not always split

I'm trying to split one line layer with another line layer, and additionally get the vertices where they intersect. However, if a line is self-intersecting, it does not split the underlying layer. In ...
1
vote
0answers
19 views

Loading temporary layer in processing PyQgis 3.4 [on hold]

I have been working on processing script in PyQgis 3.4 and i have serious issues with loading temporary layers to project after processing. Since following code works perfectly fine: entimport ...
0
votes
2answers
39 views

Transforming time series gridded meteorological data from .csv file to multiple .shp files (one per date) with pyQGIS

I downloaded gridded meteorological data as .csv file from the JRC CGMS database for a territory of interest. The file has data for predefined point locations over the territory in a regular-spacing ...
1
vote
0answers
30 views

How to build loop using memory layer with PyQGIS 3?

I have a "for" loop included on a "while" loop, and it work when I save the for loop result in a shapefile and I reuse it on the loop like that : #last step of the "for" loop alg_params = { ...
1
vote
0answers
20 views

Saving raster layer to disk using Python: TIFF raster layer loses data type when saved with QgsRasterFileWriter

I'm trying to save a TIFF image stored as a raster layer. The image is fetched from a server so that its source (the url passed when creating the layer) is a HTTP url: the image should be saved to ...
2
votes
0answers
18 views

Adding shape of defined dimensions in metres on an WGS84 ellipsoid using PyQGIS in QGIS 3.4

How can I place the shape of defined dimensions (in metres, 5000m X 2000m) measured around the WGS84 ellipsoid at a location on the ellipsoid (51 degrees N 2 degrees W)? Joseph provided a very ...
1
vote
0answers
26 views

How to Export a QGSVectorLayer as KML format with style

i have a vector layer with geometry type PointGeometry and styled with QgsGraduatedSymbolRendererV2 renderer. i have tried: QgsVectorFileWriter.writeAsVectorFormat(layer,"kml_example.kml","utf-8",...
2
votes
2answers
43 views

Adding shape of defined dimensions using PyQGIS in QGIS 3.4

I am attempting to add a feature with defined geometry as a layer. Having added the feature I checked on the dimensions of its sides and they measure differently. This is the code that I am using. x ...
2
votes
1answer
27 views

How to set label color with setCustomProperty in QGIS2?

I can set most font properties like this: layer.setCustomProperty("labeling", "pal") layer.setCustomProperty("labeling/enabled", "true") layer.setCustomProperty("labeling/fontFamily", "Noto Sans") ...
3
votes
0answers
43 views

Lines length plugin - QgsVectorLayer error

Several similar questions have already been made, but none of the is helping me. I have a layer of polygons and I want to known the length of each line of each polygon. And based on the length I ...
1
vote
1answer
48 views

How to import a shapefile from database into QGIS plugin?

I am building a QGIS plugin, and want to add some base maps from the shapefiles which were stored in the PostgreSQL database. My question is: Is there a way to import shapefiles stored in the ...
2
votes
1answer
27 views

Conditional statement in PyQGIS field calculator

I am trying to perform a if/elif/else routine in the field calculator environment from PyQGIS (i.e. coding in Python). My code is the following, however I keep getting indentation errors. The field ...
1
vote
0answers
25 views

Overriding the QGIS Feature Dialog?

NZ Farmer gave a solution how to use a control function for a customised attribute form from within your own plugin. It seems that the control function accompanying a customised UI Form needs to be a ...
1
vote
0answers
33 views

QGIS crashes when trying to return layer from processing toolbox console

The following script is intended to take a polygon layer and extract the features having a particular value ('natural') in a given field ('landuse') and return the selection. Everything seems to work ...
1
vote
0answers
19 views

Is there a standard way to apply different field values to linestring vertices?

In QGIS I have several 3D points that I am creating a linestring from and each point could have a different value in one of the fields like "type". I want to somehow create the linestring and be able ...
0
votes
0answers
14 views

Loading layer with QgsVectorLayer in standalone PyQgis 3

I can't seem to figure out why my layer won't charge in QGIS. After reading many topics, it seems to be linked to the prefix path. However changing this, does not seem to work (I tried around 10 ...
1
vote
2answers
63 views

Selecting by attribute using Python and a list

I have been using this script to select a feature using Python: layer = iface.activeLayer() layer.selectByExpression('\"Declividad\"= value', QgsVectorLayer.SetSelection) selection = layer....
1
vote
0answers
36 views

Processing error when using PyQGIS in PyCharm

Running processing alghorithms works fine from the Python console in QGIS. I am using OSGEO4W (Python 3.7). However when trying to run the same processing algorithm in PyCharm, I get the following ...
2
votes
1answer
30 views

Create Memory layer in pyQGIS with projected coordinates

I am trying to make a memory layer in QGIS using python and then generate a grid base on calculations in meters. When I run the script, a banner comes and says the CRS is not defined. Then when I look ...
1
vote
1answer
57 views

Is my layout window open?

I would like to execute some code only if a given layout window is open ... Is there a way to programmatically detect this ? I've browsed the QgsPrintLayout and QgsLayout classes and i didn't find ...
1
vote
0answers
48 views

Error during a for loop in Python terminal from QGIS 2.18.17

When I run the script below in Python Terminal at QGIS 2.18.17 (Linux Mint 19) it always crash after doing 73 iterations at the 2nd for loop from the script. Could anyone explain why this happens and ...
1
vote
2answers
45 views

AttributeError: 'QgsVectorLayer' object has no attribute 'geometry'. How to fix?

Ok... So I am trying to add a column (Length) in attribut table that shows the length of each line of a line feature. A part of my code is this: geom = layer.geometry() len = ...
2
votes
1answer
34 views

Getting coordinates on click and pass it to dialog using PyQGIS?

I am creating a plugin in which i need to get coordinates by clicking on QGIS canvas so i tried the solution mentionned at Getting coordinates by clicking on QGIS Canvas with PyQGIS? but it didn't ...
0
votes
1answer
28 views

Invalid syntax when trying to define a dictionary in pyQGIS code [closed]

I'm trying to run a code in which I need to use a dictionary, but the terminal acuses 'Invalid Syntax' when I try to define that dictionary. Outside of QGIS the code runs without any problems.
1
vote
1answer
75 views

Select by location inside a for loop in Python Terminal at QGis 2.18.17

I have two shapefiles (drenagem and rio_pri). I need to loop through every feature from rio_pri and save all those features from drenagem that intersect rio_pri. So I wrote the following code to be ...
1
vote
1answer
26 views

Doing pairwise or pixel wise raster comparison using PyQGIS & Processing Scripts?

Do you know how to do a pairwise o pixel wise raster comparison using PyQGIS or Processing Scripts? Pairwise or pixel wise comparisons are made between two raster datasets pixel by pixel. That means ...
4
votes
1answer
80 views

Getting label feature with PyQGIS?

I need get the label text for each feature in a points layer. I can read feature attribute using: layer = QgsProject.instance().mapLayersByName('layer_name')[0] features = layer.getFeatures(...
1
vote
0answers
74 views

ImportError: cannot import name 'QgsGeometryAnalyzer' from 'qgis.analysis'

I am trying to do a buffer analysis of my shapefile by Python script but I have this problem in every beginning. The warning message is: ImportError: cannot import name 'QgsGeometryAnalyzer' from '...
3
votes
0answers
44 views

Grouping polygon neighbors recursively using PyQGIS? [closed]

I have a shapefile with polygons and need to group them with the same Group_ID if they touch each others. The thing is, once I start assigning a number to one polygon, it needs to keep looking for ...
1
vote
1answer
27 views

PyQGIS problem with QgsRasterCalculator CRS definition

from qgis.analysis import QgsRasterCalculator, QgsRasterCalculatorEntry import processing from osgeo import osr, gdal from gdalconst import * dataset1 = gdal.Open(input1, GA_Update) band1 = dataset1....
0
votes
1answer
20 views

pyqgis: dbf blocked after removeLayer

I developed a plugin in QGIS. One of the processes consists in remove some layers from the QGisProject, use them with other third party code in C# (maybe layers are modified by C# code) and finally ...
2
votes
0answers
38 views

Attribute from point to line using end Vertex of a line - py console

I have a line feature and a point feature. I would like to join the attribute of a point feature to the line feature based on end vertex, so when end vertex of a line falls on a point, the line ...
2
votes
1answer
66 views

Interface of QGIS plugin created by QtCreator

The image below is the interface of the plugin which I created using Qt Creator. However, when I loaded this plugin in QGIS3 (version: 3.6.1). The interface of the plugin does not appear completely. (...
2
votes
0answers
40 views

PyQGIS: creating a feature from multiple linestrings

I am trying to create a closed linestring made of a number of circularstrings, but have got stuck. I cannot see how to add the geometry from both strings. This is what I have so far. QGIS version 3....
2
votes
1answer
38 views

Adding circular string feature using PyQGIS?

I am attempting to add a circular string feature (in this case an arc of a circle). The following code runs without error but doesn't create a feature. I am using version 3.4.2. vl = QgsVectorLayer(...
1
vote
1answer
29 views

Getting rid of warning messages when selecting by location using PyQGIS?

I am running a Python script in QGIS 2.18.26 and I have a select by location with a code like that: indir = "C:/Infolder/" outdir = "C:/Outfolder/" os.chdir(indir) for fname in glob.glob("*....
3
votes
0answers
52 views

Using input layer as output in PyQGIS for QGIS Modeler?

I have written a simple Processing script to rename a given field. It works successfully, changing the input layer's field name. However, I have not been able to produce an Output. This is a problem ...
1
vote
0answers
29 views

Transform an azimuth measured in a given projection system to its value in a separate projection system

I have a set of polygons in which one of the attributes is azimuth. This azimuth was measured in ESPG:3310 (California Albers). I want to transform this measure to ESPG:4326 (WGS 84). I know the ...
1
vote
1answer
31 views

Saving only selected features after doing a selection by location in QGIS using Python Terminal?

I wrote the following script to save only the selected features after have a selection by location done. But I have got an error when the saving line is executed. I don't want to load these layers in ...