Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having problems identifying intersections on a layer of linework, the lines are representative of contacts and faults (geological rock formations). I am trying to select where there are connected line segments of faults and contacts because it is geologically unlikely for a fault to end and a contact to begin immediately after it (thus might be an error in the layer). So I only need to select intersections where there are 2 lines intersecting.

Here is the query I have so far I stole most of it from this thread:

Identifying road intersections using PostGIS

CREATE TABLE contacts_st_touching_faults as

SELECT ST_Intersection(a.the_geom, b.the_geom),
 Count(Distinct a.gid) = 2

intersect_linejoin_geolines as a,
intersect_linejoin_geolines as b

WHERE ST_Touches(a.the_geom, b.the_geom)

AND a.f_class = 'Contact'

AND b.f_class = 'Fault'

AND a.gid != b.gid

GROUP BY ST_Intersection(a.the_geom, b.the_geom)

When I run this and populate the geometry, I get coordinates with more than 2 intersections (T intersections), but I do only get intersections where contacts and faults are intersecting which is what I want. However, I only want it where there is an intersection between two lines. I'm pretty sure this means leaving Count = 2, I've tried Count = 1 and that didn't work either.

Thanks for the help!!

share|improve this question
In these cases, a picture is often useful in describing what it is you're trying to figure. I can't quite get it from your description. – Paul Ramsey Apr 23 '13 at 4:53
SELECT * FROM a , b where ST_intesects(a.geom ,b.geom) AND != and ...(thsoe f_class limits) . ST_intersection return true when two geoms intersect . Does that help – simplexio Apr 23 '13 at 6:39
I'm trying to select where there is what looks like a continuous straight line, however, when you click on it you realize it is actually two segments. The first segment is a contact and the second segment is a fault. This is unlikely to occur in geology so I'm trying to select them. And I would put a picture up but it says I don't have enough reputation :(. I havn't been able to get st_intersects working either – Jenn Apr 23 '13 at 16:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.