QGIS Expressions – Numbering Points per Polygon Group with QGIS

expressionoverlaypointpolygonqgis

In QGIS, I have a point and a polygon layer. I want to number the points ascending from left to right (from smallest to highest x-coordinate value – West to East). However, counting should be made separately for each group of polygons with a common attribute value.

The screenshot shows the setting: all points inside polygons with value = 1 are considered together and should be counted from 1 to N, starting with the leftmost and proceeding to the right. Points inside polygons with value = 2 should also start from 1 to N, left to right, points in polygons = 3 as well and so on.

How to achieve that using QGIS expressions?

enter image description here

Best Answer

It is not a solution using the expression, it may seem a bit lamer.

Let's assume there are two layers: a point 'random_points_test' and a polygon 'poly_test' respectively, see image below.

input

Step 1. Use the "Join attributes by location" to get "id"s from polygons

step_1

Step 2. Proceed with the "Add autoincremental field" geoalgorithm for the result from the Step 1 with the following settings:

step_2_1

"id"s from polygons was used as 'Group values by [optional]'

and get the output

result

Related Question