[postgis-users] return points where line intersects polys

Stephen Woodbridge woodbri at swoodbridge.com
Mon May 7 13:44:20 PDT 2012


Hi Puneet,

First if you intersect a line with a polygon you should expect to get back:

1. a line if it crosses the polygon or lies alont an edge of it
2. or a point if it touches a vertex
3. or a collection of these if there are multiple instances along the line

The results are always returned in a GEOMETRYCOLLECTION.

Also you should expect to get one result row for every row in  TABLE

If you only want, results for rows the intersect then add a WHERE clause

SELECT 
ST_AsText(ST_Intersection(ST_GeomFromText('LINESTRING(<p0>,<p2>)', 
4326), the_geom))
   FROM table
  WHERE ST_Intersects(ST_GeomFromText('LINESTRING(<p0>,<p2>)', 4326), 
the_geom);

As far as the points you want, you should probably intersect the 
polygon's outer ring with your line, or extract the points from the 
start and end of the line. You also have to deal with the case where the 
line lies along an edge.

-Steve

On 5/7/2012 1:36 PM, Puneet Kishor wrote:
> Given a line, I want to get the points at which it intersects a polygon dataset.
>
>                   +--------------+
>                   |              |
>          +--------+              |
>          |    a   |      b       |
>      ====o========o==============o=======
>      p0  |p1      |p2            |p3     pn
>          +--------+              |
>                   |              |
>                   |              |
>                   +--------------+
>
> In the figure above, I want to get the following
>
>      poly_id point1  point2
>      ------- ------  ------
>      a       p1      p2
>      b       p2      p3
>
>      SELECT ST_AsText(ST_Intersection(ST_GeomFromText('LINESTRING(<p0>,<p2>)', 4326), the_geom))
>      FROM table;
>
> But I back N 'GEOMETRYCOLLECTION EMPTY' where N = number of rows in the 'table'. From what I understand, that indicates "the geometries do not share any space (are disjoint)". But, I know that is not correct. So, my query is formulated incorrectly. What am I doing wrong?
>
>
> --
> Puneet Kishor
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users




More information about the postgis-users mailing list