C# 在SQL server中获取错误的空间结果+;管理工作室(2014年)从MultiPolygon WKT解析时

C# 在SQL server中获取错误的空间结果+;管理工作室(2014年)从MultiPolygon WKT解析时,c#,sql-server,geojson,geography,wkt,C#,Sql Server,Geojson,Geography,Wkt,用于将WKT解析为DbGeography的SQL查询: 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.364

用于将WKT解析为DbGeography的SQL查询:

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)
其显示空间结果如下图所示

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

map.data.addGeoJson(geoJsonObject);
它画在地图下面

请帮我从以上两张图片中找出哪个是正确的


如果SQL Management Studio的SQL部分结果是错误的,那么我该如何更正此错误?

我已经找到了答案。通过非公共属性值中的“m_isLargerThanAHemisphere”布尔值,我们可以知道SqlGeography是否大于半球

以下代码用于获取“m_isLargerThanAHemisphere”值:

SqlGeography-SqlGeography=SqlGeography.Parse(geoWKT);
object geoData=PropertyHelper.GetPrivatePropertyValue(sqlGeography,“geoData”);
bool m_isLargerThanAHemisphere=PropertyHelper.GetPrivateFieldValue(地理数据,“m_isLargerThanAHemisphere”);
if(m_Islarger半球)
{
sqlGeography=sqlGeography.ReorientObject();
}
bool isValid=sqlGeography.STIsValid().Value;
如果(!isValid)
{
sqlGeography=sqlGeography.MakeValid();
isValid=sqlGeography.STIsValid().Value;
}
DbGeography=DbGeography.FromText(sqlGeography.ToString(),4326);

您需要反转多边形中点的顺序。当你在一个球体上画一个多边形时,没有自然的“内部”或“外部的”——考虑在赤道附近画一条线——我们包围了北半球还是南半球?由于SQL Server允许覆盖地球一半以上的多边形,因此它使用不同的规则来确定内部和外部。(左手法则)@Damien_非信徒是正确的。或者,在SQL Server的中等现代版本中,您可以在地理实例上调用
ReorientObject()
方法,它将为您反转点。整洁的
                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);