Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QGIS expression function overlay_nearest with filter condition: different result for first few features #53494

Open
1 of 2 tasks
Babelgit opened this issue Jun 18, 2023 · 4 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Expressions Related to the QGIS expression engine or specific expression functions

Comments

@Babelgit
Copy link

Babelgit commented Jun 18, 2023

What is the bug or the crash?

QGIS returns different results when using overlay_nearest() function with filter condition for the first few features.

Steps to reproduce the issue

See comment below for a more consistent dataset

A minimal reproducible example is linked in the GIS Stackexchange question. I have a point layer with fields id and name and use overlay_nearest with filter condition to find all features with the name = A:

array_to_string(
	overlay_nearest(
		@layer,
        id,
        limit:=11,
        filter:=name= 'A')
)

The result should return the same value for all 11 features, namely 1,2,4. However, in some cases, it returns just two features instead of 3, namely for the first three features.

grafik

Versions

<style type="text/css"> p, li { white-space: pre-wrap; } </style>
QGIS version 3.30.1-'s-Hertogenbosch QGIS code revision 9035a01
Qt version 5.15.3
Python version 3.9.5
GDAL/OGR version 3.6.3
PROJ version 9.2.0
EPSG Registry database version v10.082 (2023-02-06)
GEOS version 3.11.2-CAPI-1.17.2
SQLite version 3.41.1
PDAL version 2.5.2
PostgreSQL client version unknown
SpatiaLite version 5.0.1
QWT version 6.1.6
QScintilla2 version 2.13.1
OS version Windows 10 Version 2009
       
Active Python plugins
joinmultiplelines Version 0.4.1
LAStools 1.4
processing_saga_nextgen 0.0.7
qfieldsync v4.5.0
qgiscloud 3.8.5
QuickOSM 2.2.2
vector_tiles_reader 3.2.2
db_manager 0.1.20
grassprovider 2.12.99
processing 2.12.99
QGIS version 3.30.1-'s-Hertogenbosch QGIS code revision [9035a01](https://github.com/qgis/QGIS/commit/9035a01e) Qt version 5.15.3 Python version 3.9.5 GDAL/OGR version 3.6.3 PROJ version 9.2.0 EPSG Registry database version v10.082 (2023-02-06) GEOS version 3.11.2-CAPI-1.17.2 SQLite version 3.41.1 PDAL version 2.5.2 PostgreSQL client version unknown SpatiaLite version 5.0.1 QWT version 6.1.6 QScintilla2 version 2.13.1 OS version Windows 10 Version 2009

Active Python plugins
joinmultiplelines
Version 0.4.1
LAStools
1.4
processing_saga_nextgen
0.0.7
qfieldsync
v4.5.0
qgiscloud
3.8.5
QuickOSM
2.2.2
vector_tiles_reader
3.2.2
db_manager
0.1.20
grassprovider
2.12.99
processing
2.12.99

Supported QGIS version

  • I'm running a supported QGIS version according to the roadmap.

New profile

Additional context

https://gis.stackexchange.com/q/461886/88814 and https://gis.stackexchange.com/a/461863/88814 (see comments)

@Babelgit Babelgit added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Jun 18, 2023
@agiudiceandrea
Copy link
Contributor

agiudiceandrea commented Jun 18, 2023

@Babelgit, thanks for reporting. Please attach a simple layer to reproduce the issue directly to this issue report and please use a currently supported release according to the roadmap.

Anyway, it seems to me there is an inconsistency in your report: the minimal reproducible example linked in the GIS Stackexchange question you are referring in this report does contain the following attribute table:
image

and such attribute table is different from the attribute table visible in the provided screenshot.

In the minimal reproducible example linked in the GIS Stackexchange question layer, the only 2 features with "name"='A' have the "id" field with 0 an 1 value, so the result of the provided expression could only be a combination of 0 and 1.
In fact, the provided expression used with QGIS 3.30.3 to create a virtual field named "new_result" outputs the following values that seem correct to me:

image

Could you please better explains the issue, providing the correct data and expression?

@agiudiceandrea agiudiceandrea added Feedback Waiting on the submitter for answers Expressions Related to the QGIS expression engine or specific expression functions labels Jun 18, 2023
@Babelgit
Copy link
Author

Babelgit commented Jun 19, 2023

Sorry for the confusion. I created a new test Geopackage here:

test_points.zip

I run QGIS 3.30.3 with a new, clean user profile on Win 10. I have 11 points with field fid 1 to 11 and field name with characters A to F. I then use the following expression to create the rest of the fields (result_A... result_F).

