联合 SQL Server 表中的所有几何图形,例如 Postgres 中的 GeomUnion

发布于 2024-09-10 08:39:38 字数 537 浏览 5 评论 0原文

预先澄清一下:我说的是联合几何,而不是 SQL 关键字 UNION

我正在尝试将一些空间数据从带有 PostGIS 的 Postgres 移动到 SQL Server 2008。一切都很好,直到我看到这样的语句:

SELECT GeomUnion(the_geom) FROM some_table

This unions all geography in that column and return it as a result (类似于 COUNT 有效)。据我所知,SQL Server 只有 STUnion 函数,它将一种几何图形与另一种几何图形结合起来。有什么方法可以做类似 Postgres 的事情吗?

如果有帮助的话,STUnion 函数的工作原理如下:

SELECT first_geometry_column.STUnion(second_geometry_column) FROM some_table

Just to clarify up-front: I'm talking about unioning geometry, not the SQL keyword UNION.

I'm trying to move some spatial data from Postgres with PostGIS to SQL Server 2008. It was fine until I saw a statement like this:

SELECT GeomUnion(the_geom) FROM some_table

This unions all geometry in that column and return it as one result (similar to how COUNT works). As far I know, SQL Server only has the STUnion function, which unions one geometry with another. Is there any way to do something similar to the Postgres way?

If it helps, the STUnion function works like this:

SELECT first_geometry_column.STUnion(second_geometry_column) FROM some_table

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烙印 2024-09-17 08:39:38

UnionAggregate函数只有SQL2012吗?

SELECT geography::UnionAggregate( geometry ) FROM some_table

嗯,猜是这样。 http://technet.microsoft.com/en-us/library/ff929095.aspx

Is the UnionAggregate function SQL2012 only?

SELECT geography::UnionAggregate( geometry ) FROM some_table

Hmm guess so. http://technet.microsoft.com/en-us/library/ff929095.aspx

云淡月浅 2024-09-17 08:39:38

我最终这样做的方式是使用变量:

DECLARE @Shape GEOMETRY
SET @Shape = GEOMETRY::STGeomFromText('GEOMETRYCOLLECTION EMPTY', @MySrid)

SELECT @Shape = @Shape.STUnion(Shape)
  FROM MyShapeTable

它不是那么好,但它有效。

The way I ended up doing this is with variables:

DECLARE @Shape GEOMETRY
SET @Shape = GEOMETRY::STGeomFromText('GEOMETRYCOLLECTION EMPTY', @MySrid)

SELECT @Shape = @Shape.STUnion(Shape)
  FROM MyShapeTable

It's not as nice, but it works.

白日梦 2024-09-17 08:39:38

最好的选择是创建一个 CLR 函数来支持聚合。有几个现有的解决方案:

Your best option is to create a CLR function to support the aggregate. There are a couple of existing solutions:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文