How to find the closest segment to a point

المشرف العام

Administrator
طاقم الإدارة
I am trying to find the closest road segment to point that i have and return an attribute that is the closest segment to the given points. I know in POSTGIS I need to us ST_ClosestPoint, St_distance and min function and I keep having syntax errors. I am not sure where I am messing up but any help would ne amazing.

So far my code looks like WITH closest_segment As ) SELECT ST_ClosestPoint(ST_GeogFromText('POINT(-122.206111 47.983056)')::GEOMETRY,
shape::GEOMETRY)AS segment_location --shape is the geography WKB

FROM public.road_segments) RETURNING closest_segmentWITH new_segment AS) SELECT MiN(ST_Distance(closest_segment::GEOM,ST_GeogFromText('POINT(-122.206111 47.983056)')::GEOMETRY) FROM closest_segment) RETURNING closest_segmentmy knowledge of POSTGIS and codes in it is very limited and I hope someone can help me.

Thank you



أكثر...
 
أعلى