17

I have a big Shapefile with 200,000 polygons but the file is too big for the application that will use it. I would like to generalise these polygons and create much smaller file.

I have tried to do this in QGIS using "Simplify Geometries" tool. I have tried this on a very small portion of my Shapefile and I am happy with the results but have small problem which I do not know how to solve. I have appended the image to show the problem.

WHITE boundaries are boundaries before simplification. RED boundaries are after simplification. The problem areas are circled with orange colour. As you can see "simplified boundaries" contain some areas that after simplification do not belong to any of the previous polygons.

How do I simplify this Shapefile and keep common boundaries between polygons as a single line and eliminate areas that have been created after simplification?

Simplified Polygons in QGIS

ADDITIONAL INFORMATION:

After following suggested instructions

  1. Convert polygons to lines
  2. Simplify lines
  3. Convert lines back to polygons

I get the following results. It is slightly better than before but still I get areas outside original polygons (see white areas in the picture below).

@Andrew suggested that I associate each line with adjacent polygon but I do not know how to do it in QGIS.

enter image description here

I am still trying to complete simplifying polygons process. I have followed instructions suggested in this post and when I thought I got acceptable results one more problem appeared. Below is the summary of what I did with images of results. All steps have been performed using PROCESSING toolbox in QGIS.

  1. First, I converted polygons to lines
  2. Second, I cleaned lines using v.clean with break option. This resulted in CLEANED VECTOR LAYER and ERROR LAYER. Error Layer (green dots on the provided image) has green dot on every line intersection. I do not know what this means.
  3. Third, I simplified lines using "SIMPLIFY GEOMETRY" tool (result in red lines in the images). Comparing simplified red lines and original orange lines I am happy with the result.
  4. Fourth, I wanted to convert lines back to polygons using "Polygonize" tool in "PROCESSING" and got results that I did not expect (second image with a shaded dark olive colour polygons). It looks like polygonizer connected error layer intersections and created completely different set of polygons ignoring simplified lines.

Could someone explain what went wrong here?

Why red simplified lines were not converted properly to simplified polygons?

As you can see I am not an GIS expert but need to do this myself. I do not know if I am too far from the solution but it is frustrating that I can see simplified lines that I found acceptable for what I'd like to do but cannot convert them to polygons.

Here are two images with results of last two steps of the process:

Simplified Lines and Original Lines

Results of Plygonized simplified lines

4
  • @nhopton On Polygonizer webpage plugins.qgis.org/plugins/Polygonizer it says that it "Creates polygons from intersecting lines". This suggests that polygons will be created whenever there is a line intersection (but maybe my interpretation is wrong). What I need is to get rid of those gaps that were created when using "simplify geometries" tool and if Polygonizer can do it I would be very hapy.
    – David
    Commented Jan 22, 2014 at 16:53
  • Thinking about it, your original polygon layer ought to simplify without problems. If it's not doing this I think it probably means that you have bad polygons in the original data. Polygons that overlap slightly or that have tiny spaces between them. Try zooming-in on the problem areas to see if you can find anything like this. N.
    – nhopton
    Commented Jan 22, 2014 at 17:42
  • 1
    A good way to preserve topology consists in the workflow suggested by @radouxju (except the centroid calculation which is not necessary) and represented in the Processing model in my answer. Alternatively, I think that GRASS v.generalize is another great option. Hope this helps. Commented Jan 23, 2014 at 9:14
  • Related question: gis.stackexchange.com/questions/20799/…
    – simon04
    Commented May 9, 2018 at 12:42

4 Answers 4

13

I got a pretty good result using GRASS v.generalize from the Processing Toolbox using default values:

enter image description here

Some lines remain untouched.

2
  • Had good success with this method after setting v.in.ogr snap tolerance from -1 (no snap) to 0.00001 as suggested by @Kantan.
    – cm1
    Commented Aug 22, 2018 at 15:39
  • 1
    This tool works really well for internal, shared boundaries, but it seems to often fail to simplify external (non-shared) boundaries at all. When simplifying large areas (e.g. Australian local government areas), some of the more complex coastlines remain, and take up a lot of space. Repeated treatments seem to help a bit, but not completely.
    – naught101
    Commented Sep 21, 2020 at 12:00
6

I got into that problem with Qgis2.16, but couldn't get GRASS to give a topologically correct result like @AndreJ.

A nice workaround is to change the v.in.ogr snap tolerance in the advanced parameters of the v.generalize.simplify tool. The default is -1, which prevents snapping in GRASS.

By putting a small value here (like 1e-05 m), snapping is enabled and GRASS recognises the shared borders of the polygons. The simplification then gives a topologically correct layer, without holes.

Note : By setting the snap tolerance to higher values, it is even possible to alter the polygons so that very thin ones can be deleted if you want. Follow that operation with v.clean using rmarea and a threshold big enough to delete the small leftovers, and there you're done!

4

You can solve the problem with a Processing (ex SEXTANTE) model like this:

enter image description here

Script version:

##Simplify polygons=name
##vectorlayer_input=vector
##number_tolerance=number 0.0
##output_layer_alg3=output vector
outputs_0=Processing.runalg("qgis:polygonstolines", vectorlayer_input, None)
outputs_1=Processing.runalg("qgis:simplifygeometries", outputs_0['OUTPUT'], number_tolerance, None)
outputs_2=Processing.runalg("qgis:linestopolygons", outputs_1['OUTPUT'], None)
outputs_3=Processing.runalg("qgis:joinattributestable", outputs_2['OUTPUT'], vectorlayer_input, ID, ID, output_layer_alg3)

Note: the only constraint is that the common field has to be ID in Join attributes table, because is the only field of the output of Lines to polygons. That's why the common field is not a variable input of the model. So an ID field has to be available in the input polygon layer.

4

first convert your polygon into lines

use v.clean to clean your topology (with the "break" option)

then you simplify your lines

Finally you turn your lines back to polygons.(using polygonize)

EDIT: To get the attributes of your polygons, the best way, if you don't have multipart polygons in the original dataset, is to get the centroids of the old andof the simplified polygons and join them based on the closest location (centroids should not move a lot if you only slightly modify your boundaries)

3
  • 1
    This looks to me like your omitting a few steps, although the workflow might work in the end. When you convert the polygons to lines you might need to associate the line with all adjacent polygons. Then after simplification you need to turn the lines back into multi-part polygons. If the original polygons are convex you may be able to match the original to the simplified using the centroid (e.g. if the centroid of the original is contained in the simplified poly it is a match). If they aren't convex though it will be much harder.
    – Andy W
    Commented Jan 22, 2014 at 14:57
  • Hi, I have followed procedure suggested by radouxju but I still get parts of the original polygon outside its original boundaries. How do I associate the line with all adjacent polygons in QGIS? I am planning to use these polygons in the web applications and need to reduce number of nodes for faster loading. What I get now is good reduction but I cannot get rid of these small areas that are there after simplification. Any ideas to solve this will be greatly appreciated.
    – David
    Commented Jan 22, 2014 at 15:18
  • @David. I think your problem might be with Step 3, lines to polygons. In the Processing Toolkit there a tool called "Polygonize" and I would try this. I think this still needs the Shapely and Numpy packages to be installed. This said, I can't get "Polygonize" to work for me in QGIS-Master just at the minute. N.
    – nhopton
    Commented Jan 22, 2014 at 16:23

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.