3

I was given a shapefile made up of a few thousand squares. The data in the squares has 5 different values. I wanted to merge all the common values into the same polygon to simplify things. This is what it looked like.

Before Merge

I used the the Select by Expression tool to select all the polygons of the same values and then used the Merge Selected Features tool to merge the polygons together. I was hoping I would be left with 5 geometries that held each value. However after the merge I had vertical stripes through each of the zones as shown here.

After Merge

I suspect that I'm looking at polygons that have points that are not exactly at the same coordinates. I also suspect that it is a problem created by the software program that generated the shapefile. I was able to confirm this by using the Snap tool to move the points and snap it back over the other one and then I could merge the polygons together. I don't have the time nor the patience to do that for every point on the map.

I've tried to use the GRASS clean tools to get rid of these points as well as a few other tools I could find and have searched the forum for solutions, but after an afternoon of not getting anywhere, I've decided to see if anyone could help me figure this out. I've provided the (Shapefile Data) here if someone wants to try to do it.

How do I clean this up?

I'm running 2.18.14.

5

Here is the workflow on how to solve this problem using your data:

  1. Download Multipart Split from the plugin manager
  2. Start editing your polygon layer -> Select all -> Use Multipart Split tool from step 1 to explode the polygons into separate polygons. (# Singlepart to Multiparts tool did not work)
  3. Agree with @Matte solution, you need to use Snap points to grid from QGIS Geoalgorithms -> Vector general tool -> Snap points to grid with Horizontal and vertical spacing of 0.000001 (the minimum you can).
  4. Use Dissolve tool to merge all the polygon together based on field attribute QGIS Geoalgorithms -> Vector general tool -> Dissolve, and uncheck the option (Dissolve all (do not use field))

enter image description here

Here is the result of step 2:

enter image description here

Result of step 4:

enter image description here

However, there are some missing tinny polygons, and I think this is due to the CRS used. You are using geographic (unprojected) data, and working with unprojected data for cleaning polygons may produce undesired outputs.

  • Thank you all for your suggestions and clear instructions. There are so many tools available for QGIS it is sometimes hard to find the right ones for the job. I was able to use the instructions above to completely clean up the data in no time. – Jason Steffen Mar 16 '18 at 15:13
  • @JasonSteffen You are welcome. Glad it worked :) – ahmadhanb Mar 16 '18 at 17:52
3

In those cases where coordinates are not exact enough for the needed topological relation (neighbors should share the same edges and vertices) you can work with snapping as you mentioned.

To not do it manually you can snap all your coordinates to an underlying grid. In this case the vertices are moved to the nearest grid. The question there is the needed accuracy. I would use the "Snap points to grid" tool from the QGIS processing toolbox (at "QGIS Geoalgorithms" - "Vector general tools"). I would try with a horizontal and vertical spacing of 0.000001. This is in average a grid below 1 meter extent an should be accurate enough. All your edges and vertices are moved by this operation and you get a new file. In the new file merging should work much better.

And by the way you can use the dissolve tool for merging polygons sharing the same attribute value to not do it manually.

1

You could just buffer your layer a tiny bit and buffer back with a negative value. So you get rid of the vertical stripes: Just run in your OSGeo4W shell which comes with your QGIS install:

ogr2ogr.exe C:/myfolder/output.shp C:/myfolder/SW14_ADS.shp SW14_ADS -dialect sqlite -sql "SELECT ST_Buffer(ST_Buffer( geometry , 0.0000000001 ), 0.0000000001 ),* FROM 'SW14_ADS' "

enter image description here

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.