5

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 a "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

3
7

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.
0
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

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

8
  • i don't want to digitize by manual- i search for automatic action. – newGIS Jan 15 '19 at 11:27
  • where the trace tool location? – newGIS Jan 15 '19 at 13:31
  • on the Snapping toolbar - look at the one I have ringed in red – Ian Turton Jan 15 '19 at 13:32
  • 1
    your image is too small – newGIS Jan 15 '19 at 13:35
  • 2
    it is a tool bar - so no not in plugins. Right click on a grey area and select it – Ian Turton Jan 15 '19 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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