2

When I digitize a polygon and snap to existing features, sometimes the coordinates end up very slightly away from where I want them to be for example 15.000000099, rather than 16.

Is there a way to round each vertex to a fixed precision?

8
  • Are you talking about manually editing those features?
    – Erik
    Commented Aug 20 at 9:26
  • No. I want some way to run a rounding function across all vertices, then save the rounded geometry without manually editing. Commented Aug 20 at 9:27
  • 2
    Perhaps there is a mistake here (should be 15): for example 15.000000099, rather than 16. Commented Aug 20 at 10:15
  • 2
    Try Snap points to grid
    – Bera
    Commented Aug 20 at 11:07
  • 2
    Why would you want to snap double precision rounding of a value near 15 to 16?
    – Vince
    Commented Aug 20 at 11:54

2 Answers 2

9

THIS WILL OVERWRITE YOUR DATA (MAKE A COPY)

That's easy:

  1. Open Field Calculator.
  2. Insert this code: geom_from_wkt(geom_to_wkt(@geometry, 0))
  3. Replace 0 with precision you need.
  4. Check box Update existing field.
  5. Choose <geometry>as a field.
  6. Press OK.

Field Calculator before after

-parameters ---->before ------->after

Another example with point:

enter image description here

P.S. This can collapse your polygons to a point or line, so choose precision wisely.

4
  • 1
    Okay, that's way easier than I thought it would be =D
    – Erik
    Commented Aug 20 at 10:36
  • 1
    Great answer -didn't know about the possibility to update geometries with field calculator! Do you know since which version this is possible?
    – Babel
    Commented Aug 20 at 12:59
  • 1
    @Babel This feature was implemented in 2016. Changelog for QGIS 2.14 2016-02-26: qgis.org/project/visual-changelogs/visualchangelog214/… Commented Aug 20 at 19:22
  • Thanks for this. I will revert and accept once I have tested it. Commented Aug 21 at 0:27
4

You can use the "Snap points to grid" (native:snappointstogrid) processing algorithm https://docs.qgis.org/3.34/en/docs/user_manual/processing_algs/qgis/vectorgeometry.html#snap-points-to-grid

3
  • As with all ways to do this in QGIS at the moment, this can lead to invalid geometries. If you want to have this solved, please "vote" on this QGIS issue :-): github.com/qgis/QGIS/issues/58023
    – Pieter
    Commented Aug 20 at 15:56
  • I will try this. However, the polygons were digitised by snapping to a generated grid of points at regular spacing, so I was surprised to find that some of the vertices were not exact when I extracted them. That is what I am trying to remedy. Commented Aug 21 at 0:26
  • @LeighBettenay, I didn't understand correctly your question. May you please better clarify the issue? Commented Aug 21 at 5:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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