[postgis-users] Query to select dangling line segments

Brian Stempin brian.stempin at gmail.com
Mon Nov 29 11:54:58 PST 2010


Hi All!
I'm currently trying to write a query to do the following: I need to find
all line segments that have an end point or a start point that doesn't
overlap with everything.  Here's what I had so far:

SELECT t1.osm_id, ST_StartPoint(t1.way)
FROM "OSMData".osm_mn_data_highway_20101129_101234 t1,
"OSMData".osm_mn_data_highway_20101129_101234 t2
WHERE t1.way && t2.way
AND t1.osm_id <> t2.osm_id
AND NOT ST_Intersects(ST_StartPoint(t1.way), t2.way)
UNION
SELECT t1.osm_id, ST_EndPoint(t1.way)
FROM "OSMData".osm_mn_data_highway_20101129_101234 t1,
"OSMData".osm_mn_data_highway_20101129_101234 t2
WHERE t1.way && t2.way
AND t1.osm_id <> t2.osm_id
AND NOT ST_Intersects(ST_EndPoint(t1.way), t2.way)

way = GEOMETRY
osm_id = INTEGER (id)

(I'm working on some OpenStreetMap data in case you're curious)
This query doesn't give me what I want.  If there exists a t2 within t1's
bounding box that doesn't intersect t1's start/end point, then it gets
included into the list (false positives).  I want to select rows who's
geometry's start/end point does not intersect *anything*.  I have a feeling
that I should be using some sort of grouping operator, but I'm lost.

Any help would be greatly appreciated.

Brian Stempin
http://brianstempin.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20101129/90a744f8/attachment.html>


More information about the postgis-users mailing list