From PostgreSQL to Postgis -


i've got trouble here. have 2 tables in postgres columns 'lat' , 'lon'. how convert them postgis geom(point) , calculate distance between points? i'm newbie, me please :)

in general, see answer (or this one).

-- add spatial column epsg:4326 (wgs84) alter table some_table add column geom geometry(point, 4326);  -- use coordinates create point geometries update some_table set   geom = st_setsrid(st_makepoint(lon, lat), 4326); 

then calculate distances of each point point, use this:

select t1.gid, t2.gid, st_distance(t1.geom, t2.geom) some_table t1, some_table t2 t1.gid > t2.gid; 

be aware distance cartesian, based on degrees, non-sense. consider either using geography type (instead of geometry) distance result in metres, or use st_distance_sphere or st_distance_spheroid geometry.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -