SharpMap入门教程
2024-08-26 04:20:51
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);
运行结果如下
渲染效果还不错吧,比默认样式好看多了 :)
最新文章
- ASP.NET Core中显示自定义错误页面
- HtmlAgilityPack组件
- Java多线程系列--“JUC原子类”02之 AtomicLong原子类
- 三、BLE(上)
- Android系统自带APP分析——短信app
- zju(1)嵌入式开发环境构建
- JavaScript Promise API
- 每天一个linux命令(39):iostat命令
- 鸟哥的linux私房菜学习记录之查看帮助文档
- PDM文件编辑
- Java中的事务——JDBC事务和JTA事务
- 用到的Python运算符
- Android打赏功能:支付宝转账
- 2017-2018-1 Java演绎法 第一周 作业
- AndroidStudio如何快速制作.so
- [Swift]LeetCode961. 重复 N 次的元素 | N-Repeated Element in Size 2N Array
- java十进制转三十六进制
- Spring MVC原理及配置详解
- Spring Boot Runner启动器
- ajax操作json的三种方式