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?