[postgis-users] precision on intersection results

Michael Fuhr mike at fuhr.org
Tue Sep 12 09:30:57 PDT 2006


On Tue, Sep 12, 2006 at 04:50:01PM +0200, TECHER David wrote:
> Select Cast(Intersection(a.the_geom,b.the_geom) as decimal(15,3)) from
> your_fisrt_table a, your_second_table b where ...

Intersection() returns a geometry; casting it to decimal/numeric
won't work:

postgis=> SELECT CAST(Intersection(a.geom, b.geom) AS decimal(15,3))
postgis-> FROM table1 AS a, table2 AS b;
ERROR:  cannot cast type geometry to numeric

Maybe SnapToGrid() is what you're looking for:

postgis=> SELECT AsText(Intersection(a.geom, b.geom))
postgis-> FROM table1 AS a, table2 AS b;
                  astext                  
------------------------------------------
 LINESTRING(1.987654321 0,10.123456789 0)
(1 row)

postgis=> SELECT AsText(SnapToGrid(Intersection(a.geom, b.geom), 0.001))
postgis-> FROM table1 AS a, table2 AS b;
            astext            
------------------------------
 LINESTRING(1.988 0,10.123 0)
(1 row)

-- 
Michael Fuhr



More information about the postgis-users mailing list