[postgis-users] nested query to make adjacency list?

Jeff D. Hamann jeff.hamann at forestinformatics.com
Tue Dec 20 00:05:14 PST 2005


I've been in the process of moving an application that uses Arc/Info files 
to one that uses PostGIS completely! I need to generate an adjacency 
list/matrix and have been able perform the query for a single polygon,

-- build a temp table of the first polygon, only.
select * into table first_one from test where gid = 1;

-- now create a adjacency list for the first polygon
select
 first_one.gid as gid,
 first_one.Standid as stid,
 test.gid as adj_gid,
 test.Standid
from
 test,
 first_one
where
 touches( first_one.the_geom, test.the_geom );

-- boo-yah!

 gid |  stid  | adj_gid | standid
-----+--------+---------+---------
   1 | 010101 |       2 | 010115
   1 | 010101 |       6 | 010103
   1 | 010101 |       7 | 010105
   1 | 010101 |       8 | 010113
(4 rows)

This yields the correct results.

Is it possible to nest this query so that I can create this for every 
polygon all at once?

Jeff.








More information about the postgis-users mailing list