I'm using PostGIS/Tiger for geocoding I am trying to find the first/nearest tract for a given long/lat, and while this query works great every time, it takes anywhere from 2-5 seconds to complete.
Any opportunities to make it faster? I added an index on the tract table's "the_geom" column (it looks like I have two indexes, a gist and a regular)
Here is my query:
SELECT tract_id, intptlat, intptlon
FROM tract
WHERE ST_Distance_Sphere(ST_Point(ST_X(ST_Centroid(the_geom)),
ST_Y(ST_Centroid(the_geom))),
(ST_MakePoint(-118.2436849, 34.0522342))
) <= 650
LIMIT 1
I suspect the way I'm handling the distance might be the issue in the where clause, but I'm a bit stuck.
the_geomis in the EPSG:4326 projection (lat/lon). If not, you have to find out which one and add a transform to the point. – tilt Jul 26 '17 at 19:42SELECT ST_Srid(the_geom) FROM tract LIMIT 1? – tilt Jul 26 '17 at 19:48