2

I have a shapefile with 1364 polygons in the Stockholm area:

attribute table of shapefile

But the "areas" are too detailed - I want to make fewer and bigger polygons. I would like to merge/dissolve all "BASKOD2010" id's based on the five first digits. As an example from my table above, I want to merge 3510280, 3510270 and 3510260 into one polygon.

Can anyone explain how I do this in QGIS?

  • 2
    You could create a new field, then use field calculator to populate it with the first 5 digits of your other field (in Python: BASKOD2010[0:5], then dissolve on the new field. – roms Oct 18 '16 at 21:02
4

If the field type is not string, then the simplest way is to create a new field with Text type of 5 characters length. Then in the field calculator go to Update existing field and select the newly created field. Then use the following expression:

to_string("NewField")

The numbers will be truncated to the first 5 digits.

However, if the existing field is already of Text type, then create a new field as above and use the following expression, and it will do the job:

left("NewField" ,5)

enter image description here

The column in red color is the original column, and the column in green color is the selected first 5 digits.

Then use dissolve tool from Vector -> Geoprocessing tools -> Dissolve, if you are using QGIS 2.14.7, and select the NewField as a base to dissolve your polygons. If you are using QGIS 2.16.3, then go to Processing toolbox -> QGIS geoalgorithms -> Vector geometry tools -> Dissolve

The output of dissolve tool using the NewField column (in this example the column name is EndDateSub) is as follows:

enter image description here

  • This doesn't quite answer the question. You've shown how to create a field of the first 5 characters. Not how to merge the polygons. – Fezter Oct 19 '16 at 1:26
  • 1
    @Fezter thanks for your comment, I will update my answer to use dissolve tool based on the new field. – ahmadhanb Oct 19 '16 at 1:28

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.