I want to evaluate land distribution and concentration regarding to road network. Specificly, I'm trying to calculate the median distance between a shape of roads (multilinestring) and a shape of polygons (polygon) which will "split" the total polygon area in two. That is more or less a geographic median regarding a set of references geometries.
As I absolutly have no idea how to proceed, I tried some alternative approach. I first calculate the nearest neighbor between each polygon centroid and road network and the minimal distance between those two. Then I calculate the median of those distances.
WITH nearest_distances AS (SELECT DISTINCT ON (polygons.id) polygons.id, roads.gid, ST_Distance(ST_PointOnSurface(geom), roads.geom) as distance FROM polygons, roads ORDER BY polygons.id, ST_Distance(ST_PointOnSurface(geom), roads.geom), roads.gid ) SELECT percentile_const(0.5) WITHIN GROUP (ORDER BY nearest_distances.distance) FROM nearest_distances;
I a second time, I cross-check my median result with a query giving the area of polygons covered by a buffer on road network set on the result of the median.
SELECT ST_Area(ST_Union(ST_Intersection(polygons.geom, ST_Buffer(road.geom, 220)))) FROM polygons, roads;
This is totally experimental as I needed quick estimation but I wonder if there any cleaner way to perform this. Idealy, I would split my polygons along a median line dividing polygon surface in two parts regarding the road network.