3

I want to perform a selection by locatin in QGIS using "intersection." However, I want to add a distance parameter so that it disregards polygons that are exactly adjacent and retrieves only those that are at a certain distance.

To illustrate my example: I have a layer of communes of France (red shapefile). I want to select only the communes (green layer) that are within the shape of the Languedoc-Roussillon region (black outline).

If I perform a selection by location using intersection in QGIS, it will select all communes within (green layer), but also those that touch the boundary (yellow communes).

Selection by location in QGIS

In ArcGIS, we can specify a distance parameter in the selection. In the case of my example above, I set it to "-10" to exclude the communes that touch the boundary. (Sorry, the menu is in French)

Menu ArcGIS

In QGIS, there is no way to add a parameter in the selection menu...

2
  • Maybe you can add a diagram, or something. I'm not clear on what you are asking by "polygons that intersect within a radius of less than 10 meters", particularly given your comment below. Commented May 15, 2023 at 11:54
  • @TomBrennan, I edited the question, hope it's clearer now...
    – caslumali
    Commented May 16, 2023 at 11:54

4 Answers 4

2

Try using the "Extract by expression" algorithm, the expression could be this one:

with_variable(
    name:='buffered',
    value:=buffer(
        $geometry,
        -10 -- set here the distance to filter features, this distance is in map units
    ),
    expression:=aggregate(
        layer:='Polygon layer name/id', -- put inside quotes the layer name/id that is going to filter the polygons
        aggregate:='count',
        expression:=1,
        filter:=intersects(
             $geometry,
             @buffered 
        )
    )
)
4
  • Many thanks, worked smoothly and did exactly what I needed!
    – caslumali
    Commented May 15, 2023 at 13:32
  • 2
    Hi @caslumali, good to hear it worked. If you find my answer useful and it solved your problem, please mark it as accepted, this help people with the same question to find this answer easier. 😉
    – Mayo
    Commented May 15, 2023 at 13:59
  • 2
    @caslumali, as mentioned by Erik in a comment in the oder answer, is not clear that "intersections in a radius of less than 10 meters" means intersections 10 meters inside the polygon or intersections in a -10 meters buffer. Actually, part of my answer was based on your comment in that oder answer. I suggest you to edit you question clarifying that point.
    – Mayo
    Commented May 15, 2023 at 20:13
  • 1
    Hi @Mayo, I edited the question, hope it's clearer now. Many thanks...
    – caslumali
    Commented May 16, 2023 at 11:55
0

You can use the tool selectwithindistance

Just search for it in the Toolbox. You can open the Toolbox with strg + alt + t

3
  • This answer doesn't help because I need to put a negative distance and QGIS doesn't allow it. I want it to use a distance, like -10 meters to not pick up the polygons that touch the edge...
    – caslumali
    Commented May 15, 2023 at 10:14
  • 3
    That is not clear by the way you ask your question @caslumali - "less than 10 m" usually means "anything within a distance of 10 m from the edge of my feature".
    – Erik
    Commented May 15, 2023 at 18:52
  • Hey @Erik, I just edited the question, hope its clearer now. Many thank.
    – caslumali
    Commented May 16, 2023 at 11:57
0

For solving your particular problem, rather than negative buffering, an alternative approach is to consider the commune polygons as points.

By using pole_of_inaccessibility, you can treat the commune polygons to points with confidence that the point is inside the commune polygon (and hence inside your region polygon).

You need to supply the LayerId, Attribute, and Value for the Languedoc region, and Tolerance based on your units (1m or 0.000001 degree should be fine). Expression is of the form:

contains(
   geometry(
      get_feature(<LayerId>,<Attribute>,<Value)
   ),
   pole_of_inaccessibility($geometry,<Tolerance>)
)

Here's a specific example using districts in India. The points are just for visualisation.

contains(
   geometry(
      get_feature('IND_adm2_f8a55c74_b2be_45a5_9a48_e701942c7c5d','NAME_2','Anantapur')
   ),
   pole_of_inaccessibility($geometry,0.000001)
)

enter image description here

0

Use Select by expression with this expression and replace region_layer with your layer name:

within (
    $geometry, 
    overlay_nearest ('region_layer', buffer($geometry,0.1))[0]
)

The expression looks for each commune if it is completely within the nearest feature from the region_layer. For exact matches add a very small buffer around the region. This does not affect neighboring communes being selected, as we only select if a commune is completely within the region (not not just overlaps in the margins).

Screenshot: only those of the red polygons are selected (highlighted in yellow) that are completely within the blue polygon: enter image description here

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.