Large UTM coordinates snap, workaround and possible solution

Hi everyone,

I wanted to share a quick note about the classic “snap” issue when working with real UTM coordinates (X/Y in the millions) in GiD/Iber. As you probably know, the cursor jumps in 1m or 10m steps, making precise geometry creation and picking a real headache. It’s just the OpenGL float32 limitation, while the kernel itself works in double precision.

My current workaround
To get around this, I ended up writing a Tcl plugin (UTM_Tools) that physically translates the imported geometry to the origin (0,0,0). I work locally and only re-apply the offset when exporting or calculating. It works, but moving geometry around is destructive, can mess up the topology, and requires custom plugins for different problem types. For the moment the plugin works only with IBER and with Shapefile and background image import.

The idea
Instead of relying on external plugins and physical moves, would it be feasible to introduce two project-level variables (offset_x, offset_y, default 0.0) directly in the kernel?

The kernel could apply the offset transparently only at the boundaries:

  • Subtracting it before sending data to OpenGL (so the GPU always gets small numbers).

  • Adding it to the GiD_GetWorldCoord results.

  • Applying it automatically during import/export.

This would keep the kernel in double precision, OpenGL safe, and make the whole user experience completely transparent across any problem type.

I’ve looked into the Tcl interface files to see where the kernel would need to apply this offset.

I cannot upload files so the following is an extract of a report on the problem:

Based on the analysis of the Tcl interface files (gid_gis.tcl, gid_shapefile.tcl, Import.tcl, tclfileP.tcl, GrDataMenus.tcl), the offset must be applied at the following kernel boundaries:
5.1 Rendering pipeline (OpenGL → GPU)
• Before submitting vertices to OpenGL, the kernel subtracts (offset_x, offset_y, offset_z).
• Result: OpenGL receives coordinates near the origin and never suffers from float32 precision loss, regardless of the real model position.
• The internal double-precision database is unchanged: it continues to store real coordinates.
5.2 Picking (mouse → world coordinates)
• When the user clicks, the kernel converts screen (2D) → model (3D) coordinates.
• The result returned to Tcl (via GiD_GetWorldCoord) must be local + offset, so the user always receives real coordinates.
• This single change automatically propagates to all places that use GiD_GetWorldCoord: precision-point tools, geometry creation, the coordinate bar, etc.
5.3 Status bar (bottom-right coordinate readout)
• If §5.2 is applied, the status bar (currently populated by the C++ kernel) automatically shows real coordinates. No additional work is needed.
5.4 User input (command line, Coordinate Window)
• When the user types coordinates (command line or Coordinate Window), the kernel must interpret them as real coordinates and internally use real - offset before storing them.
• If the current input is in local coordinates (e.g. Create Point after an Offset = 0 project), behavior is unchanged.
5.5 File I/O (import / export)
• Import (Shapefile, XYZ, GDAL Raster, DXF, KML, STL, .msh, .2dm, etc.): the kernel receives real coordinates from the file, subtracts the offset, and stores local in the database. The Tcl-level importers that call GiD_Geometry create point will see local coordinates coming out of the kernel.
• Export (IGES, DXF, VTK, .msh, .dat, .bas, STL, etc.): the kernel adds the offset before writing.
• Raster georeferencing: the georeferencing info (.prj, GeoTIFF metadata, etc.) is already read by GDAL and used to compute the raster’s extent. The offset should be applied to the computed extent before sending it to OpenGL.
5.6 Solver input files (calculation)
• When writing .dat/.bas files for the solver, the offset is subtracted so that the solver works in local coordinates.
• This is compatible with the existing Iber behavior where the solver already works in local coordinates (or can be made to).
• Optionally: provide a preference so the user can choose whether the solver receives real or local coordinates.
5.7 Camera and view
• The camera (eye, target, up vector) and view matrix should remain in local coordinates internally, to avoid precision issues in the matrix math.
• The view is then rendered correctly after §5.1.
5.8 Operations that are already double-precision
• Boolean operations, NURBS construction, mesh generation, and the mathematical kernel in general already work in double precision. They see real coordinates internally and are unaffected by the change. Only the rendering and picking views need the offset applied.

I’d love to hear if the developers think this is feasible, or if anyone else has found a better way to handle this!

Cheers

Oscar

Hi Oscar,

About the ‘snap’, the cursor jumps to the ‘grid nodes’, the default spacing is 1 unit (UTM models are implicitly in meters), but in preferences can change this grid spacing.

In any case this is not the problem with common UTM coordinates, that use too big numbers to be represented with floating point. The problem is graphic with OpenGL (with these numbers there are graphic artifacts in screen an selecting in screen)

Unfortunately OpenGL and the graphic card drivers are not planning to implement coordinates with double instead float (although it exists limited support for doubles using shaders)

The solution could seems simple: sum an (offset_x,offset_y,offset_z) to the coordinates

There are the the approaches that you suggest:

0-Expect that OpenGL implements double (but it won’t happen)

1- Do the trick at ‘GiD-side-kernel’: e.g. intercept all OpenGL calls and sum this offset in each redraw
2-Do the trick at ‘problemtype/plugin side’: move the geometry/mesh near the origin with and offset and revert this movement in some places where coordinates are used (what you did in your own UTM_Tools plugin or can be added to Iber problemtype)
3-Do the trick at ‘user side’: move the geometry/mesh manually (move window) and store somewhere (e.g. a note) the offset used, to move it again if require some export that need the original UTM coordinates (e.g. shapefile or geo-referenced raster)

Any of these solutions are completely satisfactory.
The solution must not have big impact in performance (speed and memory consumption ). Most GiD uses are not related to UTM terrain models.

and must be robust: all possible Tcl and C++ affected commands must be taken into account. You have enumerated some of them, but there are more…

Probably you have noticed that your plugin is not perfect and have not covered all paths. If you provide us we can examine it and aid to enhance it, but won’t be perfect (but maybe good enough to add its features to the Iber problemtype GUI)

At GiD side we continue thinking in the implementation of 1, doing at ‘render pipeline’ side, but this task is planned since a lot of years ago, and maybe will never done.