Bing Maps开发扩展三:Bing Maps中渲染ESRI SHP空间数据
2 /// 读取指定路径的SHP文件并返回空间对象集合
3 /// </summary>
4 /// <param name="shapepath">SHP文件路径</param>
5 /// <returns>空间对象集合</returns>
6 private IGeometryCollection ReadShape(string shapepath)
7 {
8 //判断文件是否存在
9 if (!File.Exists(shapepath))
10 throw new ArgumentException("文件 " + shapepath + " 未找到!");
11
12 //读取SHP文件的空间数据返回空间对象集合
13 ShapefileReader reader = new ShapefileReader(shapepath);
14 IGeometryCollection geometries = reader.ReadAll();
15 return geometries;
16 }
2 /// 读取SHP地图数据并发布WCF服务
3 /// </summary>
4 /// <returns>返回空间对象的WKT</returns>
5 public List<string> GetShapeDate()
6 {
7 string shpPath = "D:\\BingMapDemo.DataService\\App_Data\\大区界线_polyline.shp";
8 IGeometryCollection collection = ReadShape(shpPath);
9
10 List<string> result = new List<string>();
11 foreach (IGeometry item in collection.Geometries)
12 {
13 //存储WKT格式空间数据
14 result.Add(item.AsText());
15 }
16 return result;
17 }
2 {
3 public static ICoordinate Convert(Location location)
4 {
5 return new Coordinate {Y = location.Latitude, X = location.Longitude};
6 }
7
8 public static Location ConvertBack(ICoordinate location)
9 {
10 return new Location {Latitude = location.Y, Longitude = location.X};
11 }
12
13 public static LocationCollection CoordinatesToLocationCollection(ICoordinate[] coordinates)
14 {
15 var locations = new LocationCollection();
16 foreach (var coordinate in coordinates)
17 {
18 locations.Add(ConvertBack(coordinate));
19 }
20 return locations;
21 }
22
23 public static ICoordinate[] LocationCollectionToCoordinates(LocationCollection locations)
24 {
25 var coordinates = new Coordinate[locations.Count];
26 for (var x = 0; x < locations.Count;x++ )
27 {
28 coordinates[x] = (Coordinate)Convert(locations[x]);
29 }
30 return (ICoordinate[])coordinates;
31 }
32
33 public static LocationCollection LocationRectToLocationCollection(LocationRect locationRect)
34 {
35 var locations = new LocationCollection
36 {
37 locationRect.Northwest,
38 locationRect.Southwest,
39 locationRect.Southeast,
40 locationRect.Northeast,
41 locationRect.Northwest
42 };
43 return locations;
44 }
45 }
2 {
3 GeometryServiceClient service = new GeometryServiceClient();
4 service.GetShapeDateCompleted += service_GetShapeDateCompleted;
5 service.GetShapeDateAsync();
6 }
7
8 private void service_GetShapeDateCompleted(object sender, GetShapeDateCompletedEventArgs e)
9 {
10 if (e.Error == null)
11 {
12 ObservableCollection<string> result = e.Result;
13 WKTReader reader = null;
14 foreach (var item in result)
15 {
16 reader = new WKTReader();
17 //读取WKT到空间对象
18 IGeometry geometry = reader.Read(item);
19 if (geometry == null) continue;
20 //边界
21 MapPolygon line = new MapPolygon();
22 //转换坐标
23 line.Locations = CoordinateConvertor.CoordinatesToLocationCollection(geometry.Coordinates);
24 line.Fill = new SolidColorBrush(Colors.Gray);
25 line.BorderBrush = new SolidColorBrush(Colors.Green);
26 line.BorderThickness = new Thickness(2);
27 line.MouseEnter += new MouseEventHandler(line_MouseEnter);
28 line.MouseLeave += new MouseEventHandler(line_MouseLeave);
29 this.mlayer.Children.Add(line);
30 }
31 }
32 }
五、相关资源:
[1]、SharpMap:http://sharpmap.codeplex.com
[2]、NetTopologySuite:http://code.google.com/p/nettopologysuite
[3]、WKT:http://www.opengis.org/techno/specs.htm
本文属学习笔记文章,愿与有志者共同学习交流。欢迎转载,为了保存作者的创作热情,但请在明显地位标记本文的原文连接。
作 者:Beniao
文章出处:http://beniao.cnblogs.com/ 或 http://www.cnblogs.com/
Bing Maps开发扩展三:Bing Maps中渲染ESRI SHP空间数据相关推荐
- SLAM机器人开发(三)SLAM中常见的里程计
SLAM机器人开发(三)SLAM中常见的里程计 里程计分类 车轮里程计 惯性里程计 电磁波(光学)雷达 超声波雷达 视觉里程计 里程计对比图 里程计分类 里程计(Odometry)这个词是由希腊单词o ...
- OpenGL ES 3.0 开发(三):YUV 渲染
该原创文章首发于微信公众号:字节流动 YUV 渲染原理 前面文章一文掌握 YUV 图像的基本处理介绍了 YUV 常用的基本格式,本文以实现 NV21/NV12 的渲染为例. 前文提到,YUV 图不能直 ...
- Revit二次开发——扩展存储
Revit二次开发--扩展存储 在revitAPI中,提供了Extensible Storage framework,可以使开发者将需要存储的数据存到Revit的rvt文件中, 扩展的数据始终跟 ...
- Thingworx自定义扩展开发(三)- echarts集成
系列 Thingworx自定义扩展开发(一)- 开发环境搭建.Extension Demo Coding Thingworx自定义扩展开发(二)- Widget Demo Coding Thingwo ...
- Dubbo源码分析(三)Dubbo中的SPI和自适应扩展机制
前言 我们在往期文章中,曾经深入分析过Java的SPI机制,它是一种服务发现机制.具体详见:深入理解JDK的SPI机制 在继续深入Dubbo之前,我们必须先要明白Dubbo中的SPI机制.因为有位大神 ...
- android 界面组件,安卓开发学习周第三篇——Android中的UI组件
原标题:安卓开发学习周第三篇--Android中的UI组件 在Android APP中,所有的用户界面元素都是由View和ViewGroup的对象构成的.View是绘制在屏幕上的用户能与之交互的一个对 ...
- 详述Visual Studio 代码远程开发扩展中的远程命令执行漏洞
聚焦源代码安全,网罗国内外最新资讯! 编译:代码卫士 Visual Studio 代码远程开发扩展(Code Remote Development Extension) 1.50 未能在将其用作 s ...
- 用python绘制y=x,y=1+sinx,编写Python程序,使用numpy、pandas、matplotlib三个扩展库在一个画布中绘制4个子图.
目录 1.编写Python程序绘制y=x图. 2.绘制表达式为1+sin(x)的图. 3.编写Python程序,使用numpy.pandas.matplotlib三个扩展库在一个画布中绘制4个子图,分 ...
- 云计算Python自动化运维开发实战 三、python文件类型
为什么80%的码农都做不了架构师?>>> 云计算Python自动化运维开发实战 三.python文件类型 导语: python常用的有3种文件类型 1. 源代码 py ...
最新文章
- VC使用CRT调试功能来检测内存泄漏
- 选择UPS电源的四大要素
- 一款很好用的JQuery dtree树状图插件(一)
- 7个HTML5移动开发框架,初学HTML5必看
- sv编程语言_SV及UVM高级话题篇之一:SystemVerilog开源公共库(上)
- 图片句柄_PC微信逆向:自动保存加密的聊天图片
- 中职计算机课程教学,提高中职计算机课程教学效率的途径
- RFID打印机有什么用
- python安装sqlalchemy python2_Python SQLAlchemy --2
- Http协议简易分析
- java添加购物车代码_Java web实现购物车功能的示例代码
- java基础入门(完整详细版)
- 扫二维码登录的实现原理
- K3默认序时簿是不体现即时库存的,如果需要在序时簿将物料的即时库存数据带入,可以按照下方的步骤实现:
- ROS中gazebo工具学习(使用gazebo加载机器人模型)
- 对不起 我追不上你了。
- Java生成“年月日“+流水号
- WIFI驱动开发——WIFI基础知识汇总
- dolphin scheduler(一)
- Randomized algorithms(随机算法)
热门文章
- 检查字段是否包含字符串
- 在Java / Maven中处理“Xerces hell”?
- 2D阵列中的峰值检测
- 0832工作原理详解_最经典MOS管电路工作原理及详解没有之一
- u盘怎么重装系统win11教程
- mysql 数据库时间类型 datetime 数据在页面上显示一串数字, 用函数date_format( )转换格式 ;
- Git:clone时报错403
- java .size,Java中length,length(),size()详解及区别
- python编写请求参数带文件_python:解析httppost请求,其中包含文件上传和其他参数...
- web浏览器_微软低头,Chrome 一统浏览器!