0

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)
poly.AddGeometry(ring)
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)
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Nov 20, 2014 at 10:17

1 Answer 1

3

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:

answered Nov 20, 2014 at 10:43

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.