# Tag Info

Accepted

### Is it ok to group by geometry in PostGIS?

There's almost certainly nothing wrong with grouping by geometry in this case, since you're already grouping by a unique ID (nbhd_id). And, as you point out, it saves you a join and makes the query ...
• 13.1k

### Clustering points/polygons based on proximity (within specifed distance) using QGIS?

you can try this (did this in QGIS 2.16) fixed distance buffer each point by 250m (this is half the required distance between points) then dissolve all on the result of that then use multipart to ...
• 20.5k
Accepted

### Counting fire occurences per county per year using QGIS

You can use the "Statistics by categories" from the Vector analysis toolbox in QGIS. Select your layer, leave 'Field to calculate statistics on' empty, select "COUNTY_NM" and "...
• 7,583
Accepted

### Adding unique ID for groups of items using Field calculator in QGIS

You can use arrays for this purpose: array_find(array_distinct(array_agg("Name")), "Name") This returns for example this "id" column: So how does it work: First an ...
• 34.5k
Accepted

### Calculating Convex Hull based on attributes in QGIS

There is another Convex Hull function in the "Vector geometry" -" "Minimum bounding geometry" tool. That one allows you to specify a field by with the geometries should be grouped.
• 10.9k
Accepted

### Summarizing fields with same ID in QGIS Field Calculator

As an alternative you may try this expression: if("WEA" IS NOT NULL, array_sum( array_agg( "Baulast", group_by:="ogc_fid", ...
• 33.1k

### Categorising data points along transect using QGIS

I just wanted to add another solution in case the intervals are not intended to be equal, the interval 'names' are not necessarily sequential the intervals are represented by line geometries, and you ...
• 12.6k

### Copying all visible layers to new group

Use the following script. root = QgsProject.instance().layerTreeRoot() group = root.addGroup("group") for layer in root.children(): if layer.isVisible() and layer != group: _layer ...
• 77.2k

### Counting fire occurences per county per year using QGIS

There is a possibility using a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer... Let's assume there is a layer called 'points' with its attribute table, see image ...
• 33.1k

### Calculating two columns at once in QGIS

QGIS has an algorithm for that : Statistics by categories (official documentation) You have to select your layer, your category field (here "Cover") and the field to calculate statistics (...
• 15.7k
Accepted

### How to group by attributes and give unique categories in QGIS?

There is an easy way that needs two steps from the db-manager and two tables that can be deleted in the end(there is a way with virtual tables, but i don´t get them to work properly from the db-...
• 6,245
Accepted

### Load Named Style within a group on QGIS

Change this line child.loadNamedStyle('*.qml') by: child.layer().loadNamedStyle('/some/real/path/to/a/file.qml') Your child object is of type QgsLayerTreeLayer, but you need to access layer() to ...
• 36.6k

### Summing area of by several attributes in QGIS

Use a combination of the two fields like concat: "id" || "function" for the group_by() part of the expression: sum("area", "id" || "function")
• 72k
Accepted

### Area of each polygon that intersects another layer and total area of intersections in QGIS

You can do this using QGIS expressions and e.g. create a new field with the Field Calculator. If you have a layer 'polygon' (orange in the screenshot) and another layer 'overlay' (blue outlined), on ...
• 72k

### Area of each polygon that intersects another layer and total area of intersections in QGIS

Other solution is to use your SQL statement for the "Virtual Layer" and change it to: SELECT fid, group_concat(b_full) as formated, sum(area) from ( SELECT a.fid, st_area(b.geometry) ...
• 11.1k
Accepted

### Unsplitting/merging lines that have coincident endpoints using PostGIS

The graph-theoretical answer for simplifying edge topologies and decreasing the size of a graph would be contraction - implemented as stable function as of pgRouting 3.0. To perform a linear graph ...
• 30.3k

### Selected item in layertree group or layer?

You can check with the QgsLayerTree.isGroup() / .isLayer() static methods, the .nodeType() method, or by using isinstance(). p = QgsProject.instance() root = p.layerTreeRoot() for c in root.children()...
• 17.4k

### Filling attributes in one field based on second field with same values in QGIS

If you want to update SID_1 with the value of SID_2 if SID_1 is NULL choose Update existing field in the Field Calculator execute a simple conditional: IF( "SID_1" IS NULL, "SID_2"...
• 30.3k
Accepted

### Categorising data points along transect using QGIS

Use this expression: it will automatically adapt if you change the interval (2nd last line). See below for explanation: array_foreach( generate_series(65,90), char(@element) )[floor ( ...
• 72k
Accepted

### Selecting N points within each geometry using SQL

You want a correlated sub-query for this - a query that essentially does a for-each loop over the running table - and I would suggest a LATERAL join for flexibility. Here we find (up to) 50 pseudo-...
• 30.3k

### Creating population dot density map at the block group level in QGIS

Use Vector -> Research Tools -> Random Points Inside Polygons. Select the variable, which contains the number of people in each Block (=polygon) under expression. leave sampling strategy ...
• 7,107

### Clustering geographical data based on point location and associated point values

The rioja package provides functionality for constrained hierarchical clustering. For what your are thinking of as "spatially constrained" your would specify your cuts based on distance whereas for "...
• 31.9k
Accepted

### Centroid of multiple polygons based on value in attribute table

Try the natively supported SpatiaLite SQL, either via Virtual Layer, or the DB Manager; run SELECT "AreaChar", ST_Centroid(ST_Collect(geometry)) AS geometry FROM <your_layer> GROUP BY ...
• 30.3k

### Adding unique ID for groups of items using Field calculator in QGIS

You can use PyQGIS: lyr = QgsProject.instance().mapLayersByName('lmv ok_my_riks_sample')[0] #Change name to match your data category_field = 'kategori' #Same field_to_calculate = 'cat' #Same. This ...
• 74.2k

### Adding unique ID for groups of items using Field calculator in QGIS

This is a typical CASE...WHEN..THEN solution. In the field calculator, you can use the following statement to update the ID field: Case When "Name" = 'loam' then 1 When "Name&...
• 41k
Accepted

### Adding unique ID for consecutive groups using Field calculator in QGIS

create an ID field following the GpsTime field, then create the group1 field and populate it with the following expression (can be improved): with_variable('cucu', aggregate( layer:=@layer_name,...
• 4,500

### Grouping and measuring total length of road based on specific attribute in QGIS

To get the km of cycleway for each type of highway, use this expression: sum("lunghezza", group_by:="highway") To get the percentage of each highway type, use this expression: sum(...
• 72k

### Grouping and measuring total length of road based on specific attribute in QGIS

You can create a virtual layer with the query: select row_number() over() as id, highway, sum(lunghezza) as lunghezza_sum, sum(lunghezza)/sum(sum(lunghezza)) over () * 100 as ...
• 74.2k

### Filling attributes in one field based on second field with same values in QGIS

You can use a short PyQGIS script. First create your new field e.g. "ID_2" and fill it with the values from "ID_1" (the expression to do that is simply "ID_1"). Next open ...
• 21.8k

### Get a group from layerTreeRoot using its unique id using PyQGIS

I've written a script to access easily to layer(s) and group(s) in QGIS Layer Panel. Here's the group part: def G(group_path: str = None): """ Return the group given in path ...
• 77.2k

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