Coordinates precision

Hello,

What is the precision of the floats for the coordinates in shapes, like Polygon? We tried to store a polygon without intersections with coordinates having 6 decimal digits but we got "Unable to Tessellate shape" error:

{'timestamp': '2021-09-27T14:50:46.427812Z', 'status': 400, 'error': 'Bad Request', 'message': '{"hint":"Ensure that this is shape has no self-intersections. If it has, split it into several sub-shapes in such a way that no self-intersections remain.","reason":"Unable to Tessellate shape [[386.41562, 565.6094] [513.0249, 538.96094] [619.57166, 520.6353] [767.19977, 506.289] [907.88605, 497.9589] [1099.2129, 498.9013] [1195.2057, 507.0456] [1203.4454, 505.5837] [1203.573, 501.9473] [1203.5731, 501.94464] [1190.4535, 500.9026] [1190.2885, 504.78632] [1139.4575, 500.21658] [1139.3555, 494.29102] [1124.5372, 493.16135] [1124.67, 496.8161] [1121.9475, 496.69806] [1122.1187, 492.65085] [1101.5104, 491.71823] [1101.7128, 495.61987] [1098.6561, 495.61987] [1098.7572, 491.29382] [974.66943, 489.19507] [974.6986, 490.45502] [971.79803, 490.76035] [971.7731, 488.87952] [921.2863, 489.2724] [921.4196, 493.3556] [918.3664, 493.3556] [918.1993, 489.29642] [903.6128, 489.40994] [903.54694, 490.06866] [885.6189, 489.96793] [885.6299, 489.5499] [746.0154, 496.31168] [745.86743, 498.2444] [746.6732, 506.30194] [726.32794, 508.11487] [725.67017, 500.22217] [706.9845, 501.5434] [707.3927, 506.30194] [704.774, 506.50336] [704.41, 501.72543] [608.293, 512.5985] [520.063, 528.71356] [500.45, 531.9685] [501.85992, 540.11456] [499.56998, 540.5725] [498.18433, 532.60504] [463.6745, 542.30023] [463.94565, 543.78156] [459.16125, 545.64215] [458.83234, 543.6606] [405.88757, 558.5349] [388.8988, 564.70245] [388.53156, 564.83575] [386.37985, 565.61694] [386.37982, 565.61694] [386.37982, 565.61694] [386.38135, 565.61664] [386.38135, 565.61664] [386.39346, 565.6141] [386.41562, 565.6094] ]. Possible malformed shape detected.","type":"illegal_argument_exception"}', 'type': 'ApiException'} 

If you notice there's just 5 decimal digits there. The original data we send have 6 digits, and it's sometimes even wrongly rounded, like e.g. in the 3rd and 5th case below:

386.415622 -> 386.41562
513.024902 -> 513.0249
386.393477 -> 386.39346
565.614061 -> 565.6141
564.835771 -> 564.83575

I did try to find some info about Elastic and coordinates precision, but not much luck so far. Though looking at Shape field type | Elasticsearch Guide [7.15] | Elastic I see some examples for 6-digit precision (e.g. Point coordinates). Still it doesn't prove anything on how Elastic processes them.

Hi,

In the indexing approach is said that:

The coordinates provided to the indexer are single precision floating point values so the field guarantees the same accuracy provided by the java virtual machine (typically 1E-38).

So the rounding values you posted above seems to be right. I had a look at the polygon and it is failing because it founds this too segments intersecting:

  [388.53156, 564.83575],[386.37985, 565.61694]
  [386.37982, 565.61694],[386.38135, 565.61664]

Difficult to asses if this self-intersection is due to the rounding or a real intersection.

Thanks! It would be helpful to trace such problems if the error message also provides the information about intersecting segments.
Here is the original data we send, those intersecting segments you mentioned have slightly different coordinates (due to that rounding?)

[388.531563, 564.835771], [386.37985, 565.616922]
[386.37985, 565.616922], [386.381351, 565.616614]

Full polygon:

      "geometry": {
        "coordinates": [
          [
            [
              386.415622,
              565.6094
            ],
            [
              513.024902,
              538.960938
            ],
            [
              619.571655,
              520.635315
            ],
            [
              767.199768,
              506.289001
            ],
            [
              907.886047,
              497.958893
            ],
            [
              1099.212891,
              498.901306
            ],
            [
              1195.205688,
              507.045593
            ],
            [
              1203.445435,
              505.58371
            ],
            [
              1203.573026,
              501.947307
            ],
            [
              1203.57312,
              501.944641
            ],
            [
              1190.453547,
              500.902579
            ],
            [
              1190.288452,
              504.786316
            ],
            [
              1139.45752,
              500.216583
            ],
            [
              1139.355469,
              494.291016
            ],
            [
              1124.537231,
              493.161346
            ],
            [
              1124.670044,
              496.816101
            ],
            [
              1121.94751,
              496.698059
            ],
            [
              1122.118594,
              492.650836
            ],
            [
              1101.510376,
              491.718231
            ],
            [
              1101.712769,
              495.619873
            ],
            [
              1098.656128,
              495.619873
            ],
            [
              1098.757252,
              491.293826
            ],
            [
              974.669443,
              489.195082
            ],
            [
              974.698608,
              490.455017
            ],
            [
              971.798035,
              490.760345
            ],
            [
              971.773067,
              488.879509
            ],
            [
              921.286339,
              489.272402
            ],
            [
              921.419617,
              493.355591
            ],
            [
              918.366394,
              493.355591
            ],
            [
              918.199252,
              489.296426
            ],
            [
              903.612801,
              489.409939
            ],
            [
              903.546936,
              490.068665
            ],
            [
              885.618896,
              489.967926
            ],
            [
              885.629896,
              489.549884
            ],
            [
              746.015381,
              496.311676
            ],
            [
              745.867432,
              498.244385
            ],
            [
              746.673218,
              506.301941
            ],
            [
              726.327942,
              508.114868
            ],
            [
              725.670191,
              500.222176
            ],
            [
              706.98449,
              501.543385
            ],
            [
              707.3927,
              506.301941
            ],
            [
              704.773987,
              506.503357
            ],
            [
              704.409956,
              501.725423
            ],
            [
              608.29303,
              512.598511
            ],
            [
              520.062988,
              528.713562
            ],
            [
              500.450024,
              531.96851
            ],
            [
              501.859924,
              540.114563
            ],
            [
              499.569977,
              540.57251
            ],
            [
              498.184334,
              532.605034
            ],
            [
              463.674513,
              542.300228
            ],
            [
              463.945648,
              543.781555
            ],
            [
              459.161255,
              545.642151
            ],
            [
              458.832333,
              543.660591
            ],
            [
              405.887587,
              558.534896
            ],
            [
              388.898793,
              564.702453
            ],
            [
              388.531563,
              564.835771
            ],
            [
              386.37985,
              565.616922
            ],
            [
              386.379814,
              565.616935
            ],
            [
              386.379814,
              565.616937
            ],
            [
              386.381351,
              565.616614
            ],
            [
              386.381356,
              565.616612
            ],
            [
              386.393477,
              565.614061
            ],
            [
              386.415622,
              565.6094
            ]
          ]
        ],
        "type": "Polygon"
      },

So it seems that the error is introduced by the rounding so in other words: Shape field type cannot handle that polygon as it requires higher precision. In the float space it becomes a self-intersecting polygon.

Thanks! It would be helpful to trace such problems if the error message also provides the information about intersecting segments.

Could you open an issue in the Elasticsearch repository?

1 Like

Sure. I hope I did it in the right place with all necessary data: