views:

68

answers:

2

Hi All,

I am struggling finding an efficient way to find a distance between a Point that intersects a polygon and the border of that polygon. I was able to use the STDistance comparing the point to every point that made up the polygon but that is taking a lot of time. Using SPatial indexed wasn't much helpful because the STDistance is not part of any constraint and even when I did put the constraint, the index didn't help much.

I appreciate any feedback.

Thanks.

+1  A: 

Try the "expanding box model" - your search grows until it finds the nearest point.

Check out a variety of solutions and more explanations here: http://blogs.msdn.com/isaac/archive/2008/10/23/nearest-neighbors.aspx

geographika
+1  A: 

Since you want to find the distance to the border, you can query for the distance to the exterior ring of the polygon, which is defined as a linestring.

select @polygon.STExteriorRing().STDistance(@point)

stevehem