Skip to main content
47 votes

Change style properties of several layers simultaneously?

This works for QGIS 3.4 => Create a group of all the layers you want to have the same style Edit the style of one of the layers in the group to your liking Right-click the correctly styled layer; '...
GISinHelsinki's user avatar
32 votes

Getting list of layer names using PyQGIS

Since version 3, QgsMapLayerRegistry funcionalities have been moved to QgsProject: https://qgis.org/api/api_break.html Update for QGIS3.x: from qgis.core import QgsProject names = [layer.name() for ...
RafDouglas C. Tommasi's user avatar
31 votes
Accepted

What are the min and max values of Map.addLayer on Google Earth Engine?

Let's start from the beginning. How satellite remote sensing work Satellites carry out sensors that can measure radiance at different wavelengths (it depends on the sensor) For example, Landsat ...
Rodrigo E. Principe's user avatar
30 votes
Accepted

Getting layer extent using PyQGIS

The answer is almost completely contained in a post I recently wrote. The extent is returned as a QgsRectangle() object with the following code: layer = iface.activeLayer() # load the layer as you ...
mgri's user avatar
  • 16.3k
28 votes
Accepted

Getting field names of layer using PyQGIS

To get field names with fields() method or other field properties (length, type, comment, ...) you can use: field_names = [field.name() for field in layer.fields()] # ['id', 'attr1', 'attr2', 'attr3'] ...
Kadir Şahbaz's user avatar
26 votes

Iterating over map layers using PyQGIS

For QGIS 3, QgsMapLayerRegistry's functionality has been moved to QgsProject. So, for iterating over map layers, you should use that structure: layers = QgsProject.instance().mapLayers() ....
Kadir Şahbaz's user avatar
24 votes
Accepted

Setting layer transparency in QGIS 3

You have to click on the layer rendering arrow (see the bottom of your second image) to access the slider and other option. in QGIS 2 it was on by default, in QGIS 3 it's off by default...
J.R's user avatar
  • 16.6k
24 votes

Setting layer transparency in QGIS 3

As an alternative option, you can unfold the Legend tab and select Opacity slider widget. It will add an opacity slider in the Layers panel. If you don't have an opacity widget yet you can enable it ...
Kazuhito's user avatar
  • 31k
24 votes
Accepted

Showing the number of currently selected layers in QGIS

You can use this script. It adds a toolbar as seen in the image and shows how many layers are selected. label = QLabel("Selected Layers Count:") count = QLabel() tree_view = iface....
Kadir Şahbaz's user avatar
22 votes

Duplicating layer in memory using PyQGIS

