Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'd like to select some neighbor polygons with ST_Touches. Therefore I found the following statement:

SELECT b.name
FROM layera as a
JOIN layera as b
  ON ST_Touches((SELECT a.geom FROM layera as a WHERE a.id = 5124),b.geom)
GROUP BY b.name

With this I get all the neighbor polygons of the polygon with the id '5124'. But now I want to call this function with a list of arguments. See the example statment below:

SELECT b.name
FROM layera as a
JOIN layera as b
  ON ST_Touches((SELECT a.geom FROM layera as a WHERE a.id > 5000),b.geom)
GROUP BY b.name

(SELECT a.geom FROM layera as a WHERE a.id > 5000 returns lets say 100 results)

I know that this won't work because ST_Touches works for only two arguments. But this should show what I'd like to do. How is it possible to insert all the results of a SELECT-statement into this ST_Touches function?

Thanks for any suggestions. =)

EDIT:

Ok, I just found out that I get the same result set with this statement:

SELECT layera.name
FROM layera
WHERE ST_Touches(layera.geom,(SELECT layera.geom FROM layera WHERE layera.nr = 5134)) 

Anyway, the problem isn't solved. =(

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

If I understand you right, you have just complicated the syntax a little:

SELECT a.nr, b.nr FROM
layera AS a INNER JOIN layera AS b 
ON ST_Touches(a.geom, b.geom) 
WHEREa.nr!=b.nr AND b.nr < 5000;

Then you will get a list of all combinations between the first 4999 numbers and the rest.

share|improve this answer
    
Thank you so much. This solved my problem. I can actually remove the WHERE a.nr!=b.nr because it returns the same result set as with it. –  Chronnie Jun 3 '13 at 14:36
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.