SQL:多边形的联合 [英] SQL: Union of polygons

查看:118
本文介绍了SQL:多边形的联合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多边形的单一列几何类型的表。

I have a table with a single column of geometry type, containing polygons. How do I get the union of all the polygons in the table?

推荐答案

这对我有效:

CREATE TABLE #g (i INT IDENTITY, a geometry)
INSERT INTO #g (a)
VALUES
    (geometry::STGeomFromText(
        'POLYGON((0 0, 3 0, 3 3, 0 3, 0 0))', 0)
    ),
    (geometry::STGeomFromText(
        'POLYGON((5 2, 7 2, 7 0, 5 0, 5 2))', 0)
    )

DECLARE @g geometry
SELECT TOP 1 @g = a FROM [#g]
SELECT @g = @g.STUnion(a) FROM #g

SELECT @g

显然,当被调用的实例或操作数为空时,STUnion方法返回null,因此选择top 1 hack。

So, apparently, the STUnion method returns null when either the instance on which it's being called or the operand is null, hence the select top 1 hack.

这篇关于SQL:多边形的联合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