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
- ...
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 the 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:
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 that's why I'm looking for 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 to do this in one step?