[postgis-users] RE : return points where line intersects polys

Francois Hugues hugues.francois at irstea.fr
Thu May 10 11:34:53 PDT 2012


Hello,

I'm not totally sure of that but you could try this way:
1. Keep points from st_intersection
2. Extract points from lines using st_startpoint / endpoint (and add an attribut to identify which kind of point it is )
3. Dump your geometrycollection and re-do the two first steps to get just points
4. Make an union of all these results to have just one table

Hugues 


-------- Message d'origine--------
De: postgis-users-bounces at postgis.refractions.net de la part de Puneet Kishor
Date: jeu. 10/05/2012 17:21
À: PostGIS Users Discussion
Objet : Re: [postgis-users] return points where line intersects polys
 

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

_______________________________________________
postgis-users mailing list
postgis-users at postgis.refractions.net
http://postgis.refractions.net/mailman/listinfo/postgis-users

-------------- next part --------------
A non-text attachment was scrubbed...
Name: winmail.dat
Type: application/ms-tnef
Size: 4327 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20120510/e7ad4a6d/attachment.bin>


More information about the postgis-users mailing list