SQL geography::EnvelopeAggregate 输出不准确

Posted

技术标签:

【中文标题】SQL geography::EnvelopeAggregate 输出不准确【英文标题】:SQL geography::EnvelopeAggregate output not accurate 【发布时间】:2017-12-09 06:16:08 【问题描述】:

我正在尝试获取一组位置的 geography::EnvelopeAggregate。地理列值是使用各个点的纬度/经度计算的。 当我尝试获取边界框(范围)时,该框不会覆盖所有单个点。这是预期的行为吗?有该领域专业知识的人可以提供一些意见吗? 下面是绘制的SQL代码和对应的Map。

IF EXISTS (SELECT * FROM tempdb.dbo.sysobjects WHERE id = OBJECT_ID(N'tempdb..[#ServicePoints]'))
    BEGIN
        DROP TABLE #Points
    END
CREATE TABLE #Points
(
    PointId nvarchar(max),
    Lat float,
    Long float,
    Location geography
)
insert into #Points(PointId, Lat, Long, Location)
values ('point1', 47.659226, -117.218292, geography::Point(47.659226, -117.218292, 4326))
insert into #Points(PointId, Lat, Long, Location)
values ('point2', 47.659226, -117.218292, geography::Point(47.659226, -117.218292, 4326))
insert into #Points(PointId, Lat, Long, Location)
values ('point3', 47.659226, -117.218292, geography::Point(47.659226, -117.218292, 4326))
insert into #Points(PointId, Lat, Long, Location)
values ('point3', 47.658276, -117.218474, geography::Point(47.658276, -117.218474, 4326))
insert into #Points(PointId, Lat, Long, Location)
values ('point3', 47.658323, -117.21899, geography::Point(47.658323, -117.21899, 4326))
insert into #Points(PointId, Lat, Long, Location)
values ('point3', 47.658341, -117.219487, geography::Point(47.658341, -117.219487, 4326))
insert into #Points(PointId, Lat, Long, Location)
values ('point3', 47.660115, -117.219365, geography::Point(47.660115, -117.219365, 4326))
insert into #Points(PointId, Lat, Long, Location)
values ('point3', 47.658478, -117.216265, geography::Point(47.658478, -117.216265, 4326))

select * from #Points
--select geography::Point(47.658323, -117.21899, 4326)
Select E1.ID, 
                   E1.SPEXtents.STPointN(3).Lat as BottomLeft_Lat, 
                   E1.SPEXtents.STPointN(3).Long as BottomLeft_Long,
                   E1.SPEXtents.STPointN(1).Lat as RightTop_Lat,         
                   E1.SPEXtents.STPointN(1).Long as RightTop_Long, 
                   E1.SPExtents.STPointN(2).Lat as BottomRight_Lat,
                   E1.SPExtents.STPointN(2).Long as BottomRight_Long,
                   E1.SPExtents.STPointN(4).Lat as TopRight_Lat,
                   E1.SPExtents.STPointN(4).Long as TopRight_Long

        from
        (SELECT 1 as ID,
                geography::EnvelopeAggregate(sp.Location) AS SPExtents
        FROM #Points sp
        ) E1;

这些点在地图中的表示如下。可以看出,有 2 个点位于边界之外。

或者我应该绘制一个连接这 4 个坐标的圆吗?在这种情况下,我可以看到所有点都落在如图所示的圆圈内。

【问题讨论】:

【参考方案1】:

根据一些粗略的测试,看起来 EnvelopeAggregate 返回一个圆形区域。我发现了以下内容:

select geography::EnvelopeAggregate(sp.Location).ToString() AS SPExtents
FROM #Points sp

如果您想查看它所描述的实际区域,只需从上面删除.ToString()

【讨论】:

以上是关于SQL geography::EnvelopeAggregate 输出不准确的主要内容,如果未能解决你的问题,请参考以下文章

sql [sql技巧]一些sql技巧#sql

sql 2008 r2 在sql 2008上兼容么

SQL基础

有大神知道,sql server 中如何批量执行sql语句吗?

pl sql developer怎么执行sql

pl sql developer怎么执行sql