为什么简单的 sql 地理多边形会填满整个地球?

Why simple sql geography polygon fill whole Earth?

我正在尝试在 sqlserver 中创建地理多边形:

declare @poly geography = geography::STGeomFromText('POLYGON ((37.1834472346309 55.9627364130318, 37.1843162703518 55.9615689125515, 37.1847990679744 55.9603833217405, 37.1861294436458 55.9590893612134, 37.1858183074 55.9583972249632, 37.1860757994655 55.9580361054639, 37.1851960349086 55.9576990575455, 37.1834901499751 55.9592217684712, 37.1819451975825 55.9611416225876, 37.1812692809108 55.9626581795365, 37.1834472346309 55.9627364130318))', 4326)

select @poly

结果如下所示:

为什么我的多边形会填满整个地球?

我有另一个多边形,看起来还不错:

declare @poly2 geography = geography::STGeomFromText('POLYGON ((37.1880241973734 55.964234021191, 37.1895369632579 55.9640354359623, 37.1900519473887 55.9640655246991, 37.1912964923716 55.9645830472949, 37.1928736312724 55.9647996825904, 37.193699751649 55.9648598588536, 37.1936568363047 55.965563914075, 37.1913823230601 55.9656120541331, 37.1905669315196 55.966273973827, 37.1896227939463 55.9666891721997, 37.1887323005534 55.9674172628857, 37.1882924182749 55.9681333056029, 37.1881851299143 55.9689095049396, 37.1880027397013 55.9692163701344, 37.1877452476359 55.9693788271893, 37.1874341113901 55.9694570470084, 37.1870371444559 55.9694690808126, 37.186693821702 55.9694510301049, 37.1863504989481 55.9693246749138, 37.1861144645548 55.9691682345792, 37.1860179050303 55.9689696747783, 37.185974989686 55.9687711139541, 37.1862324817515 55.9675737103232, 37.186693821702 55.9673631078402, 37.1868332965708 55.9667192588449, 37.1874555690622 55.9663883042339, 37.1876165016031 55.9657384214668, 37.1881529434061 55.9652269319451, 37.1880134685373 55.964577029591, 37.1880241973734 55.964234021191))', 4326)

select @poly2

我在不同版本的 SqlServer(SqlExpress 2017 和 SqlServer Professional 2016)中尝试此查询 - 结果相同。

有 2 种解释多边形的方法,您提供给 SQL 服务器的点的顺序似乎不是它期望的顺序,因此它选择“外部”区域而不是“里面”。

这是选择多边形之前的right to left rule, and the simple fix is to call native function ReorientObject()

declare @poly geography = geography::STGeomFromText('POLYGON ((37.1834472346309 55.9627364130318, 37.1843162703518 55.9615689125515, 37.1847990679744 55.9603833217405, 37.1861294436458 55.9590893612134, 37.1858183074 55.9583972249632, 37.1860757994655 55.9580361054639, 37.1851960349086 55.9576990575455, 37.1834901499751 55.9592217684712, 37.1819451975825 55.9611416225876, 37.1812692809108 55.9626581795365, 37.1834472346309 55.9627364130318))', 4326)

select @poly.ReorientObject()