     nesw := get_nesw(boundary);
     RAISE NOTICE '%', nesw;
 
+    lrc := (
+        SELECT
+        -- array_agg(a.l)
+        ARRAY_AGG(3)
+        FROM unnest(nesw) a(l), unnest(boundary) b(w)
+        -- JOIN unnest(ARRAY[rc2[1],rc2[2]]) c(w) ON c.w = b.w
+    );
+    RAISE NOTICE '%', lrc;
 
     -- TODO: call get_nesw to get labels for boundary points
     -- distinguish between multiple cases. these cases come up
     -- due to position of the nearby-road relative to the boundary points.
     -- the goal is to decide which corner we're going to cut: NW,NE,SE or SW.
-    IF   (rc2[1] = boundary[4] AND rc2[2] = boundary[3]) OR (rc2[1] = boundary[3] AND rc2[2] = boundary[4]) THEN
-        RAISE NOTICE 'north-west cut';
-    END IF;
 
     -- TODO: need to take the decision here on which
     -- direction to sweep in

    -- (so they will be clock-wise sorted)
    boundary := (
        WITH int AS (
            -- intersect the polygon ring with the
            -- envelope(bounding-box) ring to get the boundary
            -- extremum points (north,east,south,west).

                WHERE gid = p_uid
            ) a
        ), unpacked AS (
            -- TODO: handle cases where the intersection is a line and not a point
            -- (these cases are generated by the edge of the bounding box coinciding
            --  with the contour of the shape, for axis-parallel squares for example).
            -- will have to think how to handle those.
            -- 
            -- unpack ST_MultiPoint to ST_Point
            SELECT (ST_Dump(way)).geom AS p
            FROM int
