数据库
首页 > 数据库> > c# – 来自SQL服务器数据的xamGeographicMap形状

c# – 来自SQL服务器数据的xamGeographicMap形状

作者:互联网

使用Infragistics xamGeographicMap控件,尝试从SQL Server几何数据中添加形状.

>数据有效; SSMS中的选择正确显示形状
>查询SP_GEOMETRY时可以正确显示点(参见示例) – 所以GeographicSymbolSeries可以工作,形状列包含实际数据
> GeographicShapeSeries不起作用
> GeographicPolyLine不起作用

这样可行:

        var majorCitySeries = new GeographicSymbolSeries
                              {
                                  ItemsSource = data.cities,
                                  LatitudeMemberPath = "SP_GEOMETRY.YCoordinate",
                                  LongitudeMemberPath = "SP_GEOMETRY.XCoordinate"
                              };
        GeoMap.Series.Add(majorCitySeries);

但这些都没有显示:

       var countySeries = new GeographicShapeSeries
                           {
                               ItemsSource = data.counties,     
                               ShapeMemberPath = "SP_GEOMETRY"
                           };
        GeoMap.Series.Add(countySeries);

        var br = new GeographicPolylineSeries
                 {
                     ItemsSource = data.rivers,
                     ShapeMemberPath = "SP_GEOMETRY"
                 };
        GeoMap.Series.Add(br);

我需要添加转换器吗?样品,他们什么都没说.是什么赋予了?

解决方法:

好的,修好了.这是一个半通用的转换器:

public static class SqlGeometryToShapeConverter
{

    public static ShapefileConverter Create<T>(IEnumerable<T> items, 
                                               Func<T, DbGeometry> geoFunc, 
                                               Func<T, string> nameFunc) 
        where T : class
    {
        var converter = new ShapefileConverter();
        foreach (var item in items)
        {
            var rec = new ShapefileRecord();
            var points = new List<Point>();
            var geometry = geoFunc(item);
            Debug.Assert(geometry.PointCount != null, "geometry.PointCount != null");
            // Points are 1 based in DbGeometry
            var pointCount = geometry.PointCount;
            for (var pointIndex = 1; pointIndex <= pointCount; pointIndex++)
            {
                var point = geometry.PointAt(pointIndex);
                Debug.Assert(point.XCoordinate != null, "point.XCoordinate != null");
                Debug.Assert(point.YCoordinate != null, "point.YCoordinate != null");
                points.Add(new Point(point.XCoordinate.Value, point.YCoordinate.Value));
            }
            rec.Fields = new ShapefileRecordFields { { "Name", nameFunc(item) } };
            rec.Points = new List<List<Point>> { points };
            converter.Add(rec);
        }
        return converter;
    }
}

像这样使用它:

        var countySeries = new GeographicShapeSeries
                           {
                               ItemsSource = SqlGeometryToShapeConverter.Create(data.counties, x => x.SP_GEOMETRY, x => x.County_Name),     
                               ShapeMemberPath = "Points"
                           };
        GeoMap.Series.Add(countySeries);

标签:c,sql-server,infragistics,spatial-query
来源: https://codeday.me/bug/20190708/1404450.html