# PostGIS - Finding most remote point using ST_MaximumInscribedCircle?

I have a database of points coordinates taken from OSM. My geometry column is called `wkb_geometry`. I am trying to find the most remote point (by distance to the next nearest point). I was hoping to use the new `ST_MaximumInscribedCircle` function and then order by radius to find the most remote point. Below is the code I have so far. It runs but returns `0` for the radius. The example on the PostGIS website is for a polygon.

``````SELECT
osm_id, name,
geom.center,
geom.nearest
FROM
australian_points AS t,
LATERAL ST_MaximumInscribedCircle(t.wkb_geometry) AS geom
;
``````
• The table `australian_points` is a points layer not a polygon layer Commented Sep 1, 2022 at 13:40
• You need to collect the points into a `MULTIPOINT` using `ST_MaximumInscribedCircle( ST_Collect( t.wkb_geometry))` Commented Sep 1, 2022 at 15:31
• It's probably more efficient (and more correct?) to find the nearest point to each point with a NN query, and then take the one with maximum distance. Commented Sep 1, 2022 at 15:32

With an index structure supporting (spatial) (K)NN searches like the PostGIS `GIST` extension, this is trivially executed with

``````SELECT
*
FROM (
SELECT
p1.id,
p1.geom,
ST_Distance(p1.geom, pn.geom) AS dist
FROM
australian_points AS p1
CROSS JOIN LATERAL (
SELECT
p2.geom
FROM
australian_points AS p2
WHERE
p1.id <> p2.id
ORDER BY
p1.geom <-> p2.geom
LIMIT
1
) AS pn
) q
ORDER BY
dist DESC
LIMIT
1
;
``````

Here

• we find the nearest neighbor to each point using a (K)NN query (a `CROSS JOIN LATERAL` "loop" in conjunction with the index-optimized `<->` distance operator)
• and then filter for the highest `dist` value (`ORDER BY dist DESC LIMIT 1`)

If you need true geoidal surface distances, you'd want to implement a `CAST` to `GEOGRAPHY`; change the query to use

• `ST_Distance(p1.geom::GEOGRAPHY, p2.geom::GEOGRAPHY)` (spheroidal calculation)
• `p1.geom::GEOGRAPHY <-> p2.geom::GEOGRAPHY` (spherical calculation) respectively.

(Note that a `CAST` to `GEOGRAPHY` is possible only for geographic reference systems!)

But beware:

This can only ever be as performant with an appropriate index on the `CAST`, e.g.

``````CREATE INDEX
ON australian_points
USING ( (geom::GEOGRAPHY) )
;
``````