5

Through a "dissolve" process in QGIS, I achieved some defective polygons generated after dissolve process that have some fails, like these in the screenshot:

example

Is there any automatic process I can make in QGIS to remove those lines inside the polygon and leave only the outer borders? I can manually delete using the "Node Tool", but I was looking for an automated solution.

The polygon seems to be closed, as it can be seen:

Selected polygon, with defective lines

  • 1
    I assume those lines are inner rings, so this might help you with some python code: gis.stackexchange.com/questions/113284/… – AndreJ Jul 27 '15 at 9:25
  • 2
    Did you already try the GRASS v.dissolve from the toolbox? Normally this is faster and produces less errors. For removing artefacts, try v.clean with e.g. rmarea – Bernd V. Jul 27 '15 at 10:40
  • 1
    Have a look to this discussion: gis.stackexchange.com/questions/154598/… – Sergio Jul 27 '15 at 11:04
  • Thank you so much! I'll study all these proposals and then report which worked better for me. – Alan Tygel Jul 28 '15 at 10:10
5

You can use the QGIS-Processing tool Delete holes for that.

Just pass the polygon layer with holes, the algorithm will remove all inner rings (aka. holes) for each polygon automatically.

  • I had to use the tool several times on the cleaned output again to get a good result. Did not remove 100% by this procedure but around 90% – joaoal May 2 at 8:50
3

I have never worked in QGIS. The R equivalent would be to use gUnion in the rgeos package: http://www.inside-r.org/packages/cran/rgeos/docs/gUnion

Here is a reproducible example to demonstrate:

library(sp)
library(rgeos)

#create polygon
r1 <- cbind(c(641777, 642290, 642276, 641794), c(7036885, 7036743, 7036154, 7036146))
r2 <- cbind(c(642320, 642478, 642494, 642314), c(7036732, 7036699, 7036296, 7036290))
sr1 <- Polygons(list(Polygon(r1)),"r1")
sr2 <- Polygons(list(Polygon(r2)),"r2")
boundary.sp <- SpatialPolygons(list(sr1,sr2))
boundary.sp@proj4string <- CRS('+proj=utm +zone=35 +south +datum=WGS84 +units=m +no_defs')

#create bounding box grid
bbox <- bbox(boundary.sp)
boundary.grid <- expand.grid(x = seq(from = bbox[1], to = bbox[3], by = 100), y = seq(from = bbox[2], to = bbox[4], by = 100))
coordinates(boundary.grid) <- ~x + y
gridded(boundary.grid) <- TRUE
boundary.grid@proj4string <- boundary.sp@proj4string

#cut grid with polygon to create SpatialPolygons grid
boundary.poly.grid <- as.SpatialPolygons.GridTopology(getGridTopology(boundary.grid), proj4string = CRS('+proj=utm +zone=35 +south +datum=WGS84 +units=m +no_defs'))
boundary.grid.smooth <- gIntersection(boundary.poly.grid, boundary.sp, byid=TRUE)
plot(boundary.grid.smooth)

#use union to dissolve all the polygons contained
boundary.dissolved <- gUnionCascaded(boundary.grid.smooth)
plot(boundary.dissolved)

Hope it helps.

2

This happens often often to me when dissolving polygons. The only reliable and easy way that I found was to buffer the polygons with a minimal distance that is still acceptable for you (e.g. 0.001 meters).

0

I have a solution that is applicable in a small scale project and doesn't involve programming of any sort.

Probably someone already figured this, but I'll take my chances:

1) Create an ID on the original, damaged layer

Creating an ID attribute is simple, but so is my solution, so I'll go over it. creating an ID attribute on field calculator

First, you have to open your attribute table and then go to the Field Calculator, which is a button pretty much like an abacus. There, you will be given the option to create a new field or update an existing one. On the picture above I'm creating a new one called "ID". The formula is right at the end of the picture. (Sorry for having my QGIS set up in a different language. Since the design and the formulas are exactly the same throughout the language versions, I don't think it will get in our way here.)

Attribute table

2) Convert the polygons to lines

This step is located on the Vector > Geometry section the the menu. Your converted shape should look like this:

Polygons converted to lines look like this Right after converting the polygons to line, you will have to do the exact opposite, which is...

3) Convert lines to polygons

The options are right next to each other. Again, let's not mind the language barrier here. Do not mess the order here!

4) Rejoice The reason you did steps 2 and 3 is because now you're sure those lines will be considered as polygons, which means they now have their own line on the Attribute Table. If you check it out, it will look like this:

An Attribute Table ready to face some manual deletion process!

The first one is ALWAYS the entire polygon (trust me, I've deleted a couple hundred lines today...) and the rest are the loose lines in the middle. You can enable editing and get ready for action. If you decide to try this, two things that you should keep in mind are: organize your table ID-wise, this way you're sure you're not missing anything and use shift to select clusters of data, just like any other program.

I'm aware this is not the crème de la crème of QGIS problem-solving, but if you're facing a situation where the tools are not working because of the invalid geometries these lines create (I even tried dissolving by the ID instead of deleting manually, but it didn't work), then this might be a way out.

  • 1
    Your image links are no longer working. Can you move them to another site perhaps? – Mattropolis Aug 24 '17 at 22:07

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.