[postgis-users] Looking for function for sorting out vertices outside a rectangle

Sandro Santilli strk at keybit.net
Wed Jul 17 06:16:57 PDT 2013


On Wed, Jul 17, 2013 at 12:16:25PM +0200, Postgis User wrote:
>    Hello,
>     
>    for optimization purposes I'm looking for a fast method - similar to
>    st_intersection() - that clips a (multi)polygon or a (multi)linestring by
>    a rectangle. In contrast to st_intersection() it should remove the
>    vertices being outside the rectangle without generating new vertices on
>    the edges of the rectangle.

I've been thinking about such a function for some time now.
NOT adding more vertices (noding) should be very fast.
Unfortunately the result is not always necessarely the one
that you'd expect, particularly for polygons. Imagine this case:


  +--------------+
  |  +--------+  |
  |   \      /   |
  |    \    /    |
  +--------------+
         \/

If you don't add new vertices the resulting polygon will become
a collapsed line. Things can get better by keeping the vertex
that belongs to a "crossing" edge, but then you still have other
issues with cases like this one:

    +-------------------+
    | +--------------+  |
    | |  +--------+  |  |
    | | S \  H   /   |  |
    | |    \    /    |  |
    | +--------------+  |
    +-------+  +--------+
            1  2           

You can keep vertices 1 and 2 but then if you draw a straight
line between those two you end up considering what was an hole
(H) as the actual surface.

I still think it's a useful functionality to have, but it takes
a clear definition of what needs to be done in which case.

Another case (if you want to import these for further study):

    +-------------------+
    | +--------------+  |
    | |              |  |
    | |              |  |
    | |              |  |
    | +----clipper---+  |
    +-------------------+

The outer polygon is clipped by the inner one: no way to obtain
a surface without adding vertices to the original geometry

--strk;


More information about the postgis-users mailing list