I have a shapefile which contains all German Zip-Codes in a a five-digit format (e.g. 80637). For what I intend to do, this is way to much detail. I would like to aggregate all Zip-Code areas by the first two digits (e.g. 80).

enter image description here

My approach is ordering ZIP codes in the QGIS attributes table numerically, then selecting them manually, then joining them. This is somewhat cumbersome I'll have to do this a hundert time.

Is there a way of doing this programmatically? I tried automate this process following this instruction, but I failed at importing sextante.


create a new field and copy the first two digits from the left using the field calculator

-> for text, you can use (left(fieldname,2)) in the field calculator. With numeric field you can use floor(fieldname/1000)

dissolve your polygons based on this new field

-> this command is in vector -> geometry -> dissolve

  • 2
    I suggest to use text fields. Otherwise the leading 0 in East German postal codes gets lost.
    – AndreJ
    Apr 14 '14 at 14:32
  • 1
    Thanks for the quick response and saving me a lot of time. The field calculator is a mighty tool I've never noticed/used before. I think this solution can be applied to many problems.
    – stekhn
    Apr 14 '14 at 15:25
  • is it possible to export the 2 digit zip code layer as it's own 2 digit zipcode shapefile? Mar 8 '16 at 17:31
  • I don't understand your comment. maybe you could ask a question with some more details.
    – radouxju
    Mar 8 '16 at 19:29

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.