[GIS] PostGIS : Does the <-> operator work for Geography

geography-data-typepostgispostgresql

With the recent PostgreSQL/PostGIS version, you can now use the <-> operator to find the nearest rows to a point:
Indexed Nearest Neighbour Search in PostGIS

According to my tests, this query:

SELECT name, gid
FROM geonames
ORDER BY geom <-> st_setsrid(st_makepoint(-90,40),4326)
LIMIT 10;

is the same precision and a bit slower than if I use the PostgreSQL Point type.

I would like to use this new operator with the Geography type to do better calculus on a spheroid. Is this possible?

Best Answer

No, the <-> operator is not defined on geography. You can use the geometry operator and a cast to geography on the resultants

ST_Distance(geom::geography, ST_GeogFromText(''))

to get the final distances, but potentially if your objects are over the poles or dateline or in the far north the initial geometry ordering of <-> won't be correct so things won't work perfectly.