如何从另一个 SqlGeometry 对象获取 SqlGeometry 对象上的最近点?
我有一组线和多边形对象(SqlGeometry 类型)和一个点对象(SqlGeometry 类型)。我们如何找到每条线上距给定点对象最近的点?有没有API可以实现这个操作?
I have a set of line and polygon object (SqlGeometry type) and a point object (SqlGeometry type). How can we find the the nearest point on each line from the given point object? Are there any API for doing this operation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这里的示例展示了使用 SqlGeometry 和 C# 的可能解决方案,不需要 SQL Server:
程序输出:
Here a sample presenting possible solution using SqlGeometry and C#, no SQL Server is required:
The program output:
我不确定这是否可以直接在 SQL Server 2008 中实现:
http://social.msdn.microsoft.com/Forums/en/sqlspatial/thread/cb094fb8-07ba-4219-8d3d-572874c271b5
该线程中建议的解决方法是:
否则您必须编写一个脚本来从数据库中读取几何图形并使用单独的空间库。
I'm not sure if this is possible directly in SQL Server 2008:
http://social.msdn.microsoft.com/Forums/en/sqlspatial/thread/cb094fb8-07ba-4219-8d3d-572874c271b5
The workaround suggested in that thread is:
Otherwise you would have to write a script to read the geometry from your database and use separate spatial libraries.
如果您有兴趣实际找到线上最近的点(也称为节点),您可以将每条线变成一组具有相同 lineid 的点。然后查询最近的并计算距离。
相反,如果您尝试计算从一个点到最近的线的距离 - stdistance
http://msdn.microsoft.com/en-us/library/bb933808。 ASPX
我想其他答案解决的问题是在 where 子句中放入什么,尽管您可以使用 stdistance 来指定您不关心的距离,例如
Where pointGeom.stdistance(lineGeom) Where pointGeom.stdistance(lineGeom) < “你关心的距离”
If you are interested in actually finding the nearest point on the line (otherwise called a node) you can turn each line into a set of points with the same lineid. Then query for the closest and calc the distance.
If instead you are trying to calc the distance from a point to the nearest line - stdistance
http://msdn.microsoft.com/en-us/library/bb933808.aspx
I guess the problem that the other answer addresses is what to put in your where clause though you could use stdistance to specify a distance above which you don't care such as
Where pointGeom.stdistance(lineGeom) < "distance you care about"