# Interpolating point to nearest polygons to compute street width in posgis

I am trying to calculate the width of streets (line.shp) in postgis using reference point (ref_point.shp) (yellow point features) and building polygons (building.shp). The red point features are the interpolated points within 30 meter buffer. My initial approach: To select all buildings (using reference point) in a buffer of 30 meter (let say) and then compute the width of the streets using interpolated points opposite to the reference points only.

I used ST_ClosestPoint() to interpolate the reference point to the nearest edge of building polygons. For every reference point, I wanted to the interpolate the reference point to opposite ends only (like the one shown in green rectangle) so that I could use ST_Distance() to compute the distance between the interpolated points along opposite building polygons.

The problem is: When I used ST_DWithin(), the building next to the green rectangle is also in the 30m buffer thereby generating unwanted interpolated points along this building polygon. The desired scenario is explained in this image below in the green rectangle.

What I have tried so far is shown in the following code:

Select ST_ClosestPoint(bu, pt)
From
(Select
ref_point.geom As pt,
building.geom As bu,
building.gid As id
From ref_point, building
Where ST_DWithin(ref_point.geom, building.geom, 30.0)
Order By id
) As foo;


Is it appropriate to use ST_DWithin() here? Can someone please guide me to more better approach to do this?

• I don't completely understand what you mean by "The problem is the point is being interpolated to other undesired polygons". Could you clarify? – John Powell Apr 12 '16 at 18:43
• @Barca: I have edited the question and have added more explanation. I want to interpolate the reference points to the opposite building polygons only (like the one shown in green rectangle above). – khajlk Apr 12 '16 at 20:09
• Try the PostGIS function postgis.net/docs/ST_ShortestLine.html – Cyril May 25 '18 at 13:41