CSV, COPY ( PostgreSQL ) \copy psql, . Q + A SO , .
, , longitude latitude PostGIS geography, geography(POINT, 4326) ( gps) :
UPDATE my_table SET gps = ST_SetSRID(ST_MakePoint(longitude, latitude), 4326);
Add an index to this column to provide an efficient search:
CREATE INDEX my_table_gps ON my_table USING gist(gps);
Now you can find lines within 5 miles of a given location, for example. (-72.657, 42.0657)as below:
SELECT *
FROM my_table
WHERE ST_DWithin(gps, ST_SetSRID(ST_MakePoint(-72.657, 42.0657), 4326), 5 * 1609);
Note that ST_DWithin()the column geographywill work in meters, so you need to multiply the radius in miles by 1.609 meters per mile.
source
share