別の SqlGeometry オブジェクトから SqlGeometry オブジェクト上の最近接点を取得するにはどうすればよいですか?
-
21-09-2019 - |
質問
ラインとポリゴンのオブジェクト (SqlGeometry タイプ) とポイント オブジェクト (SqlGeometry タイプ) のセットがあります。与えられた点オブジェクトから各線上で最も近い点を見つけるにはどうすればよいでしょうか?この操作を実行するための API はありますか?
解決
私は、これがSQL Server 2008で直接可能であるかどうかわからないんだけどます:
そのスレッドで提案回避策はあります:
declare @g geometry = 'LINESTRING(0 0, 10 10)'
declare @h geometry = 'POINT(0 10)'
select @h.STBuffer(@h.STDistance(@g)).STIntersection(@g).ToString()
そうしないと、あなたのデータベースからジオメトリを読んで、別々の空間的なライブラリを使用するスクリプトを記述する必要があります。
他のヒント
ここでSqlGeometryとC#を使用して可能な解決策を提示したサンプル、何のSQL Serverが必要とされない。
using System;
using Microsoft.SqlServer.Types;
namespace MySqlGeometryTest
{
class ReportNearestPointTest
{
static void ReportNearestPoint(string wktPoint, string wktGeom)
{
SqlGeometry point = SqlGeometry.Parse(wktPoint);
SqlGeometry geom = SqlGeometry.Parse(wktGeom);
double distance = point.STDistance(geom).Value;
SqlGeometry pointBuffer = point.STBuffer(distance);
SqlGeometry pointResult = pointBuffer.STIntersection(geom);
string wktResult = new string(pointResult.STAsText().Value);
Console.WriteLine(wktResult);
}
static void Main(string[] args)
{
ReportNearestPoint("POINT(10 10)", "MULTIPOINT (80 70, 20 20, 200 170, 140 120)");
ReportNearestPoint("POINT(110 200)", "LINESTRING (90 80, 160 150, 300 150, 340 150, 340 240)");
ReportNearestPoint("POINT(0 0)", "POLYGON((10 20, 10 10, 20 10, 20 20, 10 20))");
ReportNearestPoint("POINT(70 170)", "POLYGON ((110 230, 80 160, 20 160, 20 20, 200 20, 200 160, 140 160, 110 230))");
}
}
}
プログラムの出力:
POINT (20 20)
POINT (160 150)
POINT (10 10)
POINT (70 160)
ライン上の最も近い点 (ノードとも呼ばれる) を実際に見つけたい場合は、各ラインを同じ lineid を持つ点のセットに変えることができます。次に、最も近いものをクエリして距離を計算します。
代わりに、点から最も近い線までの距離を計算しようとしている場合 - st distancehttp://msdn.microsoft.com/en-us/library/bb933808.aspx他の回答が解決している問題は、where 句に何を入れるかということだと思いますが、st distance を使用して、それ以上の気にしない距離を指定することもできます。
ここで pointGeom.st distance(lineGeom) < "気になる距離"
所属していません StackOverflow