I'm using PostGIS and OpenStreetMap, I tried to assign some bars to the nearest building from themselves I based myself on an example, see: link You can see below picture that resulted from below script. Where its circled in red the location of each bar is incorrect. Its not showing what I need to see. The selected location of the bar is not in front of it.
SELECT DISTINCT ON (b.osm_id) b.osm_id as osm_bar, a.osm_id as osm_building, ST_Distance(a.way, b.way) as distance FROM buildings a, bar_not_assigned b WHERE ST_DWithin(a.way, b.way, 10) ORDER BY b.osm_id, a.osm_id, ST_Distance(a.way, b.way);
When i used the script in this post link I got this result:
select poly.osm_id from (select osm_id, way from buildings) poly cross join lateral (select osm_id, way from bar_not_assigned pt where st_dwithin(pt.way, poly.way, 10) order by pt.way <-> poly.way limit 1) pts;
I changed limit to 1 to have one bulding for each bar, but does not work.