[postgis-users] get the biggest intersection

Denis Rouzaud denis.rouzaud at gmail.com
Wed Jun 20 04:54:31 PDT 2012


Hi all,

I have a table of line and a table of polygons. For a given line, I 
would like to get the polygon which has the biggest intersection with 
the line.
I tried something like this:

CREATE OR REPLACE FUNCTION distribution.get_zone_id(geometry) RETURNS 
integer AS '
     DECLARE
         inputgeom ALIAS FOR $1;
         id_poly integer;
     BEGIN
         SELECT id INTO id_poly
             FROM  polygons
             WHERE ST_Intersects(inputgeom,geometry) IS TRUE
             ORDER BY ST_Length(ST_Intersection(inputgeom,geometry)) DESC
             LIMIT 1;
         RETURN id_poly;
     END
' LANGUAGE 'plpgsql';

But I have the following error:
ERROR:  Error performing intersection: TopologyException: side location 
conflict at 553524.92178241001 147945.03792368001

If anyone has any idea, tip or whatever, it is very welcome!

Greetings,

Denis



More information about the postgis-users mailing list