Multiplying values for each field with unique id
up vote
1
down vote
favorite
For one country I have
- population densities (highlighted with a red rectangular) per watershed
- literacy rate
4.48%
(highlighted with a green rectangular) - watershed IDs, e.g. 3222, 3271 etc.
I'd like to multiply the population of each watershed by literacy rate. Is there a way to do so?
Perhaps using the field calculator?
qgis field-calculator attribute-table
add a comment |
up vote
1
down vote
favorite
For one country I have
- population densities (highlighted with a red rectangular) per watershed
- literacy rate
4.48%
(highlighted with a green rectangular) - watershed IDs, e.g. 3222, 3271 etc.
I'd like to multiply the population of each watershed by literacy rate. Is there a way to do so?
Perhaps using the field calculator?
qgis field-calculator attribute-table
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
For one country I have
- population densities (highlighted with a red rectangular) per watershed
- literacy rate
4.48%
(highlighted with a green rectangular) - watershed IDs, e.g. 3222, 3271 etc.
I'd like to multiply the population of each watershed by literacy rate. Is there a way to do so?
Perhaps using the field calculator?
qgis field-calculator attribute-table
For one country I have
- population densities (highlighted with a red rectangular) per watershed
- literacy rate
4.48%
(highlighted with a green rectangular) - watershed IDs, e.g. 3222, 3271 etc.
I'd like to multiply the population of each watershed by literacy rate. Is there a way to do so?
Perhaps using the field calculator?
qgis field-calculator attribute-table
qgis field-calculator attribute-table
edited Nov 26 at 9:47
Taras
1,5922522
1,5922522
asked Nov 26 at 8:14
Guillaume
1065
1065
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
1
down vote
accepted
You need to convert your literacy rate text to real in order to do the calculation. The rate 4,48 is of text type, thus, you need to convert it to real type to become 4.48 as number not as text. To do that, create a new field of type real (decimal) and name it "Rate_Num" for example, and under "Rate_Num" write the following expression to convert the rate text into rate number:
to_real(replace("Rate_text", ',','.'))
Then add a new field of type real (decimal) to calculate the population density and multiply the "Population" field with the "Rate_Num" field using the following formula, in this example the new field name is "Result", :
"Pop"*"Rate_Num"
add a comment |
up vote
2
down vote
My suggestion is to deploy a Virtual layer through
Layer > Add layer > Edit/Add Virtual Layer
Please try the following statements in the query field
If you need values for fields that share the same id
SELECT SUM(population_densities*literacy_rate)
FROM your_layer
GROUP BY watershed_number
ORDER BY watershed_number
If you need values for each single field
SELECT population_densities*literacy_rate
FROM your_layer
ORDER BY watershed_number
References:
- Virtual layers
- SQL GROUP BY Statement
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You need to convert your literacy rate text to real in order to do the calculation. The rate 4,48 is of text type, thus, you need to convert it to real type to become 4.48 as number not as text. To do that, create a new field of type real (decimal) and name it "Rate_Num" for example, and under "Rate_Num" write the following expression to convert the rate text into rate number:
to_real(replace("Rate_text", ',','.'))
Then add a new field of type real (decimal) to calculate the population density and multiply the "Population" field with the "Rate_Num" field using the following formula, in this example the new field name is "Result", :
"Pop"*"Rate_Num"
add a comment |
up vote
1
down vote
accepted
You need to convert your literacy rate text to real in order to do the calculation. The rate 4,48 is of text type, thus, you need to convert it to real type to become 4.48 as number not as text. To do that, create a new field of type real (decimal) and name it "Rate_Num" for example, and under "Rate_Num" write the following expression to convert the rate text into rate number:
to_real(replace("Rate_text", ',','.'))
Then add a new field of type real (decimal) to calculate the population density and multiply the "Population" field with the "Rate_Num" field using the following formula, in this example the new field name is "Result", :
"Pop"*"Rate_Num"
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You need to convert your literacy rate text to real in order to do the calculation. The rate 4,48 is of text type, thus, you need to convert it to real type to become 4.48 as number not as text. To do that, create a new field of type real (decimal) and name it "Rate_Num" for example, and under "Rate_Num" write the following expression to convert the rate text into rate number:
to_real(replace("Rate_text", ',','.'))
Then add a new field of type real (decimal) to calculate the population density and multiply the "Population" field with the "Rate_Num" field using the following formula, in this example the new field name is "Result", :
"Pop"*"Rate_Num"
You need to convert your literacy rate text to real in order to do the calculation. The rate 4,48 is of text type, thus, you need to convert it to real type to become 4.48 as number not as text. To do that, create a new field of type real (decimal) and name it "Rate_Num" for example, and under "Rate_Num" write the following expression to convert the rate text into rate number:
to_real(replace("Rate_text", ',','.'))
Then add a new field of type real (decimal) to calculate the population density and multiply the "Population" field with the "Rate_Num" field using the following formula, in this example the new field name is "Result", :
"Pop"*"Rate_Num"
edited Nov 30 at 5:27
answered Nov 26 at 8:43
ahmadhanb
21.1k31850
21.1k31850
add a comment |
add a comment |
up vote
2
down vote
My suggestion is to deploy a Virtual layer through
Layer > Add layer > Edit/Add Virtual Layer
Please try the following statements in the query field
If you need values for fields that share the same id
SELECT SUM(population_densities*literacy_rate)
FROM your_layer
GROUP BY watershed_number
ORDER BY watershed_number
If you need values for each single field
SELECT population_densities*literacy_rate
FROM your_layer
ORDER BY watershed_number
References:
- Virtual layers
- SQL GROUP BY Statement
add a comment |
up vote
2
down vote
My suggestion is to deploy a Virtual layer through
Layer > Add layer > Edit/Add Virtual Layer
Please try the following statements in the query field
If you need values for fields that share the same id
SELECT SUM(population_densities*literacy_rate)
FROM your_layer
GROUP BY watershed_number
ORDER BY watershed_number
If you need values for each single field
SELECT population_densities*literacy_rate
FROM your_layer
ORDER BY watershed_number
References:
- Virtual layers
- SQL GROUP BY Statement
add a comment |
up vote
2
down vote
up vote
2
down vote
My suggestion is to deploy a Virtual layer through
Layer > Add layer > Edit/Add Virtual Layer
Please try the following statements in the query field
If you need values for fields that share the same id
SELECT SUM(population_densities*literacy_rate)
FROM your_layer
GROUP BY watershed_number
ORDER BY watershed_number
If you need values for each single field
SELECT population_densities*literacy_rate
FROM your_layer
ORDER BY watershed_number
References:
- Virtual layers
- SQL GROUP BY Statement
My suggestion is to deploy a Virtual layer through
Layer > Add layer > Edit/Add Virtual Layer
Please try the following statements in the query field
If you need values for fields that share the same id
SELECT SUM(population_densities*literacy_rate)
FROM your_layer
GROUP BY watershed_number
ORDER BY watershed_number
If you need values for each single field
SELECT population_densities*literacy_rate
FROM your_layer
ORDER BY watershed_number
References:
- Virtual layers
- SQL GROUP BY Statement
edited Nov 27 at 6:59
answered Nov 26 at 8:38
Taras
1,5922522
1,5922522
add a comment |
add a comment |
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f303894%2fmultiplying-values-for-each-field-with-unique-id%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown