[postgis-users] return points where line intersects polys

Puneet Kishor punk.kish at gmail.com
Thu May 10 08:21:26 PDT 2012


On May 7, 2012, at 3:44 PM, Stephen Woodbridge wrote:

> 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);
> 
> 



Thanks... the above works well. But, now I am confused by a slightly different problem. How do I guarantee that the returned results are in the same order as the direction of the line? For example, given the line below (<p0> .. <pn>), how do I guarantee that I will get back "a, b" and not "b, a"?

Suggestions?




> -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?
>> 




More information about the postgis-users mailing list