I have two tables both have point geometry with SRID 4326 (WGS84) I need to find the nearest point in 1 table to every point in another table
PostGIS KNN search is written
t1.geometry <-> t2.geometry AS distance;
as I'm using WGS84 distance is in degrees I'd like distance to be in meters
https://postgis.net/docs/ST_DistanceSphere.html takes two points and calculates the distance between them like
SELECT round(CAST(ST_DistanceSphere(t1.geometry, t2.geometry ) As numeric),2) As distance
How do I combine the two functions? This errors
round(CAST(ST_DistanceSphere(t1.geometry <-> t2.geometry ) As numeric),2) As dist
ERROR: function st_distancesphere(double precision) does not exist
PostGIS version: 3.0
t1.geog <-> t2.geog? – Tony Sansom Oct 07 '20 at 13:44create index geogidx ON mytable USING gist(geography(geom));). If you need to use the distances in meters in several places, I would convert the column to geography. If you need it just once, I would keep the geometry and add an index on the cast. – JGH Oct 07 '20 at 13:59