【问题标题】:silverlight c# sql geography to xamlsilverlight c# sql 地理到 xaml
【发布时间】:2016-06-02 14:53:24
【问题描述】:

我在从 Sql Server 地理数据转换为 Silverlight XAML 时遇到了一些问题。

/* Database query spatial data structure for the SQL Server spatial data types object */

var geo = SqlGeography.STGeomFromText (new SqlChars(new SqlString(polygon.ToString())), 4326);

/* Spatial data structure for the Bing Maps graphical objects (polygons) XAML text, to resolve Xaml directly returned to the client in the Silverlight application object. */

for (int j =   0; j < geo.NumRings(); j++)

问题:geo.NumRings() 方法返回 null,但我的多边形对象中有 2 个环。

下面的打印屏幕应该解释得更好

link print screen source code and geo object data

【问题讨论】:

    标签: c# sql-server silverlight bing-maps sqlgeography


    【解决方案1】:

    您的图像显示了一个 MultiPolygon,它是一个多边形数组。每个多边形都有一组环。因此,当几何是多形状时,您将需要遍历其每个子几何并对其进行解析。您可以使用 STNumGeometry 和 STGeometryN 方法循环遍历子几何。

    也就是说,我不建议使用 Silverlight 进行任何开发。 Bing Maps Silverlight 控件将于 11 月弃用,如 here 所述。

    最新的 Bing Maps JavaScript 控件 (V8) 也更容易连接到您的 SqlGeography 对象,并且也比 Silverlight 控件快很多。 V8 控件有一个内置的 Well Known Text 模块,这意味着您只需执行 geom.STAsText 并将该数据返回到 JavaScript 中的该模块,您就可以非常轻松地在地图上呈现形状。 Bing Maps Silverlight 控件可以在变慢之前处理大约 1MB 或 2MB 的多边形数据,而 V8 控件已经用超过 40MB 的数据进行了测试,并且在加载 2MB 数据时的性能甚至比 Silverlight 控件更好。

    【讨论】:

      【解决方案2】:

      正如我们在打印屏幕中看到的,多边形对象实际上是一个多多边形对象。

      我已经解决了添加新 for 循环的问题,以收集从 sql server 返回的多多边形对象内的所有多边形。

      这是新代码:

              //NEW: loop trough the geometries (polygons inside multipolygon)
              for (int g = 1; g <= geo.STNumGeometries(); g++)
              {
                  var geopolygon = geo.STGeometryN(g);
      
                  // Spatial data structure for the Bing Maps graphical objects (polygons) XAML text, to resolve Xaml directly returned to the client in the Silverlight application object. 
                  for (int j = 1; j <= geopolygon.NumRings(); j++)
                  {
                      if (geopolygon.RingN(j).STNumPoints() > 1)
                      { ...
      

      谢谢

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-09-14
        • 2014-03-14
        • 2011-09-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多