4

From a DEM raster layer I created a set of random points and informed each point with the value of 'ELEVATION'.

I also used the following expression to connect the 10 points closest to the @map_extent_center with the lowest ELEVATION value. This is a variant of the expression developed by the user Babel in the question 'Drawing an arc with length proportional to a distance in QGIS':

case 
when 
    $geometry = 
    closest_point(
        collect($geometry),
        @map_extent_center
    )
then
    with_variable(
    'min',
    array_sort (array_agg (ELEVATION),0)[10],

    collect_geometries(
        array_slice( 
            array_agg( 
                difference(
                    make_line($geometry, @map_extent_center),
                    make_circle(@map_extent_center,400)
                ), 
                filter:=ELEVATION<@min,
                order_by:=length(make_line($geometry, @map_extent_center))
            ),
            0,
            10
        )
    ))
end

I also use the difference argument to represent a 400 meter circle that is intended to show the centroid extent of the selected points:

enter image description here

I would like, if possible, to reuse this expression to draw the polygon formed by the points. I show what I want to say with a screenshot::

enter image description here

3
  • 1
    What does "the 10 points closest to the @map_extent_center with the lowest ELEVATION value" exactly mean? This is unclear, you should be more clear about how the condition is defined. The "10 closest" points are lower than... what? What if the closest 10 points are not lower? This makes no sense as it is written now.
    – Babel
    Commented Jan 7 at 13:42
  • 1
    Does your question mean (so much I tried to understand from the expression): "Connect the map_extent_center to the 10 (11?) closest point, but consider only points that have an elevation smaller than the top 10 highest elevation values in the dataset. Create a polygon (concave hull?) around these points."
    – Babel
    Commented Jan 7 at 13:50
  • I answer these questions in the comments to your solution Commented Jan 8 at 7:22

1 Answer 1

5

You can simply create the concave hull around the points you have with function concave_hull():

enter image description here

with_variable(
    'min',
    array_sort (array_agg (ELEVATION),0)[10],
    concave_hull(
       collect_geometries(
            array_slice( 
                array_agg( 
                    $geometry, 
                    filter:=ELEVATION<@min,
                    order_by:=length(make_line($geometry, @map_extent_center))
                ),
                0,
                10
            )
        ),
        0.3
    )
)

However, I don't understand your whole task and the expression you use. It seems illogic to me why e.g. you use a case...when condition that is unnecessary - you could leave it away and reduce the expression to its core (the part included in the then part) to get the same points. I also don't see what this expression should be good for, but that's another point.

And, by the way: you want the 10 closest point to the @map_extent_center. However, your expression returns 11 points as you use the array_slice() function with array-index 0 to 10. Array indices start with 0 for the first element, so you have indices 0 to 10 / element 1 to 11...

4
  • 1
    I try to clarify some of your doubts. Regarding the use of the case...when condition, I agree with you and correct and reduce my initial expression. Regarding the use of this expression, I am helping in a dowsing project to find leaks and natural water points and we work in the field. In field work conditions, we need a fast and dynamic vector visualization of slope orientations and low altitude areas. I have designed this solution that we are testing. It may not be quite right. We will see how successful it is. I will take it into account your clarification about arrays. Commented Jan 8 at 7:17
  • 3
    In real time field work, there is not much time for complex GIS analysis and the working conditions are sometimes difficult. With this vector visualization, technicians and operators do not have to think too much and can make decisions quickly. It should be noted that the dowser has not a scientific evidence, but it is the most reliable method for finding water leaks. The concave-hull object is perfect. We will see how the tests work and what feedback I get from the workers Commented Jan 8 at 7:28
  • 2
    Thanks a lot for clarifications!
    – Babel
    Commented Jan 8 at 7:45
  • 1
    Same to you. Thank you very much for your help in providing solutions that work perfectly Commented Jan 8 at 7:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.