2

I have polygon vector data, some of the polygons are imported from another 3D program (Agisoft Metashape). The imported polygons have up to 12 decimal places in the displayed coordinates (attribute table, vertex tool etc.). The other data has only 3 decimal places.

In project properties, I applied a precision of 2 but it didn't have any impact. I also tried round but this only leads to the displayed coordinates having the right format but if I use an expression like z_min($geometry) z-values with more than 3 decimal places appear again.

How can I change the precision of the vector layer coordinates in general?

1
  • 2
    Are you asking how to use round()?
    – Erik
    Commented Jul 8 at 11:37

4 Answers 4

3

You can use a process tool called Geometry by Expression and use an expression which will round every vertex to 3 decimals:

make_polygon(
    close_line(
        make_line(
             array_foreach( 
                geometries_to_array(
                    nodes_to_points($geometry)
                ),
                make_point(
                    round(x(@element),3),
                    round(y(@element),3)
                )
            )
        )
    )
)

enter image description here

4
  • Thank you for your answer. I thought this will suit best for me, because ervery vertex will be changed, but unfortunately it doesn't work. The expression is invalid. I tryed to figure out whats wrong but I am not quite sure what it is. While checking the syntax , I also didn't find the exprssion geometries_to_array
    – chrissi
    Commented Jul 10 at 7:00
  • Which version of QGIS are you using? geometries_to_array was recently added see: changelog.qgis.org/en/entry/2333 Commented Jul 10 at 9:43
  • Ok. This could be the reason. I am using 3.22-6 an older longterm release, because of a plugin which is not compatible with newer versions.
    – chrissi
    Commented Jul 10 at 10:14
  • I will try it with an newer version later.I thought the many decimal places cause an python error in one of our plugins, but now I realised it was caused by empty geometries. So now, the many decimal places are only an aesthetic problem of inhomogenous data, but it doesn't effect the py-code.
    – chrissi
    Commented Jul 10 at 10:23
1

QGIS has a specific tool for this in the "Processing toolbox": "Snap points to grid".

Note that simply rounding the coordinates (as this tool currently does) can lead to invalid geometries, especially for polygons. To avoid issues with invalid geometries afterwards, best use the "Fix geometries" tool, also available in the "processing toolbox", after "Snap points to grid". Ideally the "Snap points to grid" tool would be improved so it couldn't lead to invalid geometries. I created a feature request for this in the QGIS issue tracker: https://github.com/qgis/QGIS/issues/58023

3
  • Thank you for your solution. I tested it and all the processing tools were working fine, but when I test the resulting layer with an expression like z_min( $geometry ) there are still values with 10 or more decimal places.
    – chrissi
    Commented Jul 10 at 9:08
  • Are those values with many zero's or 9's as decimal values? Possibly the reason for the decimal places is than that they cannot be represented exactly by the double type that is always used internally, so can't really be solved. Another possibility is that "Fix geometries" repaired self-intersections and the points created to solve those will have many decimal places again. Possibly doing another run of both tools solves that.
    – Pieter
    Commented Jul 10 at 9:22
  • 1
    Thank you, but this is propably not the point. But anyhow I can leave this problem behind because I realised that it is not the issue which led to a python error in my plugin as I allready wrote to Bernd Loigge in the comment to the answer at the top.
    – chrissi
    Commented Jul 10 at 10:29
0

Use the tool Refactor Fields. With this tool you can edit the precision of each field. It works for me.

2
  • I don't think this works for the geometry though. Commented Jul 9 at 8:20
  • Thanks for your answer, but this only effects the displayed values and I want to "round" every vertices of each polygon so I dont have coordinates like y: 5819657,62830499168263 in my saved vektorlayer geometry
    – chrissi
    Commented Jul 10 at 8:41
0

If in displaying the values is the only situation where you need a lesser precision you can apply rounding as you calculate the value to display as in: round(z_min($geometry),3)

1
  • Thank you, but I really want to change the geometry value and not only display it
    – chrissi
    Commented Jul 10 at 8:44

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