Using round function in QGIS expression?
Clash Royale CLAN TAG#URR8PPP
I created a grid of rectangular polygons with the Create Grid
function, from the Vector Creation group of the Processing Toolbox in QGIS 3.4.2.
The rectangles measure half a degree of longitude by half a degree of latitude.
When I want to label the polygons, I write an expression that rounds the values of latitude and longitude attributes to 2 decimal places, since the attributes created in the grid brings many decimal places.
But the round
function rounds the values badly.
I know that I can create new attributes that express the coordinates with fewer decimal places and label the entities based on those attributes, but I was struck by the behavior of the function. I expected it to round to the nearest value.
Does anyone know what the problem is that the round
function wrongly rounds off the decimal number?
Attached screenshots of Source Fields and the Attribute Table.
qgis-3.0 expression round-function
add a comment |
I created a grid of rectangular polygons with the Create Grid
function, from the Vector Creation group of the Processing Toolbox in QGIS 3.4.2.
The rectangles measure half a degree of longitude by half a degree of latitude.
When I want to label the polygons, I write an expression that rounds the values of latitude and longitude attributes to 2 decimal places, since the attributes created in the grid brings many decimal places.
But the round
function rounds the values badly.
I know that I can create new attributes that express the coordinates with fewer decimal places and label the entities based on those attributes, but I was struck by the behavior of the function. I expected it to round to the nearest value.
Does anyone know what the problem is that the round
function wrongly rounds off the decimal number?
Attached screenshots of Source Fields and the Attribute Table.
qgis-3.0 expression round-function
add a comment |
I created a grid of rectangular polygons with the Create Grid
function, from the Vector Creation group of the Processing Toolbox in QGIS 3.4.2.
The rectangles measure half a degree of longitude by half a degree of latitude.
When I want to label the polygons, I write an expression that rounds the values of latitude and longitude attributes to 2 decimal places, since the attributes created in the grid brings many decimal places.
But the round
function rounds the values badly.
I know that I can create new attributes that express the coordinates with fewer decimal places and label the entities based on those attributes, but I was struck by the behavior of the function. I expected it to round to the nearest value.
Does anyone know what the problem is that the round
function wrongly rounds off the decimal number?
Attached screenshots of Source Fields and the Attribute Table.
qgis-3.0 expression round-function
I created a grid of rectangular polygons with the Create Grid
function, from the Vector Creation group of the Processing Toolbox in QGIS 3.4.2.
The rectangles measure half a degree of longitude by half a degree of latitude.
When I want to label the polygons, I write an expression that rounds the values of latitude and longitude attributes to 2 decimal places, since the attributes created in the grid brings many decimal places.
But the round
function rounds the values badly.
I know that I can create new attributes that express the coordinates with fewer decimal places and label the entities based on those attributes, but I was struck by the behavior of the function. I expected it to round to the nearest value.
Does anyone know what the problem is that the round
function wrongly rounds off the decimal number?
Attached screenshots of Source Fields and the Attribute Table.
qgis-3.0 expression round-function
qgis-3.0 expression round-function
edited Dec 26 '18 at 7:08
PolyGeo♦
53.2k1779238
53.2k1779238
asked Dec 21 '18 at 1:05
Gabriel De Luca
6487
6487
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Actually I cannot replicate the same behavior that you have. I created a grid with 0.5 degree width of latitude and longitude, and I round it to 2 decimal degree and it works fine. Then I added another column with a value of 50.49 and round it to 1 decimal and it worked as expected and I got 50.5. Here is the table with values:
I am not sure what was going wrong in your case. I used the exact version of QGIS 3.4.2.
Update
You are right. If I use negative latitude and longitude, I got strange results. I think this is a bug in QGIS 3.4.2. You should report this as a bug in QGIS 3.4.2 to the QGIS developer team here:
Thank you very much for your response, I am creating a new grid in a new project to find the solution, but the problem persists. However, I am realizing that the problem does not arise if I create the grid in positive latitude and longitude coordinates. Could you try it in negative coordinates (South and West)?
– Gabriel De Luca
Dec 21 '18 at 2:07
@GabrielDeLuca You are right, I updated my answer.
– ahmadhanb
Dec 21 '18 at 2:25
Thank you @ahmadhanb, I just opened this bug report.
– Gabriel De Luca
Dec 21 '18 at 3:05
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "79"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
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%2f306757%2fusing-round-function-in-qgis-expression%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Actually I cannot replicate the same behavior that you have. I created a grid with 0.5 degree width of latitude and longitude, and I round it to 2 decimal degree and it works fine. Then I added another column with a value of 50.49 and round it to 1 decimal and it worked as expected and I got 50.5. Here is the table with values:
I am not sure what was going wrong in your case. I used the exact version of QGIS 3.4.2.
Update
You are right. If I use negative latitude and longitude, I got strange results. I think this is a bug in QGIS 3.4.2. You should report this as a bug in QGIS 3.4.2 to the QGIS developer team here:
Thank you very much for your response, I am creating a new grid in a new project to find the solution, but the problem persists. However, I am realizing that the problem does not arise if I create the grid in positive latitude and longitude coordinates. Could you try it in negative coordinates (South and West)?
– Gabriel De Luca
Dec 21 '18 at 2:07
@GabrielDeLuca You are right, I updated my answer.
– ahmadhanb
Dec 21 '18 at 2:25
Thank you @ahmadhanb, I just opened this bug report.
– Gabriel De Luca
Dec 21 '18 at 3:05
add a comment |
Actually I cannot replicate the same behavior that you have. I created a grid with 0.5 degree width of latitude and longitude, and I round it to 2 decimal degree and it works fine. Then I added another column with a value of 50.49 and round it to 1 decimal and it worked as expected and I got 50.5. Here is the table with values:
I am not sure what was going wrong in your case. I used the exact version of QGIS 3.4.2.
Update
You are right. If I use negative latitude and longitude, I got strange results. I think this is a bug in QGIS 3.4.2. You should report this as a bug in QGIS 3.4.2 to the QGIS developer team here:
Thank you very much for your response, I am creating a new grid in a new project to find the solution, but the problem persists. However, I am realizing that the problem does not arise if I create the grid in positive latitude and longitude coordinates. Could you try it in negative coordinates (South and West)?
– Gabriel De Luca
Dec 21 '18 at 2:07
@GabrielDeLuca You are right, I updated my answer.
– ahmadhanb
Dec 21 '18 at 2:25
Thank you @ahmadhanb, I just opened this bug report.
– Gabriel De Luca
Dec 21 '18 at 3:05
add a comment |
Actually I cannot replicate the same behavior that you have. I created a grid with 0.5 degree width of latitude and longitude, and I round it to 2 decimal degree and it works fine. Then I added another column with a value of 50.49 and round it to 1 decimal and it worked as expected and I got 50.5. Here is the table with values:
I am not sure what was going wrong in your case. I used the exact version of QGIS 3.4.2.
Update
You are right. If I use negative latitude and longitude, I got strange results. I think this is a bug in QGIS 3.4.2. You should report this as a bug in QGIS 3.4.2 to the QGIS developer team here:
Actually I cannot replicate the same behavior that you have. I created a grid with 0.5 degree width of latitude and longitude, and I round it to 2 decimal degree and it works fine. Then I added another column with a value of 50.49 and round it to 1 decimal and it worked as expected and I got 50.5. Here is the table with values:
I am not sure what was going wrong in your case. I used the exact version of QGIS 3.4.2.
Update
You are right. If I use negative latitude and longitude, I got strange results. I think this is a bug in QGIS 3.4.2. You should report this as a bug in QGIS 3.4.2 to the QGIS developer team here:
edited Dec 21 '18 at 2:25
answered Dec 21 '18 at 1:48
ahmadhanb
21.7k31951
21.7k31951
Thank you very much for your response, I am creating a new grid in a new project to find the solution, but the problem persists. However, I am realizing that the problem does not arise if I create the grid in positive latitude and longitude coordinates. Could you try it in negative coordinates (South and West)?
– Gabriel De Luca
Dec 21 '18 at 2:07
@GabrielDeLuca You are right, I updated my answer.
– ahmadhanb
Dec 21 '18 at 2:25
Thank you @ahmadhanb, I just opened this bug report.
– Gabriel De Luca
Dec 21 '18 at 3:05
add a comment |
Thank you very much for your response, I am creating a new grid in a new project to find the solution, but the problem persists. However, I am realizing that the problem does not arise if I create the grid in positive latitude and longitude coordinates. Could you try it in negative coordinates (South and West)?
– Gabriel De Luca
Dec 21 '18 at 2:07
@GabrielDeLuca You are right, I updated my answer.
– ahmadhanb
Dec 21 '18 at 2:25
Thank you @ahmadhanb, I just opened this bug report.
– Gabriel De Luca
Dec 21 '18 at 3:05
Thank you very much for your response, I am creating a new grid in a new project to find the solution, but the problem persists. However, I am realizing that the problem does not arise if I create the grid in positive latitude and longitude coordinates. Could you try it in negative coordinates (South and West)?
– Gabriel De Luca
Dec 21 '18 at 2:07
Thank you very much for your response, I am creating a new grid in a new project to find the solution, but the problem persists. However, I am realizing that the problem does not arise if I create the grid in positive latitude and longitude coordinates. Could you try it in negative coordinates (South and West)?
– Gabriel De Luca
Dec 21 '18 at 2:07
@GabrielDeLuca You are right, I updated my answer.
– ahmadhanb
Dec 21 '18 at 2:25
@GabrielDeLuca You are right, I updated my answer.
– ahmadhanb
Dec 21 '18 at 2:25
Thank you @ahmadhanb, I just opened this bug report.
– Gabriel De Luca
Dec 21 '18 at 3:05
Thank you @ahmadhanb, I just opened this bug report.
– Gabriel De Luca
Dec 21 '18 at 3:05
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%2f306757%2fusing-round-function-in-qgis-expression%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