zoukankan      html  css  js  c++  java
  • SharpMap入门教程

    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(204, 89, 68));
    style1.EnableOutline = true;
    style1.Outline = new Pen(Brushes.Black, 1.2f);
    VectorStyle style2 = new VectorStyle();
    style2.Fill = new SolidBrush(Color.FromArgb(253, 174, 97));
    style2.EnableOutline = true;
    style2.Outline = new Pen(Brushes.Black, 1.2f);
    VectorStyle style3 = new VectorStyle();
    style3.Fill = new SolidBrush(Color.FromArgb(255, 255, 192));
    style3.EnableOutline =  true;
    style3.Outline = new Pen(Brushes.Black, 1.2f);
    VectorStyle style4 = new VectorStyle();
    style4.Fill = new SolidBrush(Color.FromArgb(166, 217, 106));
    style4.EnableOutline = true;
    style4.Outline = new Pen(Brushes.Black, 1.2f);
    Dictionary<string, SharpMap.Styles.IStyle> styles = new Dictionary<string, IStyle>();
    styles.Add("1", style1);
    styles.Add("2", style2);
    styles.Add("3", style3);
    styles.Add("4", style4);
    vlay.Theme = new SharpMap.Rendering.Thematics.UniqueValuesTheme<string>("id", styles, style1);

    运行结果如下

     

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

  • 相关阅读:
    浅析String.intern()方法
    com.alibaba.druid.pool.DruidPooledConnection cannot be cast to oracle.jdbc.OracleConnection 异常解决办法
    ChannelEventRunnable handle RECEIVED operation error, channel is NettyChannel解决方法
    jsch channel is not opened原因及解决
    学习地址(oraclemysqllinux)
    python中数据分析常用函数整理
    Python之使用Pandas库实现MySQL数据库的读写
    Python数据分析
    如何用sql查询出连续三个月金额大于50的记录
    【Python项目实战】Pandas:让你像写SQL一样做数据分析(一)
  • 原文地址:https://www.cnblogs.com/hans_gis/p/3719910.html
Copyright © 2011-2022 走看看