【问题标题】:With SQL2008 Spatial functions, How can I generate a polygon containing the results of an aggreation使用 SQL 2008 空间函数,如何生成包含聚合结果的多边形
【发布时间】:2009-07-31 12:32:22
【问题描述】:

我有一个点表,每个点都有名称、纬度、经度和区号。我想做的是执行聚合(即“分组依据”子句)并返回一个包含特定区号的所有点的多边形。

虽然我很难找到地理数据类型是否有任何内置聚合,更不用说给我边界多边形了

为了论证,假设我有一个看起来有点像的表格:

+---------+------+---------+---------+ |姓名 |面积 |纬度 |长 | +---------+------+---------+---------+ |伊普斯维奇 |一个 | 52.053 | 1.156 | |卢顿 |一个 | 51.8717 | -0.4246 | |梅尔顿 |一个 | 52.1064 | 1.3322 | |迪科特 |乙| 51.6024 | -1.2321 | |牛津 |乙| 51.7486 | -1.265 | +---------+------+---------+---------+

(实际上最小的区域有57个点,最大的有626个)

【问题讨论】:

    标签: sql sql-server-2008 gis geospatial


    【解决方案1】:

    虽然没有内置方法来执行此操作,但 Sql Spatial Tools CodePlex 包中提供了聚合。根据您想要的确切内容,您可能有兴趣使用 Bounding Box Aggregate 或 Union Aggregate,然后调用 ConvexHull 来获取最小多边形而不是框。

    【讨论】:

      【解决方案2】:

      为了任何来到这里并希望看到您获得的代码的人的好处(真棒)Sql Spatial Tools

      DECLARE @points TABLE
      (
       Name VARCHAR(50),
       Area CHAR(1),
       Point GEOGRAPHY
      )
      
      INSERT INTO @points VALUES ('Ipswich', 'A', geography::STGeomFromText('POINT( 1.156  52.053  )', 4326))
      INSERT INTO @points VALUES ('Luton', 'A', geography::STGeomFromText('POINT(  -0.4246 51.8717 )', 4326))
      INSERT INTO @points VALUES ('Melton', 'A', geography::STGeomFromText('POINT( 1.3322  52.1064 )', 4326))
      
      INSERT INTO @points VALUES ('Didcot', 'B', geography::STGeomFromText('POINT( -1.2321 51.6024 )', 4326))
      INSERT INTO @points VALUES ('Oxford', 'B', geography::STGeomFromText('POINT( -1.265  51.7486 )', 4326))
      
      SELECT  dbo.ConvexHullGeography(dbo.GeographyUnionAggregate(point)), 'red' as color, 1 as thickness
      FROM @points
      GROUP BY Area
      

      您可以在GeoQuery2008查看结果。

      【讨论】:

      • 我不得不从您的帖子中删除图片,因为 ImageShack 已将其删除并替换为广告。有关更多信息,请参阅meta.stackexchange.com/q/263771/215468。如果可能,您最好重新上传它们。谢谢!
      猜你喜欢
      • 2012-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-02
      • 2021-08-31
      • 1970-01-01
      • 1970-01-01
      • 2014-01-27
      相关资源
      最近更新 更多