从 MultiPolygon WKT 解析时在 SQL server + management studio (2014) 中得到错误的空间结果

Getting wrong spatial result in SQL server + management studio (2014) when parse from MultiPolygon WKT

SQL 将 WKT 解析为 DbGeography 的查询:

select geography::STMPolyFromText('MULTIPOLYGON (((-2.5591667 49.2208332, -2.4799491 49.2644641, -2.3891134 49.2959748, -2.2950459 49.325767, -2.2176605 49.3624676, -2.1335686 49.4074579, -2.0975001 49.4605, -1.9925 49.3646667, -1.8916667 49.3166667, -1.8333334 49.2508333, -1.8333333 49.1833333, -1.8591667 49.0658333, -1.9428333 48.9646666, -1.9833333 48.9416666, -1.9833333 48.9365843, -1.9833333 48.8833333, -2.0833333 48.8721666, -2.2416668 48.8721666, -2.5253334 48.9278333, -2.5253333 49.0595, -2.5591667 49.2208332)))',4326)

其显示空间结果如下图

当我使用 GeoJSON4EntityFramework 将此 WKT 转换为 GeoJson 并通过以下代码在 google 地图中加载此 geojson 时:

map.data.addGeoJson(geoJsonObject);

它在地图下方绘制

请帮我看看上面两张图片哪个是正确的。

如果 SQL Management Studio 的 SQL 部分结果有误,我该如何更正?

我找到答案了。我们可以通过非public 属性值的"m_isLargerThanAHemisphere"布尔值知道SqlGeography是否大于半球。

获取 "m_isLargerThanAHemisphere" 值的代码如下:

                SqlGeography sqlGeography = SqlGeography.Parse(geoWKT);

                object geoData = PropertyHelper.GetPrivatePropertyValue<object>(sqlGeography, "GeoData");
                bool m_isLargerThanAHemisphere = PropertyHelper.GetPrivateFieldValue<bool>(geoData, "m_isLargerThanAHemisphere");
                if (m_isLargerThanAHemisphere)
                {
                    sqlGeography = sqlGeography.ReorientObject();
                }
                bool isValid = sqlGeography.STIsValid().Value;
                if (!isValid)
                {
                    sqlGeography = sqlGeography.MakeValid();
                    isValid = sqlGeography.STIsValid().Value;
                }
                DbGeography dbGeography = DbGeography.FromText(sqlGeography.ToString(), 4326);

PropertyHelper class reference