Re: For Loop in PostGIS

From: "Obe, Regina" <robe(dot)dnd(at)cityofboston(dot)gov>
To: "Bryan Manuel" <iceviper73(at)hotmail(dot)com>, <pgsql-novice(at)postgresql(dot)org>
Subject: Re: For Loop in PostGIS
Date: 2007-12-05 15:24:17
Message-ID: 53F9CF533E1AA14EA1F8C5C08ABC08D202E00E8C@ZDND.DND.boston.cob
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I did some work to deal with this very issue. Take a look at this and
hopefully you will find it useful.

http://www.bostongis.com/PrinterFriendly.aspx?content_name=postgis_neare
st_neighbor_generic
<blocked::http://www.bostongis.com/PrinterFriendly.aspx?content_name=pos
tgis_nearest_neighbor_generic>

Hope that helps,
Regina

________________________________

From: pgsql-novice-owner(at)postgresql(dot)org
[mailto:pgsql-novice-owner(at)postgresql(dot)org] On Behalf Of Bryan Manuel
Sent: Tuesday, December 04, 2007 11:48 PM
To: pgsql-novice(at)postgresql(dot)org
Subject: [NOVICE] For Loop in PostGIS

I am new to postgresql and I'm working with two tables, both having a
geometry for postGIS. What I am trying to do is get the five nearest
people from one list for every person in the second. I was trying to do
this in a for loop - all I'm trying to do for now is display the 5
people for each person in the one list.

This code works as a command line argument to psql, and correctly finds
five people for one query:

select lastname, city from eng_alumni order by ST_distance(point_geom,
(select the_geom from points where text = 'Smith')) asc limit 5;

I tried to follow a for loop using the documentation, but it is not
working. This seems like something that a for loop would work well for,
at least in other languages that I have learned. Here is the code that
I tried (running from a command line)

create table temp;
FOR temp IN SELECT text, the_geom FROM points ORDER BY text LOOP
select lastname, latitude, longitude from eng_alumni order by
ST_distance(point_geom, (select the_geom from temp)) asc limit 5;
END LOOP;

Any help would be greatly appreciated.

Thanks,

Bryan Manuel

________________________________

HO HO HO, if you've been nice this year, email Santa! Visit asksanta.ca
to learn more! <http://asksanta.ca/?icid=SANTAENCA005>

-----------------------------------------
The substance of this message, including any attachments, may be
confidential, legally privileged and/or exempt from disclosure
pursuant to Massachusetts law. It is intended
solely for the addressee. If you received this in error, please
contact the sender and delete the material from any computer.

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Brad Nicholson 2007-12-06 14:38:50 Re: Vacuum Problem
Previous Message Cedric BUSCHINI 2007-12-05 10:04:46 Re: Vacuum Problem