All Questions
40 questions
4
votes
1
answer
137
views
All field type names are lowercase after using materialize from QgsFeatureSource in PyQGIS
An interesting fact, after using the materialize() method over my original QgsVectorLayer with the following code:
layer = iface.activeLayer()
for field in layer.fields():
print(f"Field '{...
5
votes
2
answers
589
views
Batch renaming of columns in attribute table for shapefiles using QGIS
I have 11 shapefiles that shows administrative areas for 11 different countries. For each country, I have 448 columns in the attribute table that records average rainfall data. They look like this:
I ...
5
votes
1
answer
2k
views
Add file name as attribute field in QGIS
I have a folder with several shapefiles (around 75). I would like to create a new field into each .shp file which has to be filename. i.e: 20201003.shp --> 20200103.shp (New field 'Fecha' = ...
0
votes
1
answer
720
views
Setting a default value in a QGIS field stored in geopackage
I try to create a vector layer with some field values which should use a QgsDefaultValue.
It works fine if I use an in-memory layer (useGeopackage=False) but fails (no default value) if I use a ...
0
votes
1
answer
275
views
How to calculate field based on another fields [closed]
I´m trying to calculate field based on another fields. I´ve got this attribute table.
Example: If field "Smisenost" is S than FRST in new field.
Example 2: If field "Smisenost" is NULL, if field "...
2
votes
1
answer
569
views
Default Value for Field with Python Expression in Function Editor
I have a line shapefile in QGIS with several columns and the values for many of those columns could be automatically calculated and updated depending on certain other fiels.
Now, I came across the ...
3
votes
1
answer
1k
views
Copy selected attributes from one field to another using PyQGIS
QGIS version 3.4
I need to copy all selected attributes from the field 'HomePostcode' into the field 'Postcode' through PyQGIS.
Using the field calculator I would simply use the expression "...
0
votes
1
answer
109
views
Field Value shapefile - Add values
I have a shapefile that contains three lines. I want to add a specific numeric id to the field "line_id" and a string id to the field "border_id".
Basically, for the first line, I want to add the ...
4
votes
1
answer
530
views
Adding new feature to layer with pre-defined attributes using PyQGIS
I am working on a PyQGIS script where I allow the user to add features using the addFeature() map tool, where the user can create the geometry of the feature by clicking on the canvas, and after the ...
3
votes
1
answer
2k
views
KeyError when trying to set attribute in QGIS?
I have two input vector layers and I want to create an Output vector layer by doing some calculations. But somehow, the setAttribute method does not work.
In QGIS 2.18, I was able to set an attribute ...
1
vote
0
answers
455
views
QGIS3: How to set an attribute value?
I have written a python script which has one output line-vector layer. The python script should calculate some value and then the script should set the attribute (with that value) of a newFeature (...
2
votes
1
answer
1k
views
Build Radio Button in QGIS Edit Widget Properties
My question is similar to Choosing multiple options from QGIS Check Box or Value Map for feature attribute?
I have 3 categories in a row, I want to make this selection in form of radio button so that ...
3
votes
1
answer
374
views
Automatically set attribute values for a layer based on proximity relations to another layer in QGIS
Is it possible to automatically set attribute values for a layer based on proximity relationships to another layer in QGIS?
This is a more generic question with a variety of applications, so here is ...
5
votes
1
answer
528
views
How to directly copy value from attribute table associated with a selected feature?
I need to copy the attribute value (only one particular attribute) of a selected point and save it in a text file. Is there any Python script or plugin which can do this for me? I need to save a lot ...
2
votes
2
answers
2k
views
How to concatenate strings separated by dot in PyQGIS?
I would like to concatenate the string of field1 with field2 separated by dot and so on. However, when I put the "." the attribute values remain null. How to separate string by dot?
e = QgsExpression(...
3
votes
1
answer
857
views
Set editor widget type for a given layer/field with PyQGIS
I would like to set the editor widget type for a a given field of a layer with PyQGIS. The actual widget type can be retrieved for example like
>>> iface.activeLayer().editFormConfig()....
3
votes
3
answers
3k
views
How to save color VALUE to attribute table in QGIS for a vector layer with a graduated symbol renderer
I am trying to achieve this -> How to copy the color styling to a color column in a layer's attribute table?
script by @Germán Carrillo
prefix = "'"
layer = iface.activeLayer()
attr = layer....
3
votes
3
answers
2k
views
Summing values from different intersecting/overlapping points in QGIS
I am currently digitizing an old archaeological excavation. I have created the 2m grid where finds were excavated, and have created centroids within each grid. All the corresponding finds has then ...
3
votes
2
answers
194
views
Appended attribute returning "Attribute index 9 out of bounds [0;9]"
I am trying to write a PyQGIS script that copies information from one feature into an output feature and adds a field.
This is how I'm initializing my fields for my output layer
inlayer = processing....
1
vote
0
answers
67
views
Codecing vectorial field qgis
I have vectorial data that I have loaded in qgis setting as UTF-8. I was checking if the values of field in atribute table is standartized. So I am creating a script to do it. However, when I print ...
1
vote
0
answers
682
views
How can my PyQGIS script copy specified attributes from one layer to another?
I am trying to create a script that will take selected features from one layer and search for the specified attributes related to a column name. in my case 'id'. What I am having trouble doing right ...
2
votes
0
answers
174
views
problem using qgis spatial join in a python script or modeler : no results [closed]
I'm trying to create polygons from points layers. Each layer contains one point to avoid troubles due to superposition of polygons. I detailed the context here : How can I add output vector to a list ...
6
votes
3
answers
2k
views
Creating QgsFeature with default attributes using PyQGIS
I have a polygon layer loaded from PostGIS database. This layer has a default value for the first column. I can create a new feature set that attribute to some predefined value with:
newFeature = ...
13
votes
3
answers
4k
views
Setting default value in QGIS field
I would like to add in a layer's field a default value. I mean, every time a new feature is created, that field would be automatically filled with the default value.
In my case the default value would ...
3
votes
2
answers
261
views
Verifying if layer is filtered using PyQGIS
I have loaded multiples duplicated layers in QGIS with different filters. I wonder if it is possible to find the layers that haven't any filter (setSubsetString method) with PyQGIS?
4
votes
1
answer
2k
views
Subsetting a shapefile and saving it using PyQgis
I am very new to PyQgis.
I have a shapefile containing a lot of information for each place, it looks like this
id stat_1 stat_2 ... stat_n
i1 0 0 2
i2 1 1 ...
2
votes
1
answer
318
views
Why is QgsFeatureIterator returning bad data?
This is a spin-off of another question I asked previously, but it has grown in scope and deserves its own thread.
While iterating over a vector layer (shapefile) I included the following if-...
4
votes
2
answers
4k
views
PyQGIS: Change attribute value doesn't work, results in NULL
I am writing a QGIS plugin, which at one point attempts to change several attribute values on a layer. However, in the end no changes are made. If I punch similar code into the built-in Python Console,...
3
votes
1
answer
122
views
Showing QgsAddAttrDialog in a Python plugin
I want to invoke the builtin add field dialog from my python plugin in QGIS:
This is the add attribute dialog of the attribute table.
It is located HERE. I expect it to return a QgsField. ...
8
votes
1
answer
714
views
Troubles Updating Values of Selected Features with PyQGIS
I'm trying to modify the values of some selected features. I have written this small script, but nothing happens when I run it. Is there something that I've missed? Here is my code.
lyr = qgis.utils....
4
votes
1
answer
305
views
Rename field QgsField is not valid
In pyQGIS i tried this code (contains also debug prints):
def joinLayers(inputlayer, layer, index_field, name = "JOINED", dataProvider = "ESRI Shapefile"):
a = []
b = []
outpath = getPath(...
3
votes
1
answer
999
views
Updating feature attribute in QGIS plugin?
I am writing a plugin for QGIS (v2.12).
There have been quite a few similar questions on this forum, but they don't seem to work for me. My plugin does the following:
get the vector layer
check ...
7
votes
1
answer
1k
views
Filling fields with conditional clauses
I have four fields in my shapefile. I would like to fill only one of them (cell of attribute table) and automatically after to write one cell the others one will be filled by conditional clause. I ...
1
vote
1
answer
742
views
Unable to update some of the attributes using PyQGIS
I'm trying to create new attribute and populate it, but for unknown reason some of the features does not update while others are updated normally.
# scores - list of values which length is equal to ...
3
votes
1
answer
2k
views
How to create a Qgis python script to manipulate fields with some parameters?
I'm just beginning with QGIS.
I have a shape file with 10 fields field1, ..., field10, and many thousands of data.
I will like to automatize the next sequence (in a python script or a model):
load ...
4
votes
4
answers
2k
views
PyQGIS: Speed up for adding features and attribute arrays?
Context:
I'm writing a dynamic import tool for QGIS (2.2 to 2.5) with python.
Datatype: Binary Datasets with environmental simulations from HPC which might contain millions of features and terabytes ...
5
votes
2
answers
4k
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?
18
votes
4
answers
19k
views
Filter features based on their attributes using Python
How to get features by their attributes (similar to 'IQueryFilter' in ArcObjects) in QGIS using Python? Instead of getting all features and filter it manually, is there any option to use where clause ...
29
votes
4
answers
59k
views
Reading 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?
11
votes
3
answers
15k
views
Getting attributes of selected features using PyQGIS
Could anybody provide an example how to get the attributes of selected features?
I tried the following code in the Python Console : but I'm stuck at the point where I'd like to get the attributes:
...