3

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.

source-fields

round-expression

2

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:

enter image description here

enter image description here

enter image description here

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:

enter image description 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

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.