In my understanding, the output for each feature should be the same per field, so result_A should always contain 1 and 2 - which is not the case for the first two features. Comparing the other results, the first (or the first two or three) features always have different results.

This is the epxression I used for result_A; for the other result fields, I only changed the letter 'A' in line 6 to the correpsonding character (B etc.):

array_to_string(
	overlay_nearest(
		@layer,
        	fid,
       		limit:=11,
        	filter:=name= 'A'
	)
)

grafik

@agiudiceandrea agiudiceandrea removed the Feedback Waiting on the submitter for answers label Jun 20, 2023
@agiudiceandrea
Copy link
Contributor

agiudiceandrea commented Jun 20, 2023

The issues occur when the the source layer is used as target layer. See also #47201.

@Babelgit, it seems to me that, as a workaround, you can duplicate the layer (or add the same layer two time with different names) and use the duplicated layer (or the same layer added a second time with different name) as target layer in order to obtain the expected results.

Side note: when a virtual field is create using the provided expression and the source layer is used as target layer, the following errors are logged in the Log Messages panel opening the Attribute table

2023-06-20T08:29:08     CRITICAL    Stack overflow, too many nested feature iterators.
             Iterated layers:
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             ...
2023-06-20T08:29:08     CRITICAL    Stack overflow, too many nested feature iterators.
             Iterated layers:
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             test_points___points_da69b25a_388c_46ee_a348_4d95a7bcf578
             ...
2023-06-20T08:29:08     CRITICAL    Stack overflow, too many nested feature iterators.
             Iterated layers:
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             ...
2023-06-20T08:29:08     CRITICAL    Stack overflow, too many nested feature iterators.
             Iterated layers:
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             test_points___points_77997b31_85a9_463f_bb6e_3f80238206fb
             ...
2023-06-20T08:29:08     CRITICAL    Stack overflow, too many nested feature iterators.
             Iterated layers:
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             ...
2023-06-20T08:29:08     CRITICAL    Stack overflow, too many nested feature iterators.
             Iterated layers:
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             test_points___points_633bb722_36db_4e89_9594_208582524251
             ...
2023-06-20T08:29:08     CRITICAL    Stack overflow, too many nested feature iterators.
             Iterated layers:
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             ...
2023-06-20T08:29:08     CRITICAL    Stack overflow, too many nested feature iterators.
             Iterated layers:
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             test_points___points_3545cf6f_2ebc_4e0d_81f4_62fc6e62d084
             ...
2023-06-20T08:29:08     CRITICAL    Stack overflow, too many nested feature iterators.
             Iterated layers:
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             ...
2023-06-20T08:29:08     CRITICAL    Stack overflow, too many nested feature iterators.
             Iterated layers:
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             test_points___points_e937a28b_f22b_4fa8_b651_156e13453190
             ...
2023-06-20T08:29:08     CRITICAL    Stack overflow, too many nested feature iterators.
             Iterated layers:
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             ...
2023-06-20T08:29:08     CRITICAL    Stack overflow, too many nested feature iterators.
             Iterated layers:
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             test_points___points_144bf0a4_4d82_49f1_be50_31fa528e5f18
             ...
2023-06-20T08:29:08     CRITICAL    Stack overflow, too many nested feature iterators.
             Iterated layers:
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             ...
2023-06-20T08:29:08     CRITICAL    Stack overflow, too many nested feature iterators.
             Iterated layers:
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             test_points___points_2e6aceb4_da00_4406_9cab_68ed3fffdaff
             ...
2023-06-20T08:29:08     CRITICAL    Stack overflow, too many nested feature iterators.
             Iterated layers:
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             ...
2023-06-20T08:29:08     CRITICAL    Stack overflow, too many nested feature iterators.
             Iterated layers:
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             test_points___points_d8b9b8e8_5c12_49fa_8ec7_4b68306b6a70
             ...
2023-06-20T08:29:08     CRITICAL    Stack overflow, too many nested feature iterators.
             Iterated layers:
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             ...
2023-06-20T08:29:08     CRITICAL    Stack overflow, too many nested feature iterators.
             Iterated layers:
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             points_9235aa7f_5cff_4c91_addc_3d0b4722a865
             test_points___points_c16c0f59_0100_4cc9_b852_74732edc0fe4

@alexbruy
Copy link
Contributor

Duplicates #47201?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! Expressions Related to the QGIS expression engine or specific expression functions
Projects
None yet
Development

No branches or pull requests

3 participants