代码之家  ›  专栏  ›  技术社区  ›  SadikAli

从MultiPolygon WKT解析时,SQL server+management studio(2014)中出现错误的空间结果

  •  3
  • SadikAli  · 技术社区  · 8 年前

    用于将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)
    

    其显示空间结果如下图所示 enter image description here

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

    map.data.addGeoJson(geoJsonObject);
    

    其绘制在地图下方 enter image description here

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

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

    1 回复  |  直到 8 年前
        1
  •  1
  •   SadikAli    8 年前

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

    以下代码用于获取“m\u 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