ジオメトリ演算の挙動、同一座標点


ジオメトリ演算時には同一地点がある場合レコードと紐づけない限り統合されるので注意

DECLARE @TEST1 TABLE 
(
 ID INT PRIMARY KEY,
 Shape GEOMETRY NOT NULL
);

INSERT 
 @TEST1
 (ID, Shape)
VALUES
 (1, GEOMETRY::Point(10,10,0));

INSERT 
 @TEST1
 (ID, Shape)
VALUES
 (2, GEOMETRY::Point(10,10,0));

--同一点の時はUnion時に統合される。
SELECT
  GEOMETRY::UnionAggregate(Shape).STNumPoints() AS UNI
 ,GEOMETRY::CollectionAggregate(Shape).STNumPoints() AS COL
FROM
 @TEST1

DECLARE @TEST2 TABLE 
(
 ID INT PRIMARY KEY,
 Shape GEOMETRY NOT NULL
);

INSERT 
 @TEST2
 (ID, Shape)
VALUES
 (1, GEOMETRY::STGeomFromText('POLYGON ((0 0, 150 0, 150 150, 0 150, 0 0))', 0));

--インターセクションの瞬間同一点は1点に集約される。
SELECT
 T1.Shape.STIntersection(T2.Shape).STNumPoints() AS COL_PT
FROM
 (SELECT GEOMETRY::CollectionAggregate(Shape) AS Shape FROM @TEST1) AS T1,
 @TEST2 T2

SELECT
 T2.Shape.STIntersection(T1.Shape).STNumPoints() AS COL_PT2
FROM
 (SELECT GEOMETRY::CollectionAggregate(Shape) AS Shape FROM @TEST1) AS T1,
 @TEST2 T2

INSERT 
 @TEST1
 (ID, Shape)
VALUES
 (3, GEOMETRY::Point(-10,-10,0));

INSERT 
 @TEST1
 (ID, Shape)
VALUES
 (4, GEOMETRY::Point(-10,-10,0));

--異なるジオメトリインスタンスでも1点に集約される
SELECT
 --T1.Shape.STNumPoints() -
 T1.Shape.STDifference(T2.Shape).STNumPoints() AS DIF_PT
FROM
 (SELECT GEOMETRY::CollectionAggregate(Shape) AS Shape FROM @TEST1) AS T1,
 @TEST2 T2
カテゴリー: 開発 タグ: パーマリンク