1

I have an Open Street Map Shapefile and i want to use Field Calculator to add information to a field called a800900 according to the field TYPE of street, by different area (field called ID_2).

The field TYPE of street has the following values

  • motorway
  • trunk
  • primary
  • secondary
  • tertiary
  • residential

And the field ID_2 is a numeric code for 85 municipalities:

  • 8527
  • 8300
  • 8302
  • ...

enter image description here

The information added to a800900 it's based on the TYPE of street and will be different per each ID_2. So, I've been selecting each ID_2 and then performing calculations with Field calculator in two steps.

STEP 1:"Select By Expression"

ID_2 IS '8283'

STEP 2: "Field Calculator"

CASE

WHEN TYPE IS 'motorway' THEN 2405.396*0.01847

WHEN TYPE IS 'trunk' THEN 2305.396*0.0154

WHEN TYPE IS 'primary' THEN 1807.226*0.013

END

The following figure show this process: enter image description here

Then, i do similar calculations for another ID_2, varying the values in Field Calculator:

STEP 1:"Select By Expression"

ID_2 IS '8302'

STEP 2: "Field Calculator"

CASE

WHEN TYPE IS 'motorway' THEN 2405.396*0.75

WHEN TYPE IS 'trunk' THEN 2305.396*0.34

WHEN TYPE IS 'primary' THEN 1807.226*0.47

END

At the end I'll get values in a800900 different for each TYPE of street and ID_2. As example, if ID_2 is 8300 and TYPE of street is motorway, then a800900 is 2450, if ID_2 is 8302 and TYPE of street is motorway, then a800900 is 2300, and so on.

I have to make the estimation with Field Calculator for each ID_2, being 85 areas, and thats's why i'm looking a faster procedure. I would like to know if there is a ONE STEP procedure with Field Calculator, like:

CASE

WHEN ID_2 IS '8283'AND WHEN TYPE IS 'motorway' THEN 2405.396*0.01847

WHEN ID_2 IS '8283'AND WHEN TYPE IS 'trunk' THEN 2305.396*0.0154

WHEN ID_2 IS '8283'AND WHEN TYPE IS 'primary' THEN 1807.226*0.013

WHEN ID_2 IS '8302'AND WHEN TYPE IS 'motorway' THEN 2405.396*0.75

WHEN ID_2 IS '8302'AND WHEN TYPE IS 'trunk' THEN 2305.396*0.34

WHEN ID_2 IS '8302'AND WHEN TYPE IS 'primary' THEN 1807.226*0.47

END

Is there a way in one step?

Thank you so much

  • Why don't you select all at once? ID_2 in ('8283','123','456') ... – underdark Nov 16 '13 at 23:19
  • I think i wasnt clear. I need to create a new field relating ID_2 and TYPE. ID_2 has 85 areas. TYPE 60.000 streets, belonging to these areas (municipalities). Every ID_2 has different Values. I'm gonna edit my question. – Sergio Nov 17 '13 at 1:00
  • Please explain the rules of the calculation after the THEN cluase. I cannot see the pattern. If we understand the rules, there should be a way to do this. – underdark Nov 17 '13 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.