2

I am doing research on the protected areas of the Amazon rainforest and I need to create a single polygon layer that has all the forested non-protected areas in one attribute row. I have tried using different polygonise functions in QGIS with different dissolve functions and fixing geometries, but I always end up with the same final layer which has invalid geometry.

After polygonising the raster and saving the forested areas, I have a multipolygon layer (with thousands of rows in the attribute table) which looks like what I wish to achieve: Multipolygon layer

However, when I try to dissolve the layer into a single polygon layer (with SAGA Polygon Dissolve (all polygons), but the same happens with GDAL Dissolve), I get these polygons within polygons:

Singlepolygon layer

(This is just one area, not the whole layer, showing the areas that appear after trying to dissolve the multipolygon layer)

I've tried to use "Fix geometries", but that only removed some of the unwanted areas (the fixed image is included here).

I have tried to fix this problem for more than a week now and am running out of options to try.

Edit: I am running 3.2.0-Bonn on Windows 10. My GDAL/OGR version is 2.2.4 and I use WGS84 as my CRS.

14
  • Any chance you could crop your raster down to something small that illustrates the problem which you could share with us?
    – Spacedman
    Commented Aug 17, 2018 at 7:34
  • 1
    Welcome to GIS SE. As a new user, please take the Tour, which emphasizes the importance of asking one question per Question. Unfortunately, "Using A or B" questions are considered two questions, since the solutions are very different. Given that your description is about QGIS, I suggest yor remove R, and include exact details about the version(s) of QGIS (and GDAL) in use, and the exact spatial reference and command parameters involved.
    – Vince
    Commented Aug 17, 2018 at 7:42
  • Not sure if it will fix it, but I also had the problem that after I vectorized a rasterimage the created polygons had tons of geometry errors (intersections) and I was not able to process them. The "fix geometry" tools did not work either. What I did to fix it in the end is, that I drew a really small buffer around the polygons. The buffered polygons had no geometry errors. Perhaps it does work for you.
    – gHupf
    Commented Aug 17, 2018 at 7:52
  • 1
    @gisnside No, I need to take a random sample from the non-protected forested area and I use the polygon layer as the area from which the sample is taken. I use the spsample function in R for sampling. My code requires the polygon layer to have one polygon with one attribute row in order to work... I think I could use the multipolygon layer if I used x = "Polygons", but because these issues have come up I fear the geometry is invalid and there would be errors in the sampling.
    – TeemuK
    Commented Aug 20, 2018 at 10:33
  • 1
    It looks like the rings in your polygon are being turned into separate polygons, which can happen sometimes when non-core tools (ie SAGA and GDAL). Have you tried dissolving using the built-in QGIS > Vector Geometry > Dissolve tool? You could also try the Merge tool (advanced digitizing toolbar).
    – csk
    Commented Aug 21, 2018 at 20:14

2 Answers 2

2

For your specific question :

  • Reclassify your raster (to avoid further polygon dissolving) to make sure to have only 0/1 values, so that "1" values are the ones your need to convert into polygons (See Performing Raster Reclassification in QGIS? if necessary)

  • Convert this raster into a polygon with the r.to.vect GRASS tool, you should get all the raster value converted, cut in polygones with "0" and "1" values, on the raster footprint.

  • In the attribute table, delete "0" values, you should only have left "1" values polygons

  • Use the "Single to Multipart" tool to restore one polygone multipolygon

For your final objective :

Notice : For this part, you don't need one multipolygon.

  • To complete your final objective and inspired by this document , create a mesh or a regular point or polygon grid on your polygon layer boundary. You can use the vector Menu/Research Tools/Create grid tool or with QGIS geoprocessing tools/ Vectero creation tool/regular points

  • Select all points or polygons that are within your selected polygon area, invert selection, then delete external features.

  • With the vector Menu/Research Tools/Random selection tool, select a number of random interest points.

3
  • I am not sure what you meant by “raster footprint”, this is a new term for me, but I used the default options of the r.to.vect tool to create a polygon layer from the raster. I also assume you meant Multipart to singleparts tool, which I used after deleting the 0 values from the attribute table. However, this did not create one multipolygon layer, I still had separate rows of data. When I dissolved this, the result had the same errors.
    – TeemuK
    Commented Oct 9, 2018 at 15:06
  • The random sampling you suggested does not work for my purposes, unfortunately.
    – TeemuK
    Commented Oct 9, 2018 at 15:07
  • Interestingly, as I used Fixed geometries to remove the errors, they were all gone and I had the layer I want, but I am unable to save it, because when I do, the errors reappear in the saved file. Does anyone know why that is?
    – TeemuK
    Commented Oct 9, 2018 at 15:08
0

I decided to check if this was a QGIS specific problem and did the same process in ArcGIS on a different computer. I dissolved the multipolygon layer, and ArcGIS did not visualize the errors – even though I was using a copy of the same file. However, when I looked at this dissolved "error free" file in QGIS, the errors reappeared.

I decided to try the sampling to see if the sample points would appear on the error areas or not. I created a new singlepolygon layer in the latest version of QGIS (3.2.3. Bonn) and used Fix geometries tool. I used the fixed layer in the sampling and no samples appeared on the "error" areas (see picture). Besides a visual check, I also reaffirmed this by quantitative means in R.

My best guess is that this was a visual bug in QGIS since ArcGIS did not show these errors in the same file.

Sample points visualized in QGIS: No samples appeared on the "erroroneous" coloured polygon within polygon areas.

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.