Re: locating cities within a radius of another

From: Paul Ramsey <pramsey(at)opengeo(dot)org>
To: Andy Colson <andy(at)squeakycode(dot)net>
Cc: Geoffrey <lists(at)serioustechnology(dot)com>, PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: locating cities within a radius of another
Date: 2010-07-21 17:45:18
Message-ID: AANLkTikcNchWafkemGRlksHgb3AEmNSDwEqmuyRBqU4D@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

create table cities (
geog geography,
name varchar,
id integer primary key
);

insert into cities
select
Geography(ST_SetSRID(ST_MakePoint(lon, lat),4326)) as geog,
name, id
from mytable;

create index cities_gix on cities using gist ( geog );

select st_distance(a.geog, b.geog), b.name
from cities a, cities b
where a.name = 'New York';

On Wed, Jul 21, 2010 at 8:10 AM, Andy Colson <andy(at)squeakycode(dot)net> wrote:
> On 7/21/2010 8:01 AM, Geoffrey wrote:
>>
>> We need to locate all cities within a certain distance of a single city.
>> We have longitude and latitude data for all cities. I was thinking
>> postGIS was a viable solution, but I don't see a way to use our existing
>> data via postGIS.
>>
>> Is postGIS a viable solution, or should I be looking at a different
>> approach? Thanks for any suggestions or RTFM pointers.
>>
>
> I'd say PostGIS is a great option.
>
> Did you try:
>
> http://postgis.refractions.net/documentation/manual-1.5/ST_Distance_Sphere.html
>
>
> or do you mean, how do I turn my lat, long columns into a geomentry column?
>
>
> -Andy
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Pierre Racine 2010-07-21 19:17:08 Re: locating cities within a radius of another
Previous Message Chris Browne 2010-07-21 16:41:29 Re: pg_dump-restore concurrency