Search Results
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 |
Use this tag when asking questions about a representation of a real-world objects on a map.
2
votes
Permanently change attribute values using PyQGIS
As was mentioned in @nr_aus's comment it is possible to edit the Esri File Geodatabase since QGIS 3.22, see the changelog for more details.
I test it with the following data file: https://gisdata-pier …
3
votes
Accepted
Calculating information for selected parts of the polygon with PyQGIS
To sum up all features' areas can be done either via
the "FIELD_NAME" field, that contains area values:
# imports
from qgis.core import QgsProject, QgsAggregateCalculator
# getting polygon layer by its … name
layer = QgsProject.instance().mapLayersByName("YOUR_LAYER_NAME")[0]
# summing area of all features
area_total_sum = layer.aggregate(QgsAggregateCalculator.Sum, "FIELD_NAME")
print(area_total_sum …
6
votes
Accepted
Showing feature count in layer name in QGIS
single layer :
# imports
from qgis.core import QgsProject
# getting a layer by its id
layer = QgsProject.instance().mapLayer("LAYER_ID")
# getting layer's name
name = layer.sourceName()
# counting features … looping over each layer's id
for id in ids:
# accessing a layer by its id
layer = QgsProject.instance().mapLayer(id)
# getting layer's name
name = layer.sourceName()
# counting features …
5
votes
Looping every features pair with PyQGIS
the layer
features = [feat for feat in layer.getFeatures()]
# looping over pairs of features
for pair in pairwise(features):
feat1, feat2 = pair[0], pair[1]
print(feat1["id"], feat2["id"])
For … in the layer
features = [feat for feat in layer.getFeatures()]
# looping over pairs of features
for i in range(len(features) - 1):
feat1, feat2 = features[i], features[i + 1]
print(feat1["id" …
12
votes
Rotating features with multiple geometries in one layer using PyQGIS
References:
Rotating features in memory layer using PyQGIS …
1
vote
Merging values from two fields into third field using PyQGIS
Another approach might be not as Pythonic as was suggested by @BERA, however, it is still applicable in terms of PyQGIS.
It utilizes the coalesce() function inside the QgsExpression() class.
Proceed w …
2
votes
Getting dictionary for each feature with their attribute values using PyQGIS
Another solution utilizes the attributeMap() method of the QgsFeature class.
Returns the feature's attributes as a map of the field name to value.
from qgis.utils import iface
from PyQt5.QtCore impo …
3
votes
Accepted
Duplicating rows according to field values in QGIS
Let's assume there is a polyline layer called 'lines' with three features in it, see the image below.
Step 1. … Duplicate geometries as many times as needed by means of the "Array of translated features" algorithm and the following expression in 'Number of features to create':
array_length(string_to_array("dupl" …
5
votes
Getting the number of features in shapefile without opening it using Python
from os.path import normpath
from shapefile import Reader
absolute_path_to_shp = normpath("C:/Users/taras/files/cluster_test.shp")
shp = Reader(absolute_path_to_shp)
print(shp.numRecords) # returns features …
1
vote
Getting number of features in the Attribute table using PyQGIS
Another option can be the allFeatureIds() method from the QgsFeatureSource class:
num_of_features = len(layer.allFeatureIds())
5
votes
Searching for values in different layers without nested for loops using PyQGIS
Referring to several features
If only targeting features' ids should be requested, then one case get them via the getFeatures() method together with the QgsFeatureRequest() and setFilterFids(). … )
Referring to all features
In case when all features should be requested use simply the getFeatures() method:
layer = iface.activeLayer()
features = list(layer.getFeatures()) …
1
vote
"Duplicating" the attribute table for many polygons in QGIS
Try the "Drop geometries" geoalgorithm in the iterative mode.
Creates a simple geometryless copy of the input layer attribute table.
It keeps the attribute table of the source layer.
If the file is s …
1
vote
Selecting only N records from layer using PyQGIS
Another option is to use the "Random selection" tool for selecting N random features.
import processing
from qgis.utils import iface
layer = iface.activeLayer()
processing.run("qgis:randomselection", …
5
votes
Counting number of selected features in QGIS
Approach 2:
In the left bottom corner, there will be a description of selected features. … Returns the number of selected features on a given layer. By default
works on the layer on which the expression is evaluated. …
5
votes
Replica of point layer data from attribute value in QGIS
Let's assume there is a point layer called 'Centroids' with three features in it, see the image below. The field "Number" will be used for producing copies of each feature.
Step 1. … Apply the "Array of translated features" geoalgortihm (available in QGIS 3.4). In the 'Number of features to create' field use the following expression:
"Number" - 1
Step 2. …