0
我寫了這個基本的代碼,這首先提取從多面對應於內圓和外圓的多邊形,然後將特定的LineString:可靠的方式來確定是否線段形式是多邊形的內圓
DECLARE @SomeMultiPolygon GEOGRAPHY = 'MULTIPOLYGON (
((-2 -2, 2 -2, 2 2, -2 2, -2 -2), (-1 -0.5, 0 -0.5, 0 -1.5, -1 -1.5, -1 -0.5), (0 1, 1 1, 1 0, 0 0, 0 1))
, ((-4 -3, -4 -5, 0 -5, 0 -3, -4 -3)))';
SET @SomeMultiPolygon.STSrid = 4326;
DECLARE @i int = 1
DECLARE @Results TABLE (Id INT IDENTITY(1,1), PolygonData GEOGRAPHY)
WHILE @i <= @SomeMultiPolygon.STNumGeometries()
BEGIN
INSERT INTO @Results VALUES (@SomeMultiPolygon.STGeometryN(@i))
SET @i = @i + 1
END
SELECT
Id,
PolygonData.STGeometryType(),
PolygonData,
PolygonData.STAsText() AS PolygonWkt,
PolygonData.NumRings() AS NumberOfRings
FROM @Results
IF OBJECT_ID('tempdb..#Temp') IS NOT NULL
DROP TABLE #Temp
CREATE TABLE #Temp
(
ParentId INT,
SubPolygon GEOGRAPHY
)
DECLARE @Id INT, @InnerLoop INT, @SubPolygon GEOGRAPHY;
SELECT @Id = MAX(Id) FROM @Results
WHILE @Id >= 1
BEGIN
SELECT @InnerLoop = PolygonData.NumRings() FROM @Results WHERE Id = @Id
WHILE @InnerLoop > 0
BEGIN
SELECT @SubPolygon = PolygonData.RingN(@InnerLoop) FROM @Results WHERE Id = @Id
INSERT INTO #Temp
(ParentId, SubPolygon)
VALUES (@Id,
@SubPolygon
)
SET @InnerLoop = @InnerLoop - 1;
END
SET @Id = @Id - 1
END
SELECT
*,
SubPolygon.STAsText() AS SubPolygonText,
SubPolygon.EnvelopeAngle() AS EnvelopeAngle
FROM #Temp
我是正確假設,如果EnvelopeAngle小於1度,LineString對應於一個內圓?
順便說一句,有沒有一個基於集合的方法來實現上述 - 我不是真正的TSQL循環粉絲。
PS:
這是上面的例子中的可視化:
謝謝。太好了,明天再來看看。 – cs0815