1

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:

XMAX     YMAX       GRIDID
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.

Thanks

  • Are "XMAX" and "YMAX" actually string fields or are they really numeric? – whuber Jun 22 '12 at 15:47
  • 1
    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
  • 3
    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
3

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

  • 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 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.