[postgis-users] WKT/WKB Calculations

Michael Orlitzky michael at orlitzky.com
Sun Sep 27 19:38:53 PDT 2009


I noticed that some error is introduced when converting from WKB to WKT 
(and back). For example, the following computation of a polygon's area, 
divided by itself, should return one:

   SELECT (ST_Area(ST_GeomFromEWKB(ST_AsEWKB(tiger.the_geom)))
          / ST_Area(tiger.the_geom))
          AS area_ratio
   FROM tiger

       area_ratio
   -------------------
                    1
                    1
                    1
                    .
                    .


But when I convert to WKT as an intermediate format, the results get 
thrown off by as much as 0.1% (I realize the first couple of rows don't 
show this, but my tests break when the error passes that threshold):

   SELECT (ST_Area(ST_GeomFromEWKT(ST_AsEWKT(tiger.the_geom)))
          / ST_Area(tiger.the_geom))
          AS area_ratio
   FROM tiger;

       area_ratio
   -------------------
                    1
     1.00000014105231
     1.00000017733961
     1.00000021839733
     1.00000004515224
	        etc.


Is this just a floating point limitation, or something else entirely?



More information about the postgis-users mailing list