# [OSM-dev] osm2pgsql / postgis precision

Thu Jul 2 20:48:22 BST 2009

```On Thu, 2009-07-02 at 19:44 +0200, Jan-Benedict Glaw wrote:
> On Wed, 2009-07-01 19:13:26 +0100, Jon Burgess <jburgess777 at googlemail.com> wrote:
> > On Wed, 2009-07-01 at 13:51 +0200, Etienne Chové wrote:
> > > Etienne Chové a écrit :
> > > > The difference is not really significant but postgis says
> > > > polygons are olvelapping each other while they have just a
> > > > common boundary.
> > >
> > > The errors doesn't appear when I delete lines "#define
> > > FIXED_POINT" in middle_ram.c and middle_pgsql.c
> > >
> > > Is it danerous to delete them ?
> >
> > I have come across this issue before, the 'slim' mode can fetch the node
> > positions from the DB or from a RAM cache. The DB stores the positions
> > in doubles (giving 53 bits of precision), the RAM cache uses fixed point
> > arithmetic giving around 32 bits of precision. 32 bits is perfectly
> > sufficient for OSM and halves the storage size.
>
> Are you 100% sure about that comment?
>
> ISTR that at some time, I calculated the accuracy of 32bit (float) at
> the aequator, which resulted in +/- 15cm or the like. This may or may
> not be enough...

A 32 bit fixed point number is perfectly adequate, a 32 bit float is
not. A 32 bit single precision float has only 24 bits of precision.

In the middle-pgsql.c code we use a multiplier of 100 to convert the
Mercator co-ordinate to a fixed point number. 1 mercator co-ordinate is
about 1 metre around the equator. This give us a precision of around 1cm
(4e7/2^32=0.01m)

A 32bit float with only 24 bits of precision gives 4e7/2^24 = 2.38m

Jon

```