2

I have a bunch of grids (100x100m) and I need to remove some of them considering the linear shape that forms some sets forms.

enter image description here

I've blue circled the set of grids I need to remove.

What I thought since now is to count the number of adjacent vertex of each one of the grids. Considering that a square has 4 vertex, if a grid only share two sides (having the id of 2 different grids 4 times one for each vertex shared) that means only have 2 adjancents grids what forms the linear shape. I thought as well dissolving the grid by his adjacents to set the sets of geometries (1, 2, 3 in image) to remove the whole grids with a dissolved geometry. Also if I do a dissolve, I could aggregate the total number of vertex and get a score considering how many vertex the grid shares.

Any theorical ideas or any script/tool you know that do something similar?

2
  • @BERA exactly, a hole country.
    – J.Patordi
    Commented Jan 19, 2023 at 16:00
  • 1
    1) For this kind of question, it would be good to share sample data for testing - otherwise one first has to create an own project that takes some time, before even trying a solution. 2) You should provide a clear definition (condition) when a cell should be deleted. This is unclear to me. You marked some cells with 3 neighbouring cells to be deleted, where in other cases cells with two neighbours are not marked for deletion.
    – Babel
    Commented Jan 19, 2023 at 20:38

2 Answers 2

7
  1. Dissolve (with keep disjoint feature separate)
  2. Buffer with a negative distance. My grid size is 2000*2000 m and i buffer with -1400
  3. Extracy by location the input grid cells intersecting the buffer

enter image description here

2
  • 1
    Nice one! Now i have the problem that I lose the cases with isolated grids but I'll thought how to save them. Thanks!
    – J.Patordi
    Commented Jan 19, 2023 at 16:40
  • Nice! You can possibly dissolve and calculate compactness/roundess and extract polygons without arms. You will probably have to use a combination of different techniques to solve all cases
    – Bera
    Commented Jan 19, 2023 at 17:10
3

Dissolve all cells to get one large polygon, buffer with a negative value, corresponding to the size of each cell, thus eliminating those parts just one cell thick, then again buffer with the same value as before, but positive.

You can do that with this expression in one step:

case 
when $id=maximum($id) 
then 
    collect_geometries(
        buffer (
            buffer (
                buffer (collect ($geometry),0), -- dissolve all cells to one large polygon
                -100, 
                join:='miter'
            ),
            100, 
            join:='miter'
        )
    )
end

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.