使用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,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);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。