-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
Spatial references in Expressions (refFunctions goes core) #145
Comments
+1 |
I wonder if this could be simplified by splitting into two functions:
Speaking of aggregate array, it would be nice to keep similar functionality here -- i.e. have you considered adding an optional "filter" argument to geometry_overlay?
This is a rather inefficient way to do this, and would certainly have performance issues on large tables. What about adding an optional "limit" argument instead?
Is there a typo here for the 3rd argument? Like aggregates, it should be a sub expression, not a string literal, right? In general, I am very much in favour of providing a stable, optimised solution to this as an alternative to refFunctions. I see that that plugin is very widely used, so there's clearly a demonstrated need for this. Yet the approaches used by refFunctions are very inefficient, and also quite dangerous (not thread safe), so this work would be extremely valuable! |
+1 also |
Thanks for the feedback @nyalldawson
I am 50/50 on that one. While it's technically / API wise a bit more concise because of the static return type, it decreases discoverability.
Interesting thought indeed. That would make it possible to filter results earlier and improve performance.
Sounds like a very good proposal.
Thanks, corrected. |
Will this include the geomnearest feature as well? |
Is this under consideration or in development? I use the plugin for this and stumbled upon this open issue. I don't know that the functionalities of the refFunctions can be used without the plugin, so that's why I'm asking. Also, there's a typo in |
Ping @olivierdalang |
@thymaro Yes it's under development, and will hopefully land in 3.16 |
QGIS Enhancement: Spatial references in Expressions
Date 2019/05/15
Author Matthias Kuhn (@m-kuhn) / Enrico Ferreguti (@enricofer)
Contact matthias@opengis.ch
maintainer @m-kuhn
Version QGIS 3.10
Summary
The aim of this proposal is to add a set of new spatial reference functions to the expressions engine.
This new feature will allow the re-use of feature attributes and geometry located on other layers but spatially related with the currently evaluated feature.
Expressions with spatially related functions are particularly useful for defining complex symbologies, layouts and labels without the need to create new data from scratch or to run specific algorithms.
At the moment spatial reference in expressions can be performed with refFunctions plugin, available in the QGIS plugins repository, that adds some new spatial reference functions in the expression builder and field calculator. This python solution has preformance and reliability limits. This functionality can also be considered base functionality of a QGIS system. It would therefore be preferable to have a stronger implementation in core.
Proposed Solution
Adding a new function with the following syntax:
with these arguments:
_LAYER_
: type "layer" (id, layer name, QgsVectorLayer), required: the layer on which to perform spatial reference_METHOD_
: type "String", required: spatial condition to verify_OUTPUT_
: type "String", an optional Expression:_OUTPUT_
argument is not provided or left empty the command returns a boolean value depending whether or not the provided spatial condition is satisfied._OUTPUT_
contains an expression to be performed in the target layer context for extracting related informations such as"target_layer_field_name"
,$geometry
,$area
orCOALESCE("field", 0)
A target value can be retrieved from the output list using an array function, for example array_first, array_cat, array_get, array_lenght or summarized with other aggregates functions ( sum, count, etc...).
At this point existing Array functions group lacks of many geometry and number aggregation functions so it would be useful to extend the aggregate functions group, which takes features from a layer source, using them for array too either by adding a new
aggregate_array(array, aggregate_method [, filter])
or by allowing the existing one to take an array as first parameter (instead of only layers). This is not subject of this QEP in particular, but will be treated in the same project.Next to the function
geometry_overlay
, to improve discoverability by autocompletion search more self explained aliases will be created:geometry_overlay_intersects(_LAYER_, _OUTPUT_)
geometry_overlay_touches(_LAYER_, _OUTPUT_)
geometry_overlay_within(_LAYER_, _OUTPUT_)
geometry_overlay_contains(_LAYER_, _OUTPUT_)
and so on...
Example(s)
returns true or false (this method covers the most used case, can act as spatial modifier in rule symbology
returns the sum of the values of field population of the features satisfying spatial condition
returns the count of the features satisfying spatial condition (in this case the field parameter is needed to return an array of results to be counted)
array_first(geometry_overlay_touches('layer_e5313dca_be5e_4d28_95f9_8c58b41ef4ad',$geometry))
returns the first geometry from the features satisfying the "touch" spatial condition
returns the first buffered geometry from the features satisfying the "intersects" spatial condition
other aggregation modes would be possible taking vantage of aggregate function, extending them to apply to arrays as well as for layer features.
Affected Files
core/expression/qgsexpressionfunction.cpp
Performance Implications
(required if known at design time)
Further Considerations/Improvements
(optional)
Backwards Compatibility
(required)
Issue Tracking ID(s)
(optional)
Votes
(required)
The text was updated successfully, but these errors were encountered: