7

I work with this polygon and try to find a way to create a new polygon from the empty gap (not distinguish it) in the middle of the polygon.

I succeed to do it with the "Difference" tool but used with another layer on the polygon and then using the difference tool.

I can also digitize the shape of the hole and create a new layer I seeking an automated way to do it and not doing in manually.

I read:

Is it possible to do it with a direct tool in QGIS 2.18.1, without the aid of another layer?

example

Taras
  • 32,823
  • 4
  • 66
  • 137
newGIS
  • 4,062
  • 4
  • 41
  • 92

3 Answers3

10

I recommend Digitizing Tools plugin.

enter image description here

Once installed, you will find a new toolbar. The eighth from the left of this toolbar, there is an icon called Fill ring with a new feature (interactive).

For you to fill all rings at once;

  1. Switch to Fill all rings in selected polygons with new feature mode by clicking on a small triangle (right-hand-side).
  2. Start editing mode and select polygons you want to work on (you can select all polygons).
  3. Click on the tool icon.
  4. A small dialog box will appear and asks you to give a new attribute value. This value will be given all fillings, so that it helps you to identify these new features in the attribute table. Hit [OK] to close.
Kazuhito
  • 30,746
  • 5
  • 69
  • 149
2

In QGIS I can suggest using a "Virtual Layer" through Layer > Add Layer > Add/Edit Virtual Layer....

Let's assume there is a layer 'layer_with_holes' with its corresponding attribute table, see image below.

input

There are possible two cases.


Case I. When holes that are located on the polygon edges should not be included.

With the following query, it is possible to create a new polygon layer from the empty gaps inside the polygons.

-- generate series
WITH RECURSIVE generate_series(cat) AS (
SELECT conf.start
FROM conf
UNION ALL
SELECT cat + conf.step
FROM generate_series, conf
WHERE cat + conf.step <= conf.stop
),

-- config conf AS ( SELECT 1 AS start, 1 AS step, SUM(st_numgeometries(st_difference(make_polygon(st_exteriorring(l.geometry)), l.geometry))) AS stop FROM "layer_with_holes" AS l )

-- query SELECT cat, st_geometryn(st_union(st_difference(make_polygon(st_exteriorring(l.geometry)), l.geometry)), cat) AS geom FROM generate_series, "layer_with_holes" AS l GROUP BY cat

The output Virtual Layer with its Attribute table will look as follows.

output_1


Case II. When holes that are located on the polygon edges should be included.

With the following query, it is possible to create a new polygon layer from the empty gaps within the polygons.

-- generate series
WITH RECURSIVE generate_series(cat) AS (
SELECT conf.start
FROM conf
UNION ALL
SELECT cat + conf.step
FROM generate_series, conf
WHERE cat + conf.step <= conf.stop
),

-- config conf AS ( SELECT 1 AS start, 1 AS step, SUM(st_numgeometries(st_difference(make_polygon(st_exteriorring(l.geometry)), l.geometry))) + st_numgeometries(st_difference(make_polygon(st_exteriorring(st_union(make_polygon(st_exteriorring(l.geometry))))), st_union(make_polygon(st_exteriorring(l.geometry))))) AS stop FROM "layer_with_holes" AS l )

-- query SELECT cat, st_geometryn((st_union(st_union(st_difference(make_polygon(st_exteriorring(l.geometry)), l.geometry)), st_difference(make_polygon(st_exteriorring(st_union(make_polygon(st_exteriorring(l.geometry))))), st_union(make_polygon(st_exteriorring(l.geometry))))), cat) AS geom FROM generate_series, "layer_with_holes" AS l GROUP BY cat

The output Virtual Layer with its Attribute table will look as follows.

output_2

Taras
  • 32,823
  • 4
  • 66
  • 137
1

You can use the trace tool (on the Snapping Toolbar) and simply trace around the hole in the polygon while creating a new feature in a new layer (or your existing layer).

enter image description here

Ian Turton
  • 81,417
  • 6
  • 84
  • 185