Skip to main content
31 votes

Displaying only selected features on map in QGIS

This is now possible using just selections and a rule-based symbology. This requires the Expression Plus plugin (for QGIS 2.x. 3.0 has the functionality built in). Create a rule based symbology with ...
HeikkiVesanto's user avatar
30 votes

Displaying properties of GeoJSON in popup on Leaflet?

The line where you create and bind your popup should have been included in the onEachFeature option of your L.geoJSON factory. var layerGroup = L.geoJSON(data, { onEachFeature: function (feature, ...
ghybs's user avatar
  • 7,223
27 votes

Reading feature class in file geodatabase using R?

As already posted in this answer, this now also works very nicely with sf: require(sf) fc <- sf::st_read("C:/path/to/your/filegeodatabase.gdb", layer = "some_featureclass") But ...
Ratnanil's user avatar
  • 1,003
19 votes

Applying categorized symbol to each feature using PyQGIS

For those who'd like to try the code above for the PyQGIS3 version, here is my adaptation (it works for the 'active layer' if run from the console ...). # provide file name index and field's unique ...
A. Jean's user avatar
  • 321
19 votes
Accepted

Getting the bounding box for each feature in the source layer in QGIS

In the Processing Toolbox (Processing Tab > Toolbox or Ctrl+Alt+T) you will find a tool called Bounding boxes. This will achieve what you want. If your layer contains some multipart features you ...
Cushen's user avatar
  • 3,167
18 votes
Accepted

Updating text column of selected features in QGIS

make sure the layer is in edit mode (otherwise changes will not happen) Select features to change (however you like) then open attribute table select the attribute to change type in what you want it ...
Ian Turton's user avatar
  • 82.2k
18 votes
Accepted

Copying & pasting multiple values from one feature to other features in the same layer in QGIS

There is the AttributePainter plugin (https://plugins.qgis.org/plugins/attributePainter/) for this. Usage: Click on Pick source feature and select a sample feature on the map. On the table, a ...
Kadir Şahbaz's user avatar
17 votes
Accepted

Deleting all features of Vector layer using PyQGIS

You could use the following code which is heavily based on the answer from this post: How to delete selected features in QGIS using Python layer = iface.activeLayer() with edit(layer): for ...
Joseph's user avatar
  • 76k
16 votes
Accepted

Counting number of selected features in QGIS

Look at the header of the attribute table, it tells you the total number of objects in tables, as well as the filtered and selected ones.
Pierre Vivet's user avatar
16 votes
Accepted

'Could not load source layer for INPUT: layer not found' error when running QGIS algorithm on selected features using PyQGIS

You need add the layer to project. For add without showing it use: QgsProject.instance().addMapLayer(layer1, False) Example using only one layer: layer1 = QgsVectorLayer(r"C:\test\grassland....
Fran Raga's user avatar
  • 7,878
16 votes
Accepted

Creating Virtual layer in QGIS that shows only features in extent

The trick is to create a function that access QGIS graphical interface, and that is piped to the query of the virtual layer. Open a function editor (from anywhere, including from field calculator) ...
JGH's user avatar
  • 42.3k
16 votes
Accepted

Getting dictionary for each feature with their attribute values using PyQGIS

The QgsJsonUtils class has exportAttributes method for getting attributes as a dict. Solution 1: Making a dictionary including feature "id" as key, attributes map as value: {feature1.id: {...
Kadir Şahbaz's user avatar
14 votes
Accepted

Tying visibility of features to zoom level by attribute in QGIS

You can change the style to be rule-based (it will preserve the classes if a categorized style was previously set), and there you can control the display scale of each class/rule.
JGH's user avatar
  • 42.3k
13 votes

Sorting features by attribute using PyQGIS

This code will sort getFeatures() results by field in descending order. Tested with QGIS 3.6.1: request = qgis.core.QgsFeatureRequest() # set order by field clause = qgis.core.QgsFeatureRequest....
Comrade Che's user avatar
  • 7,271
13 votes
Accepted

Is there a maximum number of features that QGIS can save into a shapefile?

Officially, .shp and .dbf files are limited to 2GB. Using GDAL Shapefile driver this can be exceeded, but as stated on this site, this is not recommended due to compatibility issues (See point #Size ...
MrXsquared's user avatar
  • 34.9k
13 votes

Deleting features in PyQGIS?

Decide either to work with the data provider or the layer, not both Working directly on the layer has the advantage, that all internals of QGIS are notified about changes/deletions, whereas changes ...
Matthias Kuhn's user avatar
13 votes

Determining number of vertices of selected object in QGIS 3

You can use the following script in QGIS Python Editor. Select a layer, run the script and select a feature. def n_vertices(selected, _, __): n = len(selected) if n == 1: g = ...
Kadir Şahbaz's user avatar
13 votes
Accepted

Selecting multiple features by ID-attribute from list using PyQGIS

Use this way (without for loop): id_list = [1, 2, 5] layer.selectByExpression("id in {}".format(tuple(id_list)))
Kadir Şahbaz's user avatar
12 votes
Accepted

Merging spatially separated polygons into one feature in QGIS

Check the corresponding geoalgorithm in the Processing Toolbox (Ctrl+Shift+T). For QGIS 3 : "Promote to multipart" For QGIS 2 : "Singleparts to multipart"
eclipsed_by_the_moon's user avatar
12 votes
Accepted

Feature Count in Legend (QGIS 2.18.2)

You may try a right click on your layer and then chose to Show Feature Count (green on figure):
swiss_knight's user avatar
  • 10.5k
12 votes
Accepted

Getting ordered list of IDs of selected features using PyQGIS

Use this script: selection = [] def selection_changed(selected, deselected, clearAndSelect): global selection # If the user deselects feature(s), remove ID's from list if deselected: ...
Kadir Şahbaz's user avatar
12 votes
Accepted

Determining number of vertices of selected object in QGIS 3

num_points($geometry) returns the number of vertices of the current feature.
Erik's user avatar
  • 16.5k
12 votes

Rotating features with multiple geometries in one layer using PyQGIS

There are several things that I would improve: do not forget to start/startEditing, end/endEditCommand(), and commit/commitChanges() editings use the setGeometry() method properly, otherwise the ...
Taras's user avatar
  • 33.3k
11 votes

Quickly browsing of features for the active vector layer?

This functionality is now integrated in QGIS 3.10 (not sure about previous versions): Open the attribute table of the vector layer in question. Click on the Switch to form view icon on the bottom ...
onietosi's user avatar
  • 559
11 votes

Displaying properties of GeoJSON in popup on Leaflet?

Build a simple popup content for any properties in a simple way, in one line: var layer = L.geoJSON(data, { onEachFeature: function (f, l) { l.bindPopup('<pre>'+JSON.stringify(f.properties,...
stefcud's user avatar
  • 396
11 votes

Show/hide features on layer in OpenLayers?

One approach is to change the features' style. In order to hide a feature, you can set its style to an empty style object: myFeatureIWantToHide.setStyle(new ol.style.Style({})); To show this feature ...
Mesa's user avatar
  • 1,512
11 votes
Accepted

Replacing existing geometry in QGIS 3

There is the Geometry Paster Plugin Turns out we had a task for this too, so here we go: https://www.youtube.com/watch?v=NMs5hDf5ndE (EN) https://www.youtube.com/watch?v=Mw9y-_HBmko (RU)
Maxim Dubinin's user avatar
11 votes
Accepted

Running QGIS algorithm with selected features from layer using PyQGIS

For only selected feature use the QgsProcessingFeatureSourceDefinition class. Code below with the input of selected features only: import processing input_vlayer = 'Some path' intersect_vlayer = '...
Fran Raga's user avatar
  • 7,878
11 votes

Getting dictionary for each feature with their attribute values using PyQGIS

The snippet below should help you. It just prints a dictionary for each feature to the console, but you could do something else with the feature attribute dictionaries if you wanted. from qgis.utils ...
Ben W's user avatar
  • 21.9k
11 votes
Accepted

Sorting records by attribute in shapefile using PyShp

The script you need: features = shapefile.Reader("c:/data/cities.shp").shapeRecords() features.sort(key=lambda feat: feat.record["NAME"]) # or ["POPULATION"] ...
Kadir Şahbaz's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible