c# – 来自SQL服务器数据的xamGeographicMap形状
发布时间:2020-12-15 22:05:39 所属栏目:百科 来源:网络整理
导读:使用Infragistics xamGeographicMap控件,尝试从SQL Server几何数据中添加形状. 数据有效; SSMS中的选择正确显示形状 查询SP_GEOMETRY时可以正确显示点(参见示例) – 所以GeographicSymbolSeries可以工作,形状列包含实际数据 GeographicShapeSeries不起作用 G
使用Infragistics xamGeographicMap控件,尝试从SQL Server几何数据中添加形状.
>数据有效; SSMS中的选择正确显示形状 这样可行: 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,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); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |