In PostGIS, how can you calculate the maximum distance that one polygon is from the nearest point of another polygon?
I have two tables of polygons, 'red' and 'blue'. They can be joined by field district_code. How do you find the max distance from a red polygon to its joined blue polygon. (Distance indicated by dashed black line in image above).
The following query uses ST_MaxDistance, but this gives distance from furthest point to furthest point, not furthest point to nearest point.
select id, district_code, ST_MaxDistance(red.geometry, blue.geometry) AS max_distance
FROM red
INNER JOIN blue ON red.district_code = blue.district_code;