May 2017
Beginner to intermediate
328 pages
7h 17m
English
This is a key feature for almost any location-based application: given a current location, it will return the nearest feature (or list of nearest features, ordered by distance).
The naive approach to this problem would be to query the table ordering by ST_Distance. Let's find the five earthquakes closest to San Juan:
SELECT * FROM data_import.earthquakes_subset_with_geomORDER BY ST_Distance(geom::geography, ST_SetSRID(ST_MakePoint(-66.11,18.46),4326)::geography)LIMIT 5; id | time | depth | mag | magtype | place | geom ------------+--------------------------+-------+-----+---------+---------------------------------------------------+---------------------------------------------------- pr16281009 | 2016-10-08 01:08:46.4+02 ...Read now
Unlock full access