3.矢量数据基本操作

量数据基本操作

1.   添加现有的矢量数据

1) 本地shapefile

string filePath = "";//shapefile文件在磁盘上的地址

            //根据路径获取图层

            Shapefile sf = new Shapefile();

            bool isopen =sf.Open(filePath);

            if (!isopen)

            {

                MessageBox.Show("图层打开失败", "提示");

                return;

            }

            //添加到地图中,并且获取句柄

            int handle =map.AddLayer(sf, true);

2) 数据库内空间数据(POSTGRESQL)

        private voidAddPGVector() {

           OgrDatasource ogrDs = new OgrDatasource();

            stringpgstr = "PG:host=localhost dbname=london user=postgres password=1234";

           ogrDs.Open(pgstr);

           OgrLayer layer = ogrDs.GetLayerByName("layername");

 

           MapWinGIS.Shapefile sf = layer.GetBuffer();

            //添加到地图中,并且获取句柄

            inthandle = map.AddLayer(sf, true);

       }

2.   矢量图层创建

1) 点图层创建(线和面等图层创建使用方式思路相同)

   privatevoid CreatePointSf() {

            //创建新的图层

            var sf = new Shapefile();

            //创建为点图层

            bool result =sf.CreateNewWithShapeID("", ShpfileType.SHP_POINT);

            //创建一个点,用于写入到图层中

            var pnt = new MapWinGIS.Point();

            pnt.x = 0;

            pnt.y =0;

            //创建一个点要素

            Shape shp = new Shape();

            shp.Create(ShpfileType.SHP_POINT);

            int index = 0;

            //将点插入到要素中

            shp.InsertPoint(pnt, ref index);

            //将要素写入到图层

            sf.EditInsertShape(shp, 0);

            //给图层设置点的符号样式

           sf.DefaultDrawingOptions.SetDefaultPointSymbol(tkDefaultPointSymbol.dpsStar);

            // 将图层添加到地图中

            map.AddLayer(sf, true);

        }

 

发布了16 篇原创文章 · 获赞 2 · 访问量 3512

猜你喜欢

转载自blog.csdn.net/weixin_41012454/article/details/79460103
今日推荐