In QGIS 3 you can make a copy of a layer without saving any reference to the parent layer in this way: layer.selectAll() clone_layer = processing.run("native:saveselectedfeatures", {'INPUT': ...
Leo Cardona's user avatar
  • 1,363
22 votes
Accepted

Making layer or group private/hidden/invisible in Layers Panel of QGIS

Just to clarify, private/hidden layers/groups will not appear in the Layers Panel, but they can still be seen in the canvas or used in joins/relations with other layers. Native approach (QGIS API) You ...
Germán Carrillo's user avatar
20 votes
Accepted

Duplicating layer in memory using PyQGIS

The following code works for me from both the Python Console and plugin. It takes the features from the source input layer and copies the attributes to a memory layer (in this case, a polygon layer ...
Joseph's user avatar
  • 76k
19 votes

Understanding Coordinate Reference System of QGIS Project and Layer

Short answer: there is project CRS and layer CRS: You can more or less freely choose any project CRS, QGIS handles the rest automatically. You can't "set" another CRS for your layer (your ...
Babel's user avatar
  • 73.2k
17 votes

Setting layer visibility with PyQGIS

For QGIS 3, you have to use: QgsProject.instance().layerTreeRoot().findLayer(layer_id).setItemVisibilityChecked(False) or to be safe node = QgsProject.instance().layerTreeRoot().findLayer(layer_id) ...
Denis Rouzaud's user avatar
17 votes
Accepted

Symbols above labels in map QGIS

I don't think there is a way to do this in the map canvas itself. The labels will always be on top at least in QGIS 2.x. But for the print composer, you can work with two maps. They should be in the ...
HeikkiVesanto's user avatar
17 votes

Showing the number of currently selected layers in QGIS

To extend the great solution by @Kadir Şahbaz, you could do something like this to get a count per group: p = QgsProject.instance() root = p.layerTreeRoot() view = iface.layerTreeView() ## TOOLBAR tb ...
Matt's user avatar
  • 17.6k
16 votes
Accepted

Adding Properties to a feature in Google Earth Engine

Yes, you can use the feature.set()option which Feature Overview covers with these examples: // Make a feature and set some properties. var feature = ee.Feature(ee.Geometry.Point([-122.22599, 37.17605]...
whyzar's user avatar
  • 12.1k
16 votes
Accepted

Reprojecting layer using PyQGIS

You can use processing algorithm native:reprojectlayer. Example: lyr = iface.activeLayer() parameter = { 'INPUT': lyr, 'TARGET_CRS': 'EPSG:4326', 'OUTPUT': 'memory:Reprojected' } result = ...
Fran Raga's user avatar
  • 7,878
16 votes
Accepted

Change vector layer symbology PyQGIS 3?

The easiest for me would be to check the properties of the symbology layer which contains symbol properties affecting the whole layer: dir(symbol) >>>['DynamicRotation', 'Fill', 'Hybrid', '...
Joseph's user avatar
  • 76k
16 votes

Turning on/off ALL selected layers in QGIS

In the Layer pannel, there is an icon in form of an eye : Manage Map Themes (documentation) : By clicking on it, you can see the option for display / mask the selected layers. You can also go to the ...
J. Monticolo's user avatar
  • 15.8k
15 votes

Merging multiple vector layers to one layer using QGIS

In the meantime, a tool called "Merge vector layers" has been added to QGIS under Vector > Data Management Tools > Merge Vector Layers or under Vector general in the Processing Toolbox ...
stopopol's user avatar
  • 293
15 votes

Getting path of project or layer file in PyQGIS

In QGIS 3.2 and above: Project path: QgsProject.instance().fileName() # OR QgsProject.instance().absoluteFilePath() # C:/test/sample_project.qgz Project folder path: QgsProject.instance().homePath()...
Kadir Şahbaz's user avatar
15 votes

Getting field names of layer using PyQGIS

List field names with dataProvider() method from qgis.utils import iface # get active layer if not already set layer = iface.activeLayer() prov = layer.dataProvider() field_names = [field.name() ...
grego's user avatar
  • 1,063
14 votes

Georeferencing vector layer with control points using QGIS?

Several of the answers provided here are no longer options for QGIS 3, and/or only allow for linear transformations of the vector file being georeferenced. This may answer the OP's question, but ...
user92448's user avatar
  • 393
14 votes
Accepted

Is it possible to set different scale dependent visibility for one layer classifications?

You need to use Rule based style to set the scale for primary, secondary and tertiary network, as you can see below (but with different data): You can double-click each styled label to get more ...
ahmadhanb's user avatar
  • 41.1k
14 votes
Accepted

Editing shp layers style simultaneously in QGIS?

With a little help from Python, we could set the border width for all layers in your "State" group to a specific value (e.g. 0.16 as shown in your image). Try testing the following in the Python ...
Joseph's user avatar
  • 76k
14 votes
Accepted

Create Layer from Selected Features tool: How is the list of features stored?

Create Layer From Selected Features DOES NOT create a DYNAMIC layer. The resulting layer is not dynamic at all. It is based on an FIDset. If you change the source data, the FIDs will change and your ...
jbalk's user avatar
  • 7,583
14 votes

Adding layer to GeoPackage using PyQGIS

You need to use QgsVectorFileWriter.writeAsVectorFormat. If you store one layer per GPKG file you just need: QGIS 3: # imports from qgis.utils import iface from qgis.core import QgsProject, ...
user19291's user avatar
  • 405
14 votes
Accepted

Selecting layers in group using PyQGIS

You can use the following lines: newtable = QgsVectorLayer("None", "Results", "memory") provider = newtable.dataProvider() provider.addAttributes([QgsField('Layername', ...
Kadir Şahbaz's user avatar
13 votes

Cutting/Clipping/Splitting polygon with another polygon from the same layer in QGIS

You can substract (clip) a polygon from another of the same layer by using the plugin Clipper. You have to choose the polygon you want to clip and then you do Vector->Clipper->Clip and the plugin ...
geoSAM's user avatar
  • 875

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