Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have seen some posts on this, but only for ArcMap. I am looking to take a range of values from two fields and concatenate them into one field to make a unique value. For example:

332500   5366000    33255366
333000   5366000    33305366

In ArcMap you can do something like (Mid([XMAX]),1,4)+(Mid([YMAX]),1,4).

I know this can be done in a PostGIS database, but for the moment it needs to be done on a shapefile and I am looking to use QGIS.


share|improve this question
Are "XMAX" and "YMAX" actually string fields or are they really numeric? – whuber Jun 22 '12 at 15:47
They are numbers. But I converted the number values to string in new columns and the calculation Jef supplied still didn't work. – Ryan Garnett Jun 22 '12 at 15:50
Why not just combine them numerically then? The simplest example assumes all values of "XMAX" are six-digit multiples of 100 and all values of "YMAX" are seven-digit multiples of 1000: "XMAX"*100+"YMAX"/1000 does the trick. More generally you may need to do some rounding of the values before carrying out this calculation. – whuber Jun 22 '12 at 15:54
Thank you Whuber, that totally did it. Thanks! – Ryan Garnett Jun 22 '12 at 17:06
up vote 3 down vote accepted

In QGIS it's almost the same: substr("XMAX",1,4)||substr("YMAX",1,4) in the field calculator.

share|improve this answer
Thank you Jef. I have tried this, but it does not return anything. The field remains NULL. – Ryan Garnett Jun 22 '12 at 15:21
Hm, works for me in 1.8. If you are using an earlier version try: substr(tostring("XMAX"),1,4)||substr(tostring("YMAX"),1,4) – jef Jun 22 '12 at 15:51
I was am using 1.7.4. Is your output new field a String? My input fields are Whole Numbers. – Ryan Garnett Jun 22 '12 at 17:04
no, xmax, ymax and gridid are whole numbers - but the conversions should happen transparently. But I think the expression engine was completely redone in 1.8, so ymmv with 1.7. toint(...) should still help there. – jef Jun 22 '12 at 17:35
Yeah the 1.8 and 1.7 expression engines are different – Nathan W Jun 23 '12 at 5:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.