I'm creating a Polygon in OGR and adding coordinates to it in Python. It is a must that my coordinates aren't allowed to change when adding, however they do and I don't understand why. Here is my example:

import ogr
ring = ogr.Geometry(ogr.wkbLinearRing)
ring.AddPoint(12.5433, 54.10064)
ring.AddPoint(12.5433026066, 54.1006582464)
ring.AddPoint(12.543312311, 54.1006489082)
ring.AddPoint(12.5433093954, 54.1006320625)
ring.AddPoint(12.5433, 54.10064)

poly = ogr.Geometry(ogr.wkbPolygon)

polygon = poly.ExportToWkt()

Now if I print the polygon, I receive:

'POLYGON ((12.5433 54.10064 0,
           12.543302606599999 54.100658246400002 0,
           12.543312311 54.1006489082 0,
           12.5433093954 54.100632062499997 0,
           12.5433 54.10064 0))'

Clearly floating points have been added to some coordinates and I can't understand why.

Example: (12.5433026066, 54.1006582464) to (12.543302606599999 54.100658246400002)

Numbers in any programming language does not have "absolute" precision. As they must be represented as bits in the computer hardware its precision is limited.

Anyway review this links, because maybe they can help you:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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