I have a LineString
describing a path, and a Point
, which is not on the line. I am trying to find the closest point to my POI on the line.
I figured I'd get the ShortestLineTo between the two objects, and then intersect it with the line to find that point. It doesn't seem to work - the line does not intersect with the shortest line. I suspect it's because of different rounding along the way.
here is my code:
declare @section_a geography;
declare @poi geography;
declare @shortest_line geography;
declare @intersection geography;
set @section_a = geography::STGeomFromText('LINESTRING (-116.4703362 32.6030246 0 1880.19645062108, -116.4703371 32.603065 0 1884.67750272083, -116.4703262 32.6031078 0 1889.53294225379, -116.4702971 32.603152 0 1895.14435545006, -116.4702939 32.603177 0 1897.9330160081, -116.4703446 32.6035651 0 1941.23463376485)', 4326);
set @poi = geography::STGeomFromText('POINT (-116.470132 32.603062)', 4326);
set @shortest_line = @poi.ShortestLineTo(@section_a);
set @intersection = @shortest_line.STIntersection(@section_a);
select'section a' name, @section_a data, @section_a.ToString() toString
union all
select 'poi', @poi.STBuffer(1), @poi.ToString()
union all
select 'shortest line', @shortest_line, @shortest_line.ToString()
union all
select 'end point', @intersection.STBuffer(1), @intersection.ToString();
And my results show the intersection as an empty geometry collection. When I try and add an STBuffer
around the shortest line, it only creates a LineString
as the intersection, and I want to get the intersecting point. What am I missing?
Aucun commentaire:
Enregistrer un commentaire