SharpMap是一个基于.NET Framework 4,采用C#开发的地图渲染引擎,非常易于使用。本教程针对SharpMap入门及开发,讲述如何基于SharpMap组件渲染Shapefile数据。

一、添加SharpMap的UI组件至VS工具箱

添加后如图所示

二、加载Shapefile图层数据

1、给WinForm窗体添加MapBox组件

2、为项目添加SharpMap引用,一般来说给WinForm窗体添加MapBox组件后,会自动引用SharpMap引用,如果没有的话,手动添加SharpMap.dll引用

3、在WinForm窗体构造器方法中添加如下代码,实现加载Shapefile数据

SharpMap.Layers.VectorLayer vlay = new SharpMap.Layers.VectorLayer("States");
vlay.DataSource = new SharpMap.Data.Providers.ShapeFile("ShpData\\Provinces_R.shp", true);
mapBox1.Map.Layers.Add(vlay);
mapBox1.Map.ZoomToExtents();
mapBox1.Refresh();

4、设置当前地图工具为Pan(漫游)

mapBox1.ActiveTool = SharpMap.Forms.MapBox.Tools.Pan;

运行结果如下(默认的渲染样式比较丑)

三、根据要素属性唯一值渲染图层

该图层的id字段取值为[1,2,3,4],为每一种类型设置不同的渲染风格,指定按id字段唯一值进行渲染

VectorStyle style1 = new VectorStyle();
style1.Fill = new SolidBrush(Color.FromArgb(, , ));
style1.EnableOutline = true;
style1.Outline = new Pen(Brushes.Black, 1.2f);
VectorStyle style2 = new VectorStyle();
style2.Fill = new SolidBrush(Color.FromArgb(, , ));
style2.EnableOutline = true;
style2.Outline = new Pen(Brushes.Black, 1.2f);
VectorStyle style3 = new VectorStyle();
style3.Fill = new SolidBrush(Color.FromArgb(, , ));
style3.EnableOutline = true;
style3.Outline = new Pen(Brushes.Black, 1.2f);
VectorStyle style4 = new VectorStyle();
style4.Fill = new SolidBrush(Color.FromArgb(, , ));
style4.EnableOutline = true;
style4.Outline = new Pen(Brushes.Black, 1.2f);
Dictionary<string, SharpMap.Styles.IStyle> styles = new Dictionary<string, IStyle>();
styles.Add("", style1);
styles.Add("", style2);
styles.Add("", style3);
styles.Add("", style4);
vlay.Theme = new SharpMap.Rendering.Thematics.UniqueValuesTheme<string>("id", styles, style1);

运行结果如下

渲染效果还不错吧,比默认样式好看多了 :)

最新文章

  1. ASP.NET Core中显示自定义错误页面
  2. HtmlAgilityPack组件
  3. Java多线程系列--“JUC原子类”02之 AtomicLong原子类
  4. 三、BLE(上)
  5. Android系统自带APP分析——短信app
  6. zju(1)嵌入式开发环境构建
  7. JavaScript Promise API
  8. 每天一个linux命令(39):iostat命令
  9. 鸟哥的linux私房菜学习记录之查看帮助文档
  10. PDM文件编辑
  11. Java中的事务——JDBC事务和JTA事务
  12. 用到的Python运算符
  13. Android打赏功能:支付宝转账
  14. 2017-2018-1 Java演绎法 第一周 作业
  15. AndroidStudio如何快速制作.so
  16. [Swift]LeetCode961. 重复 N 次的元素 | N-Repeated Element in Size 2N Array
  17. java十进制转三十六进制
  18. Spring MVC原理及配置详解
  19. Spring Boot Runner启动器
  20. ajax操作json的三种方式

热门文章

  1. SVN版本控制系统最佳实践
  2. C# 重构
  3. Abstract(抽象)
  4. requesth获取参数
  5. 找不到 org/springframework/dao/support/PersistenceExceptionTranslator
  6. 数据库执行的时候报ORA-01653错误
  7. zt对于C#中的FileUpload解决文件上传大小限制的问题设置
  8. WPF Shader 正片叠底
  9. json和jsonp的区别(转)
  10. 编写DLL