Right now I have a data base with PostGIS. Several of the data sets contain different locations at latitude longitude points. I will be doing several queries based at different latitude longitude points, I need to find the closest locations at each point as well as all the points within a certain number of meters. Right now I was just sorting all the data by closest to the lat/lon point that I was querying, so:
SELECT rest.station_id FROM rest ORDER BY rest.geom <-> ST_SetSRID(ST_MakePoint('%(lat)s',' (lon)s')::geometry, 4326) LIMIT 1
where the lat lon variables are what I am querying.
Is there a way to do this better so that I don't have to sort each time I do a query?