Using PostgreSQL-PostGIS for coordinates -


i'm trying create database storing coordinates

lets x has: latitude 20°20’20.00’’ , longitude 20°20’20.00’’e , 1 mile range.

y has: latitude 20°21’21.00 , longitude 20°21’21.00’’

i want know whether y location lies within x range.

i've been trying days find way manage that; came across quad tree, k-d tree, not find way represent in database.

i stumbled on postgis don't know how create , manage simple latitude longitude interaction whit it.

the first thing want learn more postgis.

after installed postgis extension, can use geography type purposes:

create table locations (   id      serial primary key,   loc     geography(point, 4326), -- see postgis docs type modifiers   rng     double precision, -- in miles, postgis uses km   ... );  create index locations_geo on locations using gist (loc); 

your lat,long pairs go loc column geography type; postgis spatial analysis data. can find points within range of x point (say, id=12) follows:

select src.id src, src.rng, near.* locations near join locations src on st_dwithin(src.location, near.location, src.rng * 0.6215) -- miles km src.id = 12; 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -