mapbox / geobuf

A compact binary encoding for geographic data.
ISC License
967 stars 84 forks source link

Precision with value greater than 6 issue. #113

Closed PrzemyslawSwiderski closed 2 years ago

PrzemyslawSwiderski commented 4 years ago

I have problem with encoding/decoding the following geojson:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "LineString",
        "coordinates": [
          [
            15.726928710,
            52.932085718
          ],
          [
            17.116699218,
            52.912214760
          ],
          [
            16.721191406,
            52.579688026
          ],
          [
            15.803833008,
            52.315195264
          ],
          [
            14.869995117,
            52.439269354
          ]
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              13.716430661,
              53.156653053
            ],
            [
              16.847534179,
              53.156653053
            ],
            [
              16.847534179,
              53.943154702
            ],
            [
              13.716430664,
              53.943154702
            ],
            [
              13.716430661,
              53.156653053
            ]
          ]
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "Point",
        "coordinates": [
          14.518432617,
          52.855864177
        ]
      }
    }
  ]
}

Precision found should be equal to 9, but instead it is resolved to 6. Decoding encoded geobuf file produce the following geojson:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "LineString",
        "coordinates": [
          [
            15.726929,
            52.932086
          ],
          [
            17.116699,
            52.912215
          ],
          [
            16.721191,
            52.579688
          ],
          [
            15.803833,
            52.315195
          ],
          [
            14.869995,
            52.439269
          ]
        ]
      }
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Polygon",
        "coordinates": [
          [
            [
              13.716431,
              53.156653
            ],
            [
              16.847534,
              53.156653
            ],
            [
              16.847534,
              53.943155
            ],
            [
              13.716431,
              53.943155
            ],
            [
              13.716431,
              53.156653
            ]
          ]
        ]
      }
    },
    {
      "type": "Feature",
      "geometry": {
        "type": "Point",
        "coordinates": [
          14.518433,
          52.855864
        ]
      }
    }
  ]
}

So, 3 digits are missing and that is not allowed in my case.

JannikGM commented 3 years ago

This is documented in issue #96 and the README:

https://github.com/mapbox/geobuf/blob/daad5e039f842f4d4f24ed7d59f31586563b71b8/README.md#L31