STContains - 多边形内的点测试失败
STContains - tests failing for points INSIDE polygon
第一,SQL版本:
Microsoft SQL Server 2016 (RTM) - 13.0.1601.5 (X64) 2016 年 4 月 29 日 23:23:58 版权所有 (c) Microsoft Corporation Standard Edition(64 位)Windows服务器 2012 R2 标准版 6.3(内部版本 9600:)(管理程序)
我声明了一个封闭多边形(使用左手法则正确定向),根据 SQL 是有效的:
DECLARE @g geography;
SET @g = geography::STPolyFromText('POLYGON((-141.251221 60.177476, -134.351807 52.952478, -124.859620 48.440718, -123.623658 48.163009, -123.132020 48.232578, -122.906113 48.998367, -95.169068 48.966372, -94.980927 49.021337, -94.627991 48.700606, -93.907013 48.594450, -93.845215 48.495351, -93.510132 48.517642, -93.197022 48.583549, -92.743836 48.507408, -92.422486 48.211991, -91.573792 48.021520, -90.973664 48.095065, -90.146256 48.021693, -89.428711 47.911409, -88.442688 48.232120, -84.935303 46.850463, -84.819947 46.614678, -84.531556 46.397991, -84.200593 46.493917, -84.117508 46.124608, -83.620034 45.782175, -82.591267 45.290317, -82.166749 43.592965, -82.661133 42.606311, -82.886353 42.391659, -83.097840 42.332805, -83.187104 42.071357, -83.135605 41.842088, -82.865410 41.657411, -82.463379 41.587347, -81.068116 42.119252, -80.049134 42.334835, -78.887330 42.783953, -78.868104 42.953046, -78.995820 43.161758, -79.090577 43.433616, -78.664856 43.557148, -76.766968 43.541223, -76.398926 44.064539, -74.852601 44.971250, -71.471558 44.957647, -70.846711 45.205884, -70.589219 45.379779, -70.207787 45.900179, -69.238587 47.291005, -68.891488 47.116066, -68.297196 47.291936, -67.850361 47.016678, -67.864953 45.667941, -65.966034 43.191802, -49.229737 45.124550, -59.425049 68.026407, -75.421143 74.789051, -73.663331 78.324047, -57.315674 82.569900, -71.378174 83.545629, -112.335206 79.852216, -141.163331 70.394745, -141.251221 60.177476 ))', 4326);
SELECT @g.IsValidDetailed() AS 'IsValidDetailed', @g.STIsClosed() AS 'STIsClosed', @g.EnvelopeAngle() AS 'EnvelopeAngle';
执行上述查询时,SQL 响应:
IsValidDetailed STIsClosed EnvelopeAngle
24400: Valid True 33.0780372828377
为了视觉验证,我绘制了多边形(通过 Google 地图),还包括多边形内部的 3 个点以及多边形外部的 3 个点。下面是多边形的屏幕快照和缩放级别的点,显示了完整的多边形(红色区域表示包围多边形的 "bounds"):
放大地图,您可以开始看到各个点,即:
进一步放大,可以看到其中两个点非常靠近多边形的边缘,一个在里面(绿色),一个在外面(红色):
以下查询用于测试多边形内部的点:
SELECT lat, lon,
@g.STContains( geography::Point( lat, lon, 4326 ) ) AS STContains,
geography::Point( lat, lon, 4326 ).STWithin( @g ) AS STWithin
FROM ( VALUES ( 49.119404, -102.988586 ),
( 49.004776, -102.996875 ),
( 48.975416, -103.005152 )
) points( lat, lon )
SQL 响应:
lat lon STContains STWithin
49.119404 -102.988586 False False
49.004776 -102.996875 False False
48.975416 -103.005152 False False
-- 对于多边形内的点,期望 STContains 和 STwithin 到 return "True"???
以下查询用于测试多边形外部的点:
SELECT lat, lon,
@g.STContains( geography::Point( lat, lon, 4326 ) ) AS STContains,
geography::Point( lat, lon, 4326 ).STWithin( @g ) AS STWithin
FROM ( VALUES ( 48.975409, -103.005151 ),
( 48.974153, -103.005144 ),
( 48.951739, -103.005627 )
) points( lat, lon )
SQL 响应:
lat lon STContains STWithin
48.975409 -103.005151 False False
48.974153 -103.005144 False False
48.951739 -103.005627 False False
-- 所有点都在多边形外部的预期结果。
问题:
为什么 STContains / STWithin 对于位于多边形内部的点失败?
我必须假设我做错了什么,但我遵循了构建多边形的规则(左手),SQL 表示多边形是 "valid"。
如有任何建议,我们将不胜感激。
因为在球面几何中,纬线不是直线。大圆弧是。多边形的最近边缘是 -122.906113 48.998367, -95.169068 48.966372
,它位于经度 -103 的第 49 平行线以北。
select geography::STLineFromText('LINESTRING(-122.906113 48.998367, -95.169068 48.966372)', 4326);
是
第一,SQL版本:
Microsoft SQL Server 2016 (RTM) - 13.0.1601.5 (X64) 2016 年 4 月 29 日 23:23:58 版权所有 (c) Microsoft Corporation Standard Edition(64 位)Windows服务器 2012 R2 标准版 6.3(内部版本 9600:)(管理程序)
我声明了一个封闭多边形(使用左手法则正确定向),根据 SQL 是有效的:
DECLARE @g geography;
SET @g = geography::STPolyFromText('POLYGON((-141.251221 60.177476, -134.351807 52.952478, -124.859620 48.440718, -123.623658 48.163009, -123.132020 48.232578, -122.906113 48.998367, -95.169068 48.966372, -94.980927 49.021337, -94.627991 48.700606, -93.907013 48.594450, -93.845215 48.495351, -93.510132 48.517642, -93.197022 48.583549, -92.743836 48.507408, -92.422486 48.211991, -91.573792 48.021520, -90.973664 48.095065, -90.146256 48.021693, -89.428711 47.911409, -88.442688 48.232120, -84.935303 46.850463, -84.819947 46.614678, -84.531556 46.397991, -84.200593 46.493917, -84.117508 46.124608, -83.620034 45.782175, -82.591267 45.290317, -82.166749 43.592965, -82.661133 42.606311, -82.886353 42.391659, -83.097840 42.332805, -83.187104 42.071357, -83.135605 41.842088, -82.865410 41.657411, -82.463379 41.587347, -81.068116 42.119252, -80.049134 42.334835, -78.887330 42.783953, -78.868104 42.953046, -78.995820 43.161758, -79.090577 43.433616, -78.664856 43.557148, -76.766968 43.541223, -76.398926 44.064539, -74.852601 44.971250, -71.471558 44.957647, -70.846711 45.205884, -70.589219 45.379779, -70.207787 45.900179, -69.238587 47.291005, -68.891488 47.116066, -68.297196 47.291936, -67.850361 47.016678, -67.864953 45.667941, -65.966034 43.191802, -49.229737 45.124550, -59.425049 68.026407, -75.421143 74.789051, -73.663331 78.324047, -57.315674 82.569900, -71.378174 83.545629, -112.335206 79.852216, -141.163331 70.394745, -141.251221 60.177476 ))', 4326);
SELECT @g.IsValidDetailed() AS 'IsValidDetailed', @g.STIsClosed() AS 'STIsClosed', @g.EnvelopeAngle() AS 'EnvelopeAngle';
执行上述查询时,SQL 响应:
IsValidDetailed STIsClosed EnvelopeAngle
24400: Valid True 33.0780372828377
为了视觉验证,我绘制了多边形(通过 Google 地图),还包括多边形内部的 3 个点以及多边形外部的 3 个点。下面是多边形的屏幕快照和缩放级别的点,显示了完整的多边形(红色区域表示包围多边形的 "bounds"):
放大地图,您可以开始看到各个点,即:
进一步放大,可以看到其中两个点非常靠近多边形的边缘,一个在里面(绿色),一个在外面(红色):
以下查询用于测试多边形内部的点:
SELECT lat, lon,
@g.STContains( geography::Point( lat, lon, 4326 ) ) AS STContains,
geography::Point( lat, lon, 4326 ).STWithin( @g ) AS STWithin
FROM ( VALUES ( 49.119404, -102.988586 ),
( 49.004776, -102.996875 ),
( 48.975416, -103.005152 )
) points( lat, lon )
SQL 响应:
lat lon STContains STWithin
49.119404 -102.988586 False False
49.004776 -102.996875 False False
48.975416 -103.005152 False False
-- 对于多边形内的点,期望 STContains 和 STwithin 到 return "True"???
以下查询用于测试多边形外部的点:
SELECT lat, lon,
@g.STContains( geography::Point( lat, lon, 4326 ) ) AS STContains,
geography::Point( lat, lon, 4326 ).STWithin( @g ) AS STWithin
FROM ( VALUES ( 48.975409, -103.005151 ),
( 48.974153, -103.005144 ),
( 48.951739, -103.005627 )
) points( lat, lon )
SQL 响应:
lat lon STContains STWithin
48.975409 -103.005151 False False
48.974153 -103.005144 False False
48.951739 -103.005627 False False
-- 所有点都在多边形外部的预期结果。
问题:
为什么 STContains / STWithin 对于位于多边形内部的点失败?
我必须假设我做错了什么,但我遵循了构建多边形的规则(左手),SQL 表示多边形是 "valid"。
如有任何建议,我们将不胜感激。
因为在球面几何中,纬线不是直线。大圆弧是。多边形的最近边缘是 -122.906113 48.998367, -95.169068 48.966372
,它位于经度 -103 的第 49 平行线以北。
select geography::STLineFromText('LINESTRING(-122.906113 48.998367, -95.169068 48.966372)', 4326);
是