I found a solution using the ST_Split<br>this is a bit more long to write query, but work pretty well :)<br><br>select 1, ST_AsText(<br>    ST_Difference(<br>        ST_CollectionExtract(<br>            ST_Split(<br>                ST_GeomFromText('LINESTRING(10.9 2, 11 8)'), <br>
                ST_ExteriorRing(ST_GeomFromText('POLYGON((12 2, 10 10, 20 21, 21 5, 12 2))'))<br>            ),<br>            2<br>        ),<br>        ST_Intersection(<br>            ST_CollectionExtract(<br>                ST_Split(<br>
                    ST_GeomFromText('LINESTRING(10.9 2, 11 8)'), <br>                    ST_ExteriorRing(ST_GeomFromText('POLYGON((12 2, 10 10, 20 21, 21 5, 12 2))'))<br>                ),<br>                2<br>
            ),<br>            ST_GeomFromText('POLYGON((12 2, 10 10, 20 21, 21 5, 12 2))')<br>        )<br>    )<br>)<br><br><br><br><div class="gmail_quote">2011/2/16 strk <span dir="ltr"><<a href="mailto:strk@keybit.net">strk@keybit.net</a>></span><br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div></div><div class="h5">On Wed, Feb 16, 2011 at 07:08:03PM +0100, strk wrote:<br>
> On Wed, Feb 16, 2011 at 06:47:53PM +0100, Andrea Peri wrote:<br>
> > Look this simple example<br>
> ><br>
> > the difference between the line and the same line intersected with the<br>
> > polygon is equal to the line :)<br>
> ><br>
> > select 1, ST_Difference(ST_GeomFromText('LINESTRING(10.9 2, 11<br>
> > 8)'),ST_Intersection(ST_GeomFromText('LINESTRING(10.9 2, 11 8)'),<br>
> > ST_GeomFromText('POLYGON((12 2, 10 10, 20 21, 21 5, 12 2))')))<br>
> ><br>
> > the trick is that in the intersection point between polygon and line, the<br>
> > vertex added move the line so the difference fail to<br>
> > remove the internal portion.<br>
><br>
> Ok, I think I know what's going on.<br>
> The original linestring isn't noded with the polygon boundary.<br>
> When computing the intersection, a node is added.<br>
> Such a node will NOT fall on the original line anymore, due<br>
> to precision constraints.<br>
><br>
> See this:<br>
>  CREATE TABLE a AS SELECT<br>
>    'LINESTRING(10.9 2, 11 8)'::geometry as g;<br>
>  CREATE TABLE b AS SELECT<br>
>    'POLYGON((12 2, 10 10, 20 21, 21 5, 12 2))'::geometry as g;<br>
>  CREATE TABLE c AS SELECT<br>
>    ST_Intersection(a.g, b.g) FROM a, b;<br>
>  SELECT ST_Covers(a.g, ST_StartPoint(c.g)) FROM a,c; -- false<br>
>  SELECT ST_Covers(a.g,   ST_EndPoint(c.g)) FROM a,c; -- true<br>
><br>
> What you could do is _snap_ the original line to the intersection,<br>
> or to node the input before proceeding.<br>
<br>
</div></div>For a working example:<br>
select st_covers(a.g, st_startpoint(st_snap(a.g,c.g,1e-10))) from a,c;<br>
<div><div></div><div class="h5"><br>
--strk;<br>
<br>
  ()   Free GIS & Flash consultant/developer<br>
  /\   <a href="http://strk.keybit.net/services.html" target="_blank">http://strk.keybit.net/services.html</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>-----------------<br>Andrea Peri<br>. . . . . . . . . <br>qwerty àèìòù<br>-----------------<br><br